From 692e6fe2374d68e0a26e06a32748411036feefbb Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Wed, 23 Oct 2024 14:26:46 +0200 Subject: [PATCH] ui fix --- src/routes/api/historical-price/+server.ts | 2 +- src/routes/etf/[tickerID]/+page.svelte | 2689 ++++++++++---------- src/routes/stocks/[tickerID]/+page.svelte | 151 +- 3 files changed, 1476 insertions(+), 1366 deletions(-) diff --git a/src/routes/api/historical-price/+server.ts b/src/routes/api/historical-price/+server.ts index 27a47a5d..9d1409b0 100644 --- a/src/routes/api/historical-price/+server.ts +++ b/src/routes/api/historical-price/+server.ts @@ -5,7 +5,7 @@ export const POST: RequestHandler = async ({ request, locals }) => { const { apiURL, apiKey } = locals; const postData = { ticker: data?.ticker, timePeriod: data?.timePeriod }; - const response = await fetch(apiURL + "/export-price-data", { + const response = await fetch(apiURL + "/historical-price", { method: "POST", headers: { "Content-Type": "application/json", diff --git a/src/routes/etf/[tickerID]/+page.svelte b/src/routes/etf/[tickerID]/+page.svelte index e7668d53..b7435f82 100644 --- a/src/routes/etf/[tickerID]/+page.svelte +++ b/src/routes/etf/[tickerID]/+page.svelte @@ -1,86 +1,104 @@ - + + + + {$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ""} + {$displayCompanyName} ({$etfTicker}) Stock Price, Quote & News · stocknear + - - - - {$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ''} {$displayCompanyName} ({$etfTicker}) Stock Price, Quote & News · stocknear - - - - - - - - - - - - - - + + + + + + + + + + + -
- -
+
+
+ +
+
+ + +
+
+
+ {#if $isCrosshairMoveActive} + {displayLegend?.close} + {:else if !$isCrosshairMoveActive && $realtimePrice !== null} + {$realtimePrice} + {:else} + {displayLegend?.close} + {/if} -
- -
-
- - - - - -
-
- -
- {#if $isCrosshairMoveActive } - {displayLegend?.close} - {:else if !$isCrosshairMoveActive && $realtimePrice !== null} - {$realtimePrice} - {:else} - {displayLegend?.close} - - {/if} - - {#if $priceIncrease === true} -
- {:else if $priceIncrease === false} -
- {/if} - -
- - - - -
- - {#if displayLegend?.change >= 0} - - +{displayLegend?.change}% - {:else if displayLegend?.change < 0} - - {displayLegend?.change}% - {/if} - - {displayLegend?.date} - - - -
- -
- - {#if Object?.keys(prePostData)?.length !== 0 && prePostData?.price !== 0} -
-
- - {prePostData?.price} - - {#if prePostData?.changesPercentage >= 0} - ({prePostData?.changesPercentage}%) - {:else if prePostData?.changesPercentage < 0} - ({prePostData?.changesPercentage}%) - {/if} -
- {#if $isBeforeMarketOpen && !$isOpen && !$isWeekend} -
- Pre-market: - -
- {:else} -
- Post-market: - -
- {/if} - -
- {/if} - - -
- - - - -
- - - - - - - - - - \ No newline at end of file + } + + :root { + --date-picker-background: #09090b; + --date-picker-foreground: #f7f7f7; + } + diff --git a/src/routes/stocks/[tickerID]/+page.svelte b/src/routes/stocks/[tickerID]/+page.svelte index f9b00005..21225137 100644 --- a/src/routes/stocks/[tickerID]/+page.svelte +++ b/src/routes/stocks/[tickerID]/+page.svelte @@ -709,6 +709,48 @@ async function exportData(timePeriod: string) { let exportList = []; + + const response = await fetch("/api/export-price-data", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ ticker: $stockTicker, timePeriod: timePeriod }), + }); + + exportList = await response.json(); + + exportList = exportList?.map(({ time, open, high, low, close, date }) => ({ + date: timePeriod === "max" ? time : date, // Use 'time' if timePeriod is "max", otherwise use 'date' + open, + high, + low, + close, + })); + + const csvRows = []; + + // Add headers row + csvRows.push("time,open,high,low,close"); + + // Add data rows + for (const row of exportList) { + const csvRow = `${row.date},${row.open},${row.high},${row.low},${row.close}`; + csvRows.push(csvRow); + } + + // Create CSV blob and trigger download + const csv = csvRows.join("\n"); + const blob = new Blob([csv], { type: "text/csv" }); + const url = window.URL.createObjectURL(blob); + const a = document.createElement("a"); + a.setAttribute("hidden", ""); + a.setAttribute("href", url); + a.setAttribute("download", `${$stockTicker}_${timePeriod}.csv`); + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + /* if (data?.user) { const response = await fetch("/api/historical-price", { method: "POST", @@ -757,6 +799,7 @@ style: "border-radius: 200px; background: #333; color: #fff;", }); } + */ } function updateClosePrice(data, extendPriceChart) { @@ -1097,37 +1140,38 @@ /> - - - - - - - Historical Stock Price - - - - - exportData("30min")} - class="cursor-pointer hover:bg-[#27272A]" - > - - 30 min - - exportData("1hour")} - class="cursor-pointer hover:bg-[#27272A]" - > - - 1 hour - - exportData("max")} - class="cursor-pointer hover:bg-[#27272A]" - > - 1 day - - - - + 1 hour + + exportData("max")} + class="cursor-pointer hover:bg-[#27272A]" + > + 1 day + + + + + {/if}