mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-03-24 17:41:27 -04:00
Add user dependency to refreshPinnedQuestionIds in PinnedQuestionIdsProvider
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import {createContext, ReactNode, useCallback, useContext, useEffect, useState} from 'react'
|
||||
import {useUser} from 'web/hooks/use-user'
|
||||
import {api} from 'web/lib/api'
|
||||
|
||||
const PinnedQuestionIdsContext = createContext<{
|
||||
@@ -8,17 +9,19 @@ const PinnedQuestionIdsContext = createContext<{
|
||||
} | null>(null)
|
||||
|
||||
export function PinnedQuestionIdsProvider({children}: {children: ReactNode}) {
|
||||
const user = useUser()
|
||||
const [pinnedQuestionIds, setPinnedQuestionIds] = useState<number[] | undefined>(undefined)
|
||||
|
||||
const refreshPinnedQuestionIds = useCallback(() => {
|
||||
if (!user) return
|
||||
api('get-pinned-compatibility-questions').then((res) => {
|
||||
setPinnedQuestionIds(res.pinnedQuestionIds ?? [])
|
||||
})
|
||||
}, [])
|
||||
}, [user?.id])
|
||||
|
||||
useEffect(() => {
|
||||
refreshPinnedQuestionIds()
|
||||
}, [])
|
||||
}, [refreshPinnedQuestionIds])
|
||||
|
||||
return (
|
||||
<PinnedQuestionIdsContext.Provider
|
||||
|
||||
Reference in New Issue
Block a user