Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: refactor timeline api #86

Merged
merged 2 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app/community/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react'
import Footer from '@/components/Footer/Footer'
import UniversityCard from '@/components/universityCommunity/universityCommunityCart'
import { useGetUserSubscribedCommunityGroups } from '@/services/university-community'
import Loading from '../loading'
import Loading from '@/components/atoms/Loading'

interface CommunityType {
_id: string
Expand Down
File renamed without changes.
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
Loading