Skip to content

Commit

Permalink
Merge pull request #86 from BacPacNet/fix-refactor-timeline
Browse files Browse the repository at this point in the history
fix: refactor timeline api
  • Loading branch information
Aamil13 authored Sep 9, 2024
2 parents 9edb5d3 + a787e00 commit 8fb5d9c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
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

0 comments on commit 8fb5d9c

Please sign in to comment.