"use strict"; // This is the global list of the stories, an instance of StoryList let storyList; /** Get and show stories when site first loads. */ async function getAndShowStoriesOnStart() { storyList = await StoryList.getStories(); $storiesLoadingMsg.remove(); putStoriesOnPage(); } /** * A render method to render HTML for an individual Story instance * - story: an instance of Story * * Returns the markup for the story. */ function generateStoryMarkup(story) { // console.debug("generateStoryMarkup", story); const hostName = story.getHostName(); return $(`
  • ${story.title} (${hostName}) by ${story.author} posted by ${story.username}
  • `); } /** Gets list of stories from server, generates their HTML, and puts on page. */ function putStoriesOnPage() { console.debug("putStoriesOnPage"); $allStoriesList.empty(); // loop through all of our stories and generate HTML for them for (let story of storyList.stories) { const $story = generateStoryMarkup(story); $allStoriesList.append($story); } $allStoriesList.show(); } /** handles story form submission: takes in values from story submission * form, calls addStory, generates story markup to append to page */ async function getNewStoryAndSubmit(evt) { const title = $("#story-title").val(); const author = $("#story-author").val(); const url = $("#story-url").val(); const newStory = { title: title, author: author, url: url } const resultOfAddStoryCall = await storyList.addStory(currentUser, newStory); console.log("resultOfAddStoryCall: ", resultOfAddStoryCall); putStoriesOnPage(); }