ui fixes
This commit is contained in:
parent
05a14b91be
commit
226d21c6e7
@ -74,7 +74,7 @@ export const oauthProvider = writable(<string> (""));
|
|||||||
|
|
||||||
export const switchWatchList = writable(<boolean>(false));
|
export const switchWatchList = writable(<boolean>(false));
|
||||||
|
|
||||||
export const cachedPosts = writable(<Array<any>> []);
|
export const cachedPosts = writable(<Array<any>> {});
|
||||||
export const currentPagePosition = writable(<Number> (0));
|
export const currentPagePosition = writable(<Number> (0));
|
||||||
|
|
||||||
export const similarTickerClicked = writable(<boolean>(false));
|
export const similarTickerClicked = writable(<boolean>(false));
|
||||||
|
|||||||
@ -163,7 +163,7 @@ async function getPost() {
|
|||||||
|
|
||||||
let postData;
|
let postData;
|
||||||
|
|
||||||
if ($cachedPosts?.length === 0)
|
if (Object?.keys($cachedPosts)?.length === 0)
|
||||||
{
|
{
|
||||||
postData = {
|
postData = {
|
||||||
//userId: data?.user.id,
|
//userId: data?.user.id,
|
||||||
@ -176,8 +176,8 @@ async function getPost() {
|
|||||||
{
|
{
|
||||||
postData = {
|
postData = {
|
||||||
//userId: data?.user.id,
|
//userId: data?.user.id,
|
||||||
startPage: $cachedPosts[0].currentPage,
|
startPage: $cachedPosts?.currentPage,
|
||||||
seenPostId: $cachedPosts[0].seenPostId.length === 0 ? [] : $cachedPosts[0].seenPostId,
|
seenPostId: $cachedPosts?.seenPostId.length === 0 ? [] : $cachedPosts?.seenPostId,
|
||||||
sortingPosts: sortingPosts,
|
sortingPosts: sortingPosts,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -227,9 +227,9 @@ let LoginPopup;
|
|||||||
let BottomNavigation;
|
let BottomNavigation;
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
if ($cachedPosts?.length === 0) {
|
if (Object?.keys($cachedPosts)?.length === 0) {
|
||||||
// Only make API requests if cached posts are not available
|
// 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(),
|
getCommunityStats(),
|
||||||
getModerators(),
|
getModerators(),
|
||||||
getPost(),
|
getPost(),
|
||||||
@ -244,7 +244,7 @@ onMount(async () => {
|
|||||||
|
|
||||||
else {
|
else {
|
||||||
// Use cached data if available
|
// Use cached data if available
|
||||||
posts = $cachedPosts?.at(0)?.posts;
|
posts = $cachedPosts?.posts;
|
||||||
communityStats = getCache('', 'getCommunityStats');
|
communityStats = getCache('', 'getCommunityStats');
|
||||||
moderators = getCache('', 'getModerators');
|
moderators = getCache('', 'getModerators');
|
||||||
discordData = getCache('','getDiscordWidget');
|
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) {
|
async function handleCategoryOfPosts(state) {
|
||||||
loading = true;
|
loading = true;
|
||||||
@ -280,7 +280,7 @@ async function handleCategoryOfPosts(state) {
|
|||||||
noPostMore = false;
|
noPostMore = false;
|
||||||
|
|
||||||
sortingPosts = state;
|
sortingPosts = state;
|
||||||
$cachedPosts = [];
|
$cachedPosts = {};
|
||||||
posts = await getPost();
|
posts = await getPost();
|
||||||
loading = false;
|
loading = false;
|
||||||
}
|
}
|
||||||
@ -319,7 +319,7 @@ $: {
|
|||||||
$: {
|
$: {
|
||||||
if(posts)
|
if(posts)
|
||||||
{
|
{
|
||||||
$cachedPosts = [{"sortingPosts": sortingPosts,'currentPage': currentPage, 'seenPostId': seenPostId, 'posts': posts}];
|
$cachedPosts = {"sortingPosts": sortingPosts,'currentPage': currentPage, 'seenPostId': seenPostId, 'posts': posts};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,38 +1,7 @@
|
|||||||
import { error, fail, redirect } from "@sveltejs/kit";
|
import { error, fail, redirect } from "@sveltejs/kit";
|
||||||
import { validateData } from "$lib/utils";
|
import { validateData } from "$lib/utils";
|
||||||
import { loginUserSchema, registerUserSchema } from "$lib/schemas";
|
import { loginUserSchema, registerUserSchema } from "$lib/schemas";
|
||||||
import { userRegion, oauthState, oauthVerifier, oauthProvider } from '$lib/store';
|
import { 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(),
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export const actions = {
|
export const actions = {
|
||||||
|
|||||||
@ -6,8 +6,10 @@ import Downvote from '$lib/components/Downvote.svelte';
|
|||||||
import Upvote from '$lib/components/Upvote.svelte';
|
import Upvote from '$lib/components/Upvote.svelte';
|
||||||
import VideoPlayer from '$lib/components/VideoPlayer.svelte';
|
import VideoPlayer from '$lib/components/VideoPlayer.svelte';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import { onMount, onDestroy } from 'svelte';
|
import { onMount, onDestroy } from 'svelte';
|
||||||
import {cachedPosts, userRegion, screenWidth, scrollToComment, postIdDeleted, setCache, getCache, tagList, numberOfUnreadNotification, commentAdded, commentUpdated, commentIdDeleted } from '$lib/store';
|
import {userRegion, screenWidth, scrollToComment, postIdDeleted, setCache, getCache, tagList, numberOfUnreadNotification, commentAdded, commentUpdated, commentIdDeleted } from '$lib/store';
|
||||||
import { goto, afterNavigate } from '$app/navigation';
|
import { goto, afterNavigate } from '$app/navigation';
|
||||||
import { base } from '$app/paths'
|
import { base } from '$app/paths'
|
||||||
|
|
||||||
@ -30,7 +32,7 @@ userRegion.subscribe(value => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
let post = {'id': 'test', 'upvote': 0, 'downvote': 0};
|
let post = data?.getOnePost;
|
||||||
let isScrolled = false;
|
let isScrolled = false;
|
||||||
let isLoaded = false;
|
let isLoaded = false;
|
||||||
|
|
||||||
@ -40,22 +42,6 @@ let upvoteCounter = {};
|
|||||||
let downvoteCounter = {};
|
let downvoteCounter = {};
|
||||||
let userAlreadyVoted;
|
let userAlreadyVoted;
|
||||||
|
|
||||||
async function getOnePost() {
|
|
||||||
|
|
||||||
const postData = {'postId': data?.getPostId};
|
|
||||||
|
|
||||||
const response = await fetch(fastifyURL+'/get-one-post', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify(postData),
|
|
||||||
});
|
|
||||||
|
|
||||||
const output = await response.json()
|
|
||||||
return output?.items
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const handleUpvote = async (event) => {
|
const handleUpvote = async (event) => {
|
||||||
@ -295,26 +281,6 @@ let LoginPopup;
|
|||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
|
|
||||||
post = $cachedPosts?.at(0)?.posts?.find(item => item?.id === data?.getPostId) ?? {};
|
|
||||||
|
|
||||||
if (Object?.keys(post)?.length !== 0) {
|
|
||||||
[moderators, comments] = await Promise?.all([
|
|
||||||
getModerators(),
|
|
||||||
getAllComments(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
[post, moderators, comments] = await Promise?.all([
|
|
||||||
getOnePost(),
|
|
||||||
getModerators(),
|
|
||||||
getAllComments(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
numberOfComments = countAllComments(comments) || 0;
|
|
||||||
|
|
||||||
|
|
||||||
upvoteCounter[post.id] = post?.upvote;
|
upvoteCounter[post.id] = post?.upvote;
|
||||||
downvoteCounter[post.id] = post?.downvote;
|
downvoteCounter[post.id] = post?.downvote;
|
||||||
userAlreadyVoted = post?.expand['alreadyVoted(post)']?.some(item => item?.user === data?.user?.id);
|
userAlreadyVoted = post?.expand['alreadyVoted(post)']?.some(item => item?.user === data?.user?.id);
|
||||||
@ -334,8 +300,12 @@ onMount(async () => {
|
|||||||
LoginPopup = (await import('$lib/components/LoginPopup.svelte')).default;
|
LoginPopup = (await import('$lib/components/LoginPopup.svelte')).default;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[moderators, comments] = await Promise.all([
|
||||||
|
getModerators(),
|
||||||
|
getAllComments(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
numberOfComments = countAllComments(comments) || 0;
|
||||||
|
|
||||||
if (post?.postType === 'link') {
|
if (post?.postType === 'link') {
|
||||||
const url = new URL(post.link);
|
const url = new URL(post.link);
|
||||||
@ -380,6 +350,8 @@ function closePost(event) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
onDestroy( () => {
|
onDestroy( () => {
|
||||||
$commentAdded = '';
|
$commentAdded = '';
|
||||||
$commentIdDeleted = '';
|
$commentIdDeleted = '';
|
||||||
@ -526,7 +498,6 @@ $: {
|
|||||||
<!--<section on:click={closePost} class="bg-[#0F0F0F] cursor-zoom-out min-h-screen">-->
|
<!--<section on:click={closePost} class="bg-[#0F0F0F] cursor-zoom-out min-h-screen">-->
|
||||||
|
|
||||||
<!--in:pageTransitionIn={{ duration: 250, screenWidth: $screenWidth }}-->
|
<!--in:pageTransitionIn={{ duration: 250, screenWidth: $screenWidth }}-->
|
||||||
{#if isLoaded}
|
|
||||||
<div class="overflow-hidden flex flex-row item-start w-full lg:mt-5 relative max-w-6xl m-auto lg:px-5 sm:pb-40">
|
<div class="overflow-hidden flex flex-row item-start w-full lg:mt-5 relative max-w-6xl m-auto lg:px-5 sm:pb-40">
|
||||||
<!--Start Voting-->
|
<!--Start Voting-->
|
||||||
<div style="top: 4rem;" class="hidden lg:flex flex-col items-center relative h-fit sticky z-20 lg:mr-3 ">
|
<div style="top: 4rem;" class="hidden lg:flex flex-col items-center relative h-fit sticky z-20 lg:mr-3 ">
|
||||||
@ -925,11 +896,7 @@ $: {
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
|
||||||
<div class="flex justify-center items-center m-auto h-full w-full max-w-6xl">
|
|
||||||
<div class="loader">Loading...</div>
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
<!--Start Login Modal-->
|
<!--Start Login Modal-->
|
||||||
{#if LoginPopup}
|
{#if LoginPopup}
|
||||||
|
|||||||
61
src/routes/community/post/[postId]/+page.ts
Normal file
61
src/routes/community/post/[postId]/+page.ts
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
import { userRegion, cachedPosts } from '$lib/store';
|
||||||
|
|
||||||
|
import { get } from 'svelte/store';
|
||||||
|
|
||||||
|
export const load = async ({ params }) => {
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
async function getOnePost() {
|
||||||
|
// Get the current value of cachedPosts
|
||||||
|
const cachedValue = get(cachedPosts);
|
||||||
|
|
||||||
|
// Try to find the post in the cached value
|
||||||
|
const output = cachedValue?.posts?.find(item => item?.id === params.postId) ?? {};
|
||||||
|
|
||||||
|
// If the post is found in the cache, return it
|
||||||
|
if (Object.keys(output).length !== 0) {
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the post is not found in the cache, fetch it from the endpoint
|
||||||
|
const postData = { postId: params.postId };
|
||||||
|
|
||||||
|
const response = await fetch(fastifyURL + '/get-one-post', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify(postData),
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await response.json();
|
||||||
|
|
||||||
|
// Assuming the result contains an 'items' array
|
||||||
|
return result.items;
|
||||||
|
}
|
||||||
|
|
||||||
|
const getPostId = async () => {
|
||||||
|
|
||||||
|
return params.postId;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
return {
|
||||||
|
getPostId: await getPostId(),
|
||||||
|
getOnePost: await getOnePost(),
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user