From 1616f92c16aeb5600830bd9a0fa1c5f5c47cbea6 Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Fri, 25 Oct 2024 18:01:31 +0200 Subject: [PATCH] add news component --- src/lib/components/News.svelte | 160 ++++++++++ .../stocks/[tickerID]/+layout.server.ts | 5 +- src/routes/stocks/[tickerID]/+layout.svelte | 17 -- src/routes/stocks/[tickerID]/+page.svelte | 173 +---------- .../stocks/[tickerID]/news/+page.svelte | 285 ++++++++++-------- 5 files changed, 336 insertions(+), 304 deletions(-) create mode 100644 src/lib/components/News.svelte diff --git a/src/lib/components/News.svelte b/src/lib/components/News.svelte new file mode 100644 index 00000000..43b32f39 --- /dev/null +++ b/src/lib/components/News.svelte @@ -0,0 +1,160 @@ + + +
+ +
+
+
+ +
+ +
+
+
+ +
+ {#each newsList as item} +
+ {#if (videoId = checkIfYoutubeVideo(item.url))} +
+ +
+
+

+ {formatDate(item?.publishedDate)} ago · {item?.site} +

+ + {item?.title} +

+ {item?.text} +

+
+
+ {:else} +
+ +
+ news image +
+
+
+

+ {formatDate(item?.publishedDate)} ago · {item?.site} +

+ + {item?.title} +

+ {item?.text} +

+
+
+
+ {/if} +
+
+ {/each} +
+ {#if newsList?.length !== rawData?.length} + + {/if} +
+
diff --git a/src/routes/stocks/[tickerID]/+layout.server.ts b/src/routes/stocks/[tickerID]/+layout.server.ts index 61518968..2189318e 100644 --- a/src/routes/stocks/[tickerID]/+layout.server.ts +++ b/src/routes/stocks/[tickerID]/+layout.server.ts @@ -76,11 +76,12 @@ export const load = async ({ params, locals, cookies, setHeaders }) => { "/next-earnings", "/earnings-surprise", "/dividend-announcement", + "/stock-news", ]; const promises = [ ...endpoints.map((endpoint) => - fetchData(apiURL, apiKey, endpoint, tickerID) + fetchData(apiURL, apiKey, endpoint, tickerID), ), fetchWatchlist(pb, user?.id), //fetchFromFastify(fastifyURL, '/get-portfolio-data', user?.id), @@ -99,6 +100,7 @@ export const load = async ({ params, locals, cookies, setHeaders }) => { getNextEarnings, getEarningsSurprise, getDividendAnnouncement, + getNews, getUserWatchlist, getCommunitySentiment, ] = await Promise.all(promises); @@ -115,6 +117,7 @@ export const load = async ({ params, locals, cookies, setHeaders }) => { getNextEarnings, getEarningsSurprise, getDividendAnnouncement, + getNews, getUserWatchlist, getCommunitySentiment, companyName: cleanString(getStockDeck?.at(0)?.companyName), diff --git a/src/routes/stocks/[tickerID]/+layout.svelte b/src/routes/stocks/[tickerID]/+layout.svelte index 4d4e823b..bb8cde3f 100644 --- a/src/routes/stocks/[tickerID]/+layout.svelte +++ b/src/routes/stocks/[tickerID]/+layout.svelte @@ -894,23 +894,6 @@ function handleTypeOfTrade(state:string) : 'bg-[#09090B]'} mt-1 h-[3px] rounded-full w-[2.5rem]" /> -
  • - changeSection("news")} - class="px-3 text-sm sm:text-[1rem] font-medium text-gray-400 sm:hover:text-white {displaySection === - 'news' - ? 'text-white ' - : 'bg-[#09090B]'}" - > - News - -
    -
  • diff --git a/src/routes/stocks/[tickerID]/+page.svelte b/src/routes/stocks/[tickerID]/+page.svelte index a7722a5c..9fc2c7de 100644 --- a/src/routes/stocks/[tickerID]/+page.svelte +++ b/src/routes/stocks/[tickerID]/+page.svelte @@ -4,25 +4,10 @@ import { getCache, setCache, - fomcImpactComponent, - corporateLobbyingComponent, - revenueSegmentationComponent, - taRatingComponent, - swapComponent, - governmentContractComponent, - optionsNetFlowComponent, - clinicalTrialComponent, - optionComponent, - failToDeliverComponent, screenWidth, displayCompanyName, numberOfUnreadNotification, globalForm, - varComponent, - shareStatisticsComponent, - enterpriseComponent, - darkPoolComponent, - shareholderComponent, isCrosshairMoveActive, realtimePrice, priceIncrease, @@ -36,6 +21,7 @@ } from "$lib/store"; import { onDestroy, onMount } from "svelte"; import BullBearSay from "$lib/components/BullBearSay.svelte"; + import NextEarnings from "$lib/components/NextEarnings.svelte"; import EarningsSurprise from "$lib/components/EarningsSurprise.svelte"; import DividendAnnouncement from "$lib/components/DividendAnnouncement.svelte"; @@ -1570,7 +1556,7 @@
    - -
    - {#await import("$lib/components/RevenueSegmentation.svelte") then { default: Comp }} - - {/await} -
    -
    - - -
    - {#await import("$lib/components/ClinicalTrial.svelte") then { default: Comp }} +
    + {#await import("$lib/components/News.svelte") then { default: Comp }} - {/await} -
    - - - -
    - {#await import("$lib/components/VaR.svelte") then { default: Comp }} - - {/await} -
    -
    - - -
    - {#await import("$lib/components/GovernmentContract.svelte") then { default: Comp }} - - {/await} -
    -
    - - -
    - {#await import("$lib/components/FOMCImpact.svelte") then { default: Comp }} - - {/await} -
    -
    - - -
    - {#await import("$lib/components/CorporateLobbying.svelte") then { default: Comp }} - - {/await} -
    -
    - - -
    - {#await import("$lib/components/Swap.svelte") then { default: Comp }} - - {/await} -
    -
    - - -
    - {#await import("$lib/components/OptionsData.svelte") then { default: Comp }} - - {/await} -
    -
    - - -
    - {#await import("$lib/components/OptionsNetFlow.svelte") then { default: Comp }} - - {/await} -
    -
    - - -
    - {#await import("$lib/components/FailToDeliver.svelte") then { default: Comp }} - - {/await} -
    -
    - - -
    - {#await import("$lib/components/DarkPool.svelte") then { default: Comp }} - - {/await} -
    -
    - - +
    + - - -
    - {#await import("$lib/components/TARating.svelte") then { default: Comp }} - - {/await} -
    -
    diff --git a/src/routes/stocks/[tickerID]/news/+page.svelte b/src/routes/stocks/[tickerID]/news/+page.svelte index 27cca39c..f931861c 100644 --- a/src/routes/stocks/[tickerID]/news/+page.svelte +++ b/src/routes/stocks/[tickerID]/news/+page.svelte @@ -1,159 +1,190 @@ - - - - {$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ''} {$displayCompanyName} ({$stockTicker}) latest Stock Market News and Breaking Stories · stocknear + {$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ""} + {$displayCompanyName} ({$stockTicker}) latest Stock Market News and Breaking + Stories · stocknear - - + + - - - + + + - - - + + + - - +
    +
    +
    +
    +
    +

    News

    +
    + {#if newsList?.length !== 0} +
    + {#each newsList as item} +
    + {#if (videoId = checkIfYoutubeVideo(item.url))} + + {:else} + +
    + news image +
    +
    + {/if} +
    +

    + {formatDate(item?.publishedDate)} ago · {item?.site} +

    -
    -
    -
    -
    -
    -

    - News -

    -
    - - {#if newsList?.length !== 0} - -
    - {#each newsList as item} -
    - {#if videoId = checkIfYoutubeVideo(item.url)} - - {:else} - -
    - news image -
    -
    - {/if} -
    -

    - {formatDate(item?.publishedDate)} ago · {item?.site} -

    - - - {item?.title} -

    - {item?.text} -

    -
    -
    -
    - -
    - {/each} - -
    - {#if newsList?.length !== rawNews?.length} - - {/if} - - - {:else} -
    - - No news article published yet! -
    - {/if} - - + + {item?.title} +

    + {item?.text} +

    +
    -
    -
    -
    \ No newline at end of file +
    + +
    + {/each} +
    + {#if newsList?.length !== rawNews?.length} + + {/if} + {:else} +
    + + No news article published yet! +
    + {/if} +
    +
    +
    +