From 190d1c917a1e7f304de146b41f9e600c5abb0c2a Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Wed, 13 Nov 2024 16:53:39 +0100 Subject: [PATCH] add table component to top shorted stocks --- src/lib/components/Table/Table.svelte | 52 +++-- src/routes/list/exchange/[slug]/+page.svelte | 19 -- src/routes/most-shorted-stocks/+page.svelte | 227 +++---------------- 3 files changed, 69 insertions(+), 229 deletions(-) diff --git a/src/lib/components/Table/Table.svelte b/src/lib/components/Table/Table.svelte index af2e01ed..28b77d5a 100644 --- a/src/lib/components/Table/Table.svelte +++ b/src/lib/components/Table/Table.svelte @@ -27,7 +27,10 @@ { name: "Revenue", rule: "revenue" }, ]; + export let hideLastRow = false; + let ruleOfList = defaultList; + const defaultRules = defaultList?.map((item) => item?.rule); let pagePathName = $page?.url?.pathname; let testList = []; @@ -144,20 +147,25 @@ for (let i = 0; i < updateData.length; i++) { if (rawData[i]) { - // Check if "rank" is missing in updateData[i] and add it if it exists in rawData[i] + // Merge only the fields from rawData that are in defaultRules + let newData = { ...updateData[i] }; + + // Merge fields from defaultList (marketCap, price, etc.) + defaultRules.forEach((rule) => { + if (!(rule in updateData[i]) && rule in rawData[i]) { + newData[rule] = rawData[i][rule]; + } + }); + + // Ensure 'rank' and 'years' are added if they are missing in updateData if (!("rank" in updateData[i]) && "rank" in rawData[i]) { - updateData[i] = { - ...updateData[i], - rank: rawData[i]["rank"], - }; + newData.rank = rawData[i]["rank"]; } - // Check if "years" is missing in updateData[i] and add it if it exists in rawData[i] if (!("years" in updateData[i]) && "years" in rawData[i]) { - updateData[i] = { - ...updateData[i], - years: rawData[i]["years"], - }; + newData.years = rawData[i]["years"]; } + + updateData[i] = newData; } } @@ -591,9 +599,15 @@ - {#each stockList as item} + {#each stockList as item, index} {#each columns as column} {item[column.key]?.toFixed(2)}% {/if} + {:else if column?.type === "rating"} + {#if ["Strong Buy", "Buy"].includes(item[column.key])} + {item[column.key]} + {:else if ["Strong Sell", "Sell"].includes(item[column.key])} + {item[column.key]} + {:else if item[column.key] === "Hold"} + {item[column.key]} + {:else} + - + {/if} {:else} - {item[column.key] !== null ? item[column.key] : "-"} + {item[column.key] !== null && item[column.key] !== undefined + ? item[column.key] + : "-"} {/if} {/each} diff --git a/src/routes/list/exchange/[slug]/+page.svelte b/src/routes/list/exchange/[slug]/+page.svelte index 3e74670b..60c4ecd2 100644 --- a/src/routes/list/exchange/[slug]/+page.svelte +++ b/src/routes/list/exchange/[slug]/+page.svelte @@ -1,12 +1,10 @@
diff --git a/src/routes/most-shorted-stocks/+page.svelte b/src/routes/most-shorted-stocks/+page.svelte index 1f74a4d4..687c7c5c 100644 --- a/src/routes/most-shorted-stocks/+page.svelte +++ b/src/routes/most-shorted-stocks/+page.svelte @@ -1,121 +1,27 @@ @@ -156,7 +62,7 @@
- {#if isLoaded} -
-
- - - - - - {#each stockList as item, index} - - - - - - - - - - - - - - - - {/each} - -
- {item?.rank} - - - - {item?.name?.length > charNumber - ? item?.name?.slice(0, charNumber) + "..." - : item?.name} - - {item?.shortRatio} - - {abbreviateNumber(item?.sharesShort)} - - {item?.shortFloatPercent}% - - {item?.shortOutStandingPercent}% -
-
-
- {:else} -
-
- -
-
- {/if} - {#if isLoaded} - + - {/if} + + +