From b46f62b4e436468f1f132c511274bf384afa251c Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Mon, 26 Aug 2024 01:19:36 +0200 Subject: [PATCH] update bullbear component --- src/lib/components/BullBearSay.svelte | 64 ++++------------------- src/routes/stocks/[tickerID]/+page.svelte | 7 +-- 2 files changed, 11 insertions(+), 60 deletions(-) diff --git a/src/lib/components/BullBearSay.svelte b/src/lib/components/BullBearSay.svelte index aed43180..78e771da 100644 --- a/src/lib/components/BullBearSay.svelte +++ b/src/lib/components/BullBearSay.svelte @@ -3,50 +3,12 @@ import InfoModal from '$lib/components/InfoModal.svelte'; export let data; - export let marketMoods = {}; - let rawData = marketMoods; - let mode = 'bullish'; - let showFullText = false; - // Function to split text into paragraphs - - //DO NOT TOUCH THIS CODE - SAFARI 15.3 are not compatible with the previous code. The website will break. - // CONSIDER MOVING THIS LOGIC TO THE BACKEND TO REMOVE THE RISK COMPLETELY - function splitIntoParagraphs(text) { - if (!text) return []; - - // Replace "U.S." and "vs." with placeholders - const placeholderUS = '__US__'; - const placeholderVs = '__VS__'; - - let tempText = text.replace(/U\.S\./g, placeholderUS) - .replace(/vs\./g, placeholderVs); - - // Split the text based on periods followed by spaces - let paragraphs = tempText.split(/\. \s*/); + let rawData = {}; - // Restore the placeholders back to "U.S." and "vs." - paragraphs = paragraphs.map(paragraph => - paragraph.replace(new RegExp(placeholderUS, 'g'), 'U.S.') - .replace(new RegExp(placeholderVs, 'g'), 'vs.') - ); - - return paragraphs; -} - - - - let paragraphs = splitIntoParagraphs(rawData?.bullSays); - function handleMode(i) { activeIdx = i; - if(activeIdx === 0) { - paragraphs = splitIntoParagraphs(rawData?.bullSays); - } - else if (activeIdx === 1) { - paragraphs = splitIntoParagraphs(rawData?.bearSays); - } } const tabs = [ @@ -62,17 +24,15 @@ $: { if($stockTicker && typeof window !== 'undefined') { - rawData = marketMoods; - mode = 'bullish'; - showFullText = false; - paragraphs = splitIntoParagraphs(rawData?.bullSays); + rawData = data?.getBullBearSay; + activeIdx = 0; } } - {#if Object?.keys(marketMoods)?.length !== 0} + {#if Object?.keys(rawData)?.length !== 0}
@@ -125,14 +85,12 @@
-
+
- {#if showFullText} - {#each (showFullText ? paragraphs : paragraphs?.slice(0,1)) as paragraph, index} -

{paragraph} {paragraphs?.length <= index+1 ? '' : '.'}

- {/each} + {#if activeIdx === 0} +

{rawData?.bullSays}

{:else} - {paragraphs?.at(0)?.slice(0,250) + '...'} +

{rawData?.bearSays}

{/if}
@@ -144,11 +102,7 @@ {/if}
- - - +
{/if} \ No newline at end of file diff --git a/src/routes/stocks/[tickerID]/+page.svelte b/src/routes/stocks/[tickerID]/+page.svelte index b2fbf604..5220dea2 100644 --- a/src/routes/stocks/[tickerID]/+page.svelte +++ b/src/routes/stocks/[tickerID]/+page.svelte @@ -16,7 +16,6 @@ let displayChartType = 'line'; let prePostData = {}; - let marketMoods = {} let communitySentiment = {}; $: previousClose = data?.getStockQuote?.previousClose; @@ -634,12 +633,10 @@ function changeChartType() { oneYearPrice = []; threeYearPrice = []; prePostData = {}; - marketMoods = {}; communitySentiment = {} output = null; - marketMoods = data?.getBullBearSay; communitySentiment = data?.getCommunitySentiment; @@ -1178,8 +1175,8 @@ function changeChartType() { -
- +
+