diff --git a/src/lib/store.ts b/src/lib/store.ts index e8e5f22d..baa5d736 100644 --- a/src/lib/store.ts +++ b/src/lib/store.ts @@ -74,7 +74,7 @@ export const oauthProvider = writable( ("")); export const switchWatchList = writable((false)); -export const cachedPosts = writable(> []); +export const cachedPosts = writable(> {}); export const currentPagePosition = writable( (0)); export const similarTickerClicked = writable((false)); diff --git a/src/routes/community/+page.svelte b/src/routes/community/+page.svelte index 5ff20e93..fc2aa24c 100644 --- a/src/routes/community/+page.svelte +++ b/src/routes/community/+page.svelte @@ -163,7 +163,7 @@ async function getPost() { let postData; - if ($cachedPosts?.length === 0) + if (Object?.keys($cachedPosts)?.length === 0) { postData = { //userId: data?.user.id, @@ -176,8 +176,8 @@ async function getPost() { { postData = { //userId: data?.user.id, - startPage: $cachedPosts[0].currentPage, - seenPostId: $cachedPosts[0].seenPostId.length === 0 ? [] : $cachedPosts[0].seenPostId, + startPage: $cachedPosts?.currentPage, + seenPostId: $cachedPosts?.seenPostId.length === 0 ? [] : $cachedPosts?.seenPostId, sortingPosts: sortingPosts, }; } @@ -227,9 +227,9 @@ let LoginPopup; let BottomNavigation; onMount(async () => { - if ($cachedPosts?.length === 0) { + if (Object?.keys($cachedPosts)?.length === 0) { // Only make API requests if cached posts are not available - [communityStats, moderators, posts, discordData] = await Promise.all([ + [communityStats, moderators, posts, discordData] = await Promise?.all([ getCommunityStats(), getModerators(), getPost(), @@ -244,7 +244,7 @@ onMount(async () => { else { // Use cached data if available - posts = $cachedPosts?.at(0)?.posts; + posts = $cachedPosts?.posts; communityStats = getCache('', 'getCommunityStats'); moderators = getCache('', 'getModerators'); discordData = getCache('','getDiscordWidget'); @@ -269,7 +269,7 @@ onDestroy(async () => { -let sortingPosts = $cachedPosts?.at(0)?.sortingPosts?.length > 0 ? $cachedPosts?.at(0)?.sortingPosts : 'hot'; +let sortingPosts = $cachedPosts?.sortingPosts?.length > 0 ? $cachedPosts?.sortingPosts : 'hot'; async function handleCategoryOfPosts(state) { loading = true; @@ -280,7 +280,7 @@ async function handleCategoryOfPosts(state) { noPostMore = false; sortingPosts = state; - $cachedPosts = []; + $cachedPosts = {}; posts = await getPost(); loading = false; } @@ -319,7 +319,7 @@ $: { $: { if(posts) { - $cachedPosts = [{"sortingPosts": sortingPosts,'currentPage': currentPage, 'seenPostId': seenPostId, 'posts': posts}]; + $cachedPosts = {"sortingPosts": sortingPosts,'currentPage': currentPage, 'seenPostId': seenPostId, 'posts': posts}; } } diff --git a/src/routes/community/post/[postId]/+page.server.ts b/src/routes/community/post/[postId]/+page.server.ts index 2d3a6af5..14b7981b 100644 --- a/src/routes/community/post/[postId]/+page.server.ts +++ b/src/routes/community/post/[postId]/+page.server.ts @@ -1,38 +1,7 @@ import { error, fail, redirect } from "@sveltejs/kit"; import { validateData } from "$lib/utils"; import { loginUserSchema, registerUserSchema } from "$lib/schemas"; -import { userRegion, oauthState, oauthVerifier, oauthProvider } from '$lib/store'; - - -const usRegion = ['cle1','iad1','pdx1','sfo1']; -let fastifyURL = import.meta.env.VITE_EU_FASTIFY_URL; - -userRegion.subscribe(value => { -if (usRegion.includes(value)) { - fastifyURL = import.meta.env.VITE_USEAST_FASTIFY_URL; -} else { - fastifyURL = import.meta.env.VITE_EU_FASTIFY_URL; -} -}); - - -export const load = async ({ params }) => { - - - const getPostId = async () => { - - return params.postId; - }; - - - return { - getPostId: await getPostId(), - }; - - -}; - - +import { oauthState, oauthVerifier, oauthProvider } from '$lib/store'; export const actions = { diff --git a/src/routes/community/post/[postId]/+page.svelte b/src/routes/community/post/[postId]/+page.svelte index b2e107d3..cd242784 100644 --- a/src/routes/community/post/[postId]/+page.svelte +++ b/src/routes/community/post/[postId]/+page.svelte @@ -1,992 +1,959 @@ - - - - - {$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ''} {post.title} · stocknear - - - - - - - - - - - - - - - - - - + } + + $: { + if($commentIdDeleted?.length !== 0) + { + comments = removeCommentById(comments, $commentIdDeleted) + numberOfComments = countAllComments(comments) + } + } + + + + + + + + + {$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ''} {post.title} · stocknear + + + + + + + + + + + + + + + + + + + - - - - - -{#if isLoaded} -
- -