From bd92a8245891dd2d6ba065d3256bc99489fcffe8 Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Tue, 5 Nov 2024 18:11:47 +0100 Subject: [PATCH] update notification page --- src/routes/api/update-notification/+server.ts | 25 + src/routes/notifications/+page.server.ts | 25 +- src/routes/notifications/+page.svelte | 482 ++++++++++-------- src/routes/sentiment-tracker/+page.svelte | 243 +++++---- 4 files changed, 423 insertions(+), 352 deletions(-) create mode 100644 src/routes/api/update-notification/+server.ts diff --git a/src/routes/api/update-notification/+server.ts b/src/routes/api/update-notification/+server.ts new file mode 100644 index 00000000..6286dcd2 --- /dev/null +++ b/src/routes/api/update-notification/+server.ts @@ -0,0 +1,25 @@ +import type { RequestHandler } from "./$types"; + +export const POST: RequestHandler = async ({ request, locals }) => { + const data = await request.json(); + const { pb } = locals; + + const notificationList = data?.unreadList; + let output; + + try { + const itemsToUpdate = notificationList?.filter((item) => !item.readed); + // Perform updates in parallel + await Promise.all( + itemsToUpdate.map((item) => + pb.collection("notifications").update(item, { readed: "true" }), + ), + ); + + output = "success"; + } catch (e) { + output = "failure"; + } + + return new Response(JSON.stringify(output)); +}; diff --git a/src/routes/notifications/+page.server.ts b/src/routes/notifications/+page.server.ts index abb4a0d0..e248c98c 100644 --- a/src/routes/notifications/+page.server.ts +++ b/src/routes/notifications/+page.server.ts @@ -1,22 +1,25 @@ import { redirect, error } from "@sveltejs/kit"; export const load = async ({ locals }) => { - if (!locals.pb.authStore.isValid) { + const { pb, user } = locals; + + if (!pb.authStore.isValid) { redirect(303, "/login"); } async function getNotifications() { - const postData = { userId: locals?.user?.id }; + let output; - const response = await fetch(locals?.fastifyURL + "/get-notifications", { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify(postData), - }); - - const output = (await response.json())?.items; + try { + output = await pb.collection("notifications")?.getFullList({ + filter: `opUser="${user?.id}" `, + expand: "user,post,comment", + sort: "-created", + }); + } catch (e) { + console.log(e); + output = []; + } return output; } diff --git a/src/routes/notifications/+page.svelte b/src/routes/notifications/+page.svelte index 5101eaff..0a171eac 100644 --- a/src/routes/notifications/+page.svelte +++ b/src/routes/notifications/+page.svelte @@ -1,197 +1,215 @@ - - - - + - {$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ''} Notifications · stocknear - - + + {$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ""} Notifications + · stocknear + + - - - - - - - + + + + + + + - - - - - - + + + + + + - - -
- - - -
- -

- Notifications -

- - -
-
- - - - {#if isLoaded } +
+ - {#if notificationList?.length !== 0} - - - -
- {#each notificationList as item} - -
goToPost(item)} class="hover:bg-[#2B2B2B] p-3 mb-3 ml-1 text-gray-200 w-full {!item?.readed ? 'bg-[#F9AB00] bg-opacity-[0.1]' : ''} cursor-pointer"> -
+
+
+
+
+
+

+ Notification +

+
- - - -
- {#if item?.notifyType === 'vote'} -
-
- - - upvoted your {item?.comment ? 'comment' : 'post'} - -
- {formatDate(item?.created)} ago -
- {:else if item?.notifyType === 'priceAlert'} - - -
-
-
- {/each} + {:else} +
+ Empty just like our souls... + +
+ {/if} +
-
+
- - {/if} - -
- -
- - - - \ No newline at end of file +
+
+
diff --git a/src/routes/sentiment-tracker/+page.svelte b/src/routes/sentiment-tracker/+page.svelte index e230dc65..6cff7ca2 100644 --- a/src/routes/sentiment-tracker/+page.svelte +++ b/src/routes/sentiment-tracker/+page.svelte @@ -10,9 +10,8 @@ export let data; - let isLoaded = false; - let rawData = []; - let stockList = []; + let rawData = data?.getSentimentTracker ?? []; + let stockList = rawData?.slice(0, 50) ?? []; async function handleScroll() { const scrollThreshold = document.body.offsetHeight * 0.8; // 80% of the website height @@ -25,11 +24,6 @@ } onMount(() => { - rawData = data?.getSentimentTracker ?? []; - stockList = rawData?.slice(0, 50) ?? []; - - isLoaded = true; - if (data?.user?.tier === "Pro") { window.addEventListener("scroll", handleScroll); return () => { @@ -171,139 +165,126 @@ - {#if isLoaded} -
+ - - We update our data in realtime to provide you with the latest trends - and the most bullish stocks being discussed on Twitter and StockTwits -
+ We update our data in realtime to provide you with the latest trends + and the most bullish stocks being discussed on Twitter and StockTwits + -
-
+
+ -
- - - - - {#each stockList as item, index} - + + + + {#each stockList as item, index} + + + {item?.rank} + - + - + - + - + - + - - - {/each} - -
- - {item?.rank} - - - + + - {item?.name?.length > charNumber - ? item?.name?.slice(0, charNumber) + "..." - : item?.name} - + {item?.name?.length > charNumber + ? item?.name?.slice(0, charNumber) + "..." + : item?.name} + - {abbreviateNumber(item?.marketCap)} - + {abbreviateNumber(item?.marketCap)} + - {item?.price} - + {item?.price} + - {item?.changesPercentage > 0 - ? "+" - : ""}{item?.changesPercentage}% - + {item?.changesPercentage > 0 + ? "+" + : ""}{item?.changesPercentage}% + -
-
- {item?.sentiment >= 80 - ? "Very Bullish" - : item?.sentiment >= 55 - ? "Bullish" - : item?.sentiment > 50 - ? "Mixed" - : "Bearish"} -
-
- {item?.sentiment} -
+
+
+
+ {item?.sentiment >= 80 + ? "Very Bullish" + : item?.sentiment >= 55 + ? "Bullish" + : item?.sentiment > 50 + ? "Mixed" + : "Bearish"}
-
-
- +
+ {item?.sentiment} +
+
+ + + {/each} + +
- {:else} -
-
- -
-
- {/if} + +