diff --git a/src/lib/components/WatchListCard.svelte b/src/lib/components/WatchListCard.svelte index dfc594d1..893ef313 100644 --- a/src/lib/components/WatchListCard.svelte +++ b/src/lib/components/WatchListCard.svelte @@ -135,7 +135,6 @@ async function getWatchlistData() }); const output = await response.json(); -console.log(output) try { watchList = sortTickersByChange(output[0]); diff --git a/src/routes/api/all-watchlists/+server.ts b/src/routes/api/all-watchlists/+server.ts index bd6cae66..624f61d5 100644 --- a/src/routes/api/all-watchlists/+server.ts +++ b/src/routes/api/all-watchlists/+server.ts @@ -1,9 +1,5 @@ import type { RequestHandler } from "./$types"; -export const config = { - runtime: "nodejs20.x", -}; - export const GET = (async ({ locals }) => { const { user, pb } = locals; let output; diff --git a/src/routes/reddit-tracker/+page.server.ts b/src/routes/reddit-tracker/+page.server.ts new file mode 100644 index 00000000..79b43beb --- /dev/null +++ b/src/routes/reddit-tracker/+page.server.ts @@ -0,0 +1,26 @@ +export const load = async ({ locals, setHeaders }) => { + const getRedditTracker = async () => { + let output; + + const { apiKey, apiURL } = locals; + + const response = await fetch(apiURL + "/reddit-tracker", { + method: "GET", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + }); + + output = await response.json(); + + setHeaders({ "cache-control": "public, max-age=300" }); + + return output; + }; + + // Make sure to return a promise + return { + getRedditTracker: await getRedditTracker(), + }; +}; diff --git a/src/routes/reddit-tracker/+page.ts b/src/routes/reddit-tracker/+page.ts deleted file mode 100644 index 4c78800b..00000000 --- a/src/routes/reddit-tracker/+page.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getRedditTracker = async () => { - let output; - - const cachedData = getCache("", "getRedditTracker"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - - const response = await fetch(apiURL + "/reddit-tracker", { - method: "GET", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - }); - - output = await response.json(); - - setCache("", output, "getRedditTracker"); - } - - //output = data?.user?.tier !== 'Pro' ? output?.slice(0,6) : output; - - return output; - }; - - // Make sure to return a promise - return { - getRedditTracker: await getRedditTracker(), - }; -}; diff --git a/src/routes/stocks/[tickerID]/+layout.server.ts b/src/routes/stocks/[tickerID]/+layout.server.ts index e12eb0bc..83732917 100644 --- a/src/routes/stocks/[tickerID]/+layout.server.ts +++ b/src/routes/stocks/[tickerID]/+layout.server.ts @@ -80,7 +80,7 @@ export const load = async ({ params, locals, cookies, setHeaders }) => { 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), diff --git a/src/routes/watchlist/+page.ts b/src/routes/watchlist/+page.server.ts similarity index 62% rename from src/routes/watchlist/+page.ts rename to src/routes/watchlist/+page.server.ts index 7926142b..0ea57720 100644 --- a/src/routes/watchlist/+page.ts +++ b/src/routes/watchlist/+page.server.ts @@ -1,10 +1,5 @@ -/* -import { getCache, setCache } from '$lib/store'; - - - -export const load = async ({parent}) => { - +export const load = async ({ locals }) => { + /* const getMiniPlotsIndex = async () => { let output; @@ -30,12 +25,25 @@ export const load = async ({parent}) => { return output; }; + */ + const getAllWatchlist = async () => { + const { pb, user } = locals; + try { + const output = await pb.collection("watchlist").getFullList({ + filter: `user="${user?.id}"`, + }); + + return output; + } catch (e) { + return []; + } + }; // Make sure to return a promise return { - getMiniPlotsIndex: await getMiniPlotsIndex(), + //getMiniPlotsIndex: await getMiniPlotsIndex(), + getAllWatchlist: await getAllWatchlist(), }; }; -*/ diff --git a/src/routes/watchlist/+page.svelte b/src/routes/watchlist/+page.svelte index a26e0961..f4257aea 100644 --- a/src/routes/watchlist/+page.svelte +++ b/src/routes/watchlist/+page.svelte @@ -89,9 +89,8 @@ rawData?.forEach(({ symbol, priceData, changesPercentage, previousClose }) => { let displayWatchList; - let allList = []; - - + let allList = data?.getAllWatchlist; + async function handleRenameList() { const clicked = document.getElementById('editNameWatchList'); clicked.dispatchEvent(new MouseEvent('click')); @@ -309,27 +308,7 @@ async function deleteWatchList(event) { -async function getAllListData() -{ - const response = await fetch('/api/all-watchlists', { - method: 'GET', - headers: { - "Content-Type": "application/json" - }, -}); - allList = await response.json(); - - if(allList?.length !== 0) - { - displayWatchList = allList[0] - } - else { - displayWatchList = ''; - } - - -} function changeWatchList(newWatchList) { @@ -339,17 +318,16 @@ function changeWatchList(newWatchList) } -onMount( async () => { - -if (data?.user) -{ - await getAllListData() - -} +onMount(() => { +if(allList?.length !== 0) + { + displayWatchList = allList[0] + } + else { + displayWatchList = ''; + } isLoaded = true; - - }); onDestroy( () => {