From 92d038b6194594076cc7d6c988d60737da050485 Mon Sep 17 00:00:00 2001 From: bacpactech Date: Sun, 8 Sep 2024 21:06:25 +0530 Subject: [PATCH] fix: refactor timeline api --- src/app/loading.tsx | 11 ----------- src/hooks/useCookie.ts | 17 ++++++++++------- src/services/community-timeline.ts | 1 + 3 files changed, 11 insertions(+), 18 deletions(-) delete mode 100644 src/app/loading.tsx diff --git a/src/app/loading.tsx b/src/app/loading.tsx deleted file mode 100644 index b5d9a4f0..00000000 --- a/src/app/loading.tsx +++ /dev/null @@ -1,11 +0,0 @@ -export default function Loading() { - return ( -
-
- - - -
-
- ) -} diff --git a/src/hooks/useCookie.ts b/src/hooks/useCookie.ts index 89bbe0e7..888ed700 100644 --- a/src/hooks/useCookie.ts +++ b/src/hooks/useCookie.ts @@ -1,5 +1,5 @@ 'use client' -import { useState, useEffect } from 'react' +import { useState, useEffect, useCallback } from 'react' const useCookie = (cookieName: string): [string, (value: string, expirationDate: string) => void, () => void] => { const [cookieValue, setCookieValue] = useState('') @@ -10,15 +10,18 @@ const useCookie = (cookieName: string): [string, (value: string, expirationDate: setCookieValue(cookie ? cookie.split('=')[1] : '') }, [cookieName]) - const setCookie = (value: string, expirationDate: string): void => { - document.cookie = `${cookieName}=${value}; expires=${new Date(expirationDate).toUTCString()}; path=/` - setCookieValue(value) - } + const setCookie = useCallback( + (value: string, expirationDate: string): void => { + document.cookie = `${cookieName}=${value}; expires=${new Date(expirationDate).toUTCString()}; path=/` + setCookieValue(value) + }, + [cookieName] + ) - const deleteCookie = (): void => { + const deleteCookie = useCallback((): void => { document.cookie = `${cookieName}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/` setCookieValue('') - } + }, [cookieName]) return [cookieValue, setCookie, deleteCookie] } diff --git a/src/services/community-timeline.ts b/src/services/community-timeline.ts index 6b0a8692..bde1dfe7 100644 --- a/src/services/community-timeline.ts +++ b/src/services/community-timeline.ts @@ -155,6 +155,7 @@ export function useGetTimelinePosts() { const state = useQuery({ queryKey: ['timelinePosts'], queryFn: () => getAllTimelinePosts(cookieValue), + enabled: !!cookieValue, }) let errorMessage = null