first step to convert +page.ts to +page.server.ts
This commit is contained in:
parent
80e6369093
commit
8149d25f29
@ -135,7 +135,6 @@ async function getWatchlistData()
|
||||
});
|
||||
|
||||
const output = await response.json();
|
||||
console.log(output)
|
||||
|
||||
try {
|
||||
watchList = sortTickersByChange(output[0]);
|
||||
|
||||
@ -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;
|
||||
|
||||
26
src/routes/reddit-tracker/+page.server.ts
Normal file
26
src/routes/reddit-tracker/+page.server.ts
Normal file
@ -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(),
|
||||
};
|
||||
};
|
||||
@ -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(),
|
||||
};
|
||||
};
|
||||
@ -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),
|
||||
|
||||
@ -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(),
|
||||
};
|
||||
};
|
||||
*/
|
||||
@ -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( () => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user