diff --git a/src/routes/stocks/[tickerID]/+page.svelte b/src/routes/stocks/[tickerID]/+page.svelte index 6549866c..ce103781 100644 --- a/src/routes/stocks/[tickerID]/+page.svelte +++ b/src/routes/stocks/[tickerID]/+page.svelte @@ -10,11 +10,9 @@ swapComponent, governmentContractComponent, optionsNetFlowComponent, - borrowedShareComponent, clinicalTrialComponent, optionComponent, failToDeliverComponent, - marketMakerComponent, screenWidth, displayCompanyName, numberOfUnreadNotification, @@ -46,8 +44,7 @@ import { convertTimestamp } from "$lib/utils"; import { Button } from "$lib/components/shadcn/button/index.js"; import * as DropdownMenu from "$lib/components/shadcn/dropdown-menu/index.js"; - - import toast from "svelte-french-toast"; + import { goto } from "$app/navigation"; export let data; export let form; @@ -708,49 +705,52 @@ } async function exportData(timePeriod: string) { - let exportList = []; + if (data?.user?.tier === "Pro") { + let exportList = []; - const response = await fetch("/api/export-price-data", { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ ticker: $stockTicker, timePeriod: timePeriod }), - }); + 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 = 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, - })); + 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 = []; + const csvRows = []; - // Add headers row - csvRows.push("time,open,high,low,close"); + // 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); - } + // 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); - /* + // 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", @@ -800,6 +800,9 @@ }); } */ + } else { + goto("/pricing"); + } } function updateClosePrice(data, extendPriceChart) { @@ -1189,37 +1192,35 @@ on:click={() => exportData("30min")} class="cursor-pointer hover:bg-[#27272A]" > - + + 30 min exportData("1hour")} class="cursor-pointer hover:bg-[#27272A]" > - + 1 hour