From 3960ff156ebfc0cd2ec9afc188bbbd8b0c53d755 Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Sat, 1 Jun 2024 16:46:36 +0200 Subject: [PATCH] update community sentiment component --- src/lib/components/CommunitySentiment.svelte | 25 ++++++++++---------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/lib/components/CommunitySentiment.svelte b/src/lib/components/CommunitySentiment.svelte index 208088be..b8941479 100644 --- a/src/lib/components/CommunitySentiment.svelte +++ b/src/lib/components/CommunitySentiment.svelte @@ -14,6 +14,17 @@ async function updateSentiment(sentiment:string) { if(!alreadyVoted) { + + if(sentiment === 'upvote') { + upvote +=1 + } + else if(sentiment === 'downvote') { + downvote +=1 + } + alreadyVoted = sentiment; + calculateStats() + + const postData = { 'ticker': $stockTicker, 'sentiment': sentiment, @@ -29,17 +40,7 @@ async function updateSentiment(sentiment:string) { }); // make a POST request to the server with the FormData object const output = await response.json(); - if(output === 'success') { - if(sentiment === 'upvote') { - upvote +=1 - } - else if(sentiment === 'downvote') { - downvote +=1 - } - alreadyVoted = sentiment; - calculateStats() - } - else { + if(output !== 'success') { toast.error('Something went wrong. Please try again!', { style: 'border-radius: 10px; background: #383838; color: #fff;', }); @@ -89,7 +90,7 @@ $: { What do you think of {$stockTicker} today? - The community is bullish about {$displayCompanyName} today. + The community is {upvote > downvote ? 'bullish' : upvote < downvote ? 'bearish' : 'neutral'} about {$displayCompanyName} today.