Skip to content

Commit

Permalink
fix: refactor timeline api
Browse files Browse the repository at this point in the history
  • Loading branch information
bacpactech committed Sep 8, 2024
1 parent 9edb5d3 commit 92d038b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
11 changes: 0 additions & 11 deletions src/app/loading.tsx

This file was deleted.

17 changes: 10 additions & 7 deletions src/hooks/useCookie.ts
Original file line number Diff line number Diff line change
@@ -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<string>('')
Expand All @@ -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]
}
Expand Down
1 change: 1 addition & 0 deletions src/services/community-timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export function useGetTimelinePosts() {
const state = useQuery({
queryKey: ['timelinePosts'],
queryFn: () => getAllTimelinePosts(cookieValue),
enabled: !!cookieValue,
})

let errorMessage = null
Expand Down

0 comments on commit 92d038b

Please sign in to comment.