From 6b42e4b64caf161ed70c4f69093baa295f3d258c Mon Sep 17 00:00:00 2001 From: Jason Date: Fri, 3 Jun 2022 01:02:54 -0500 Subject: [PATCH] working to update article form submission functionality --- js/main.js | 1 + js/nav.js | 4 +++- js/stories.js | 22 ++++++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/js/main.js b/js/main.js index 4a8171c..601a30b 100644 --- a/js/main.js +++ b/js/main.js @@ -15,6 +15,7 @@ const $navUserProfile = $("#nav-user-profile"); const $navLogOut = $("#nav-logout"); const $addStoryForm = $('#add-story-form'); +const $navSubmit = $('#nav-submit'); /** To make it easier for individual components to show just themselves, this * is a useful function that hides pretty much everything on the page. After diff --git a/js/nav.js b/js/nav.js index 44063fe..501a3d9 100644 --- a/js/nav.js +++ b/js/nav.js @@ -43,4 +43,6 @@ function navSubmitClick(evt) { evt.preventDefault(); hidePageComponents(); $addStoryForm.show(); -} \ No newline at end of file +} + +$navSubmit.on("click", navSubmitClick); diff --git a/js/stories.js b/js/stories.js index 1a652d4..d24a34e 100644 --- a/js/stories.js +++ b/js/stories.js @@ -50,3 +50,25 @@ function putStoriesOnPage() { $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(); + +}