From 1a0a5c8b6eca9f94742196fb2df54e6109d68f09 Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Wed, 13 Nov 2024 18:45:56 +0100 Subject: [PATCH] add table component for industry page --- .../list/industry/[slug]/+page.server.ts | 9 +- src/routes/list/industry/[slug]/+page.svelte | 355 ++---------------- 2 files changed, 48 insertions(+), 316 deletions(-) diff --git a/src/routes/list/industry/[slug]/+page.server.ts b/src/routes/list/industry/[slug]/+page.server.ts index fdf057fd..13e531e7 100644 --- a/src/routes/list/industry/[slug]/+page.server.ts +++ b/src/routes/list/industry/[slug]/+page.server.ts @@ -1,7 +1,12 @@ export const load = async ({ params, locals, setHeaders }) => { - const getIndustryStocks = async () => { const { apiKey, apiURL } = locals; + const getParams = async () => { + return params.slug; + }; + + const getIndustryStocks = async () => { + const postData = { ticker: params.slug }; const response = await fetch(apiURL + "/industry-stocks", { method: "POST", @@ -24,6 +29,8 @@ export const load = async ({ params, locals, setHeaders }) => { // Make sure to return a promise return { + getParams: await getParams(), + getIndustryStocks: await getIndustryStocks(), }; }; diff --git a/src/routes/list/industry/[slug]/+page.svelte b/src/routes/list/industry/[slug]/+page.svelte index 4a063c27..3c68866f 100644 --- a/src/routes/list/industry/[slug]/+page.svelte +++ b/src/routes/list/industry/[slug]/+page.svelte @@ -1,340 +1,65 @@
- - The {data?.getIndustryStocks?.name} Industry has a total of {data - ?.getIndustryStocks?.stocks?.length} stocks, with a combined market cap of - {abbreviateNumber(totalMarketCap, true)}, total revenue of {abbreviateNumber( + The industry has a total of {rawData?.length} stocks, with a combined market + cap of {abbreviateNumber(totalMarketCap)} and a total revenue of {abbreviateNumber( totalRevenue, - true, - )} and an average PE Ratio of {avgPERatio}. + )}.
-

- Historical PE Ratio -

-
- {#if isLoaded} - - {:else} -
-
- +
+
+
+
Total Stocks
+
+ {new Intl.NumberFormat("en")?.format(rawData?.length)}
- {/if} +
+
+
+
Total Market Cap
+
+ {abbreviateNumber(totalMarketCap)} +
+
+
+
+
+
Total Revenue
+
+ {abbreviateNumber(totalRevenue)} +
+
+
-
- -
- - - - - - {#each stockList as item} - - - - - - - - - - - - - - {/each} - -
- - - {abbreviateNumber(item?.marketCap)} - - {item?.changesPercentage !== null - ? item?.changesPercentage - : "-"} - - {item?.volume !== null ? abbreviateNumber(item?.volume) : "-"} - - {item?.revenue === 0 ? "-" : abbreviateNumber(item?.revenue)} -
-
-
+ - -