mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-08-01 10:51:29 -04:00
23 lines
823 B
TypeScript
23 lines
823 B
TypeScript
import {Row} from 'common/supabase/utils'
|
|
import {useEffect} from 'react'
|
|
import {usePersistentInMemoryState} from 'web/hooks/use-persistent-in-memory-state'
|
|
import {getUserBookmarkedSearches} from 'web/lib/supabase/searches'
|
|
|
|
export const useBookmarkedSearches = (userId: string | undefined) => {
|
|
const [bookmarkedSearches, setBookmarkedSearches] = usePersistentInMemoryState<
|
|
Row<'bookmarked_searches'>[]
|
|
>([], `bookmarked-searches-${userId}`)
|
|
|
|
useEffect(() => {
|
|
if (userId) getUserBookmarkedSearches(userId).then(setBookmarkedSearches)
|
|
}, [userId])
|
|
|
|
async function refreshBookmarkedSearches() {
|
|
if (userId) getUserBookmarkedSearches(userId).then(setBookmarkedSearches)
|
|
}
|
|
|
|
return {bookmarkedSearches, refreshBookmarkedSearches}
|
|
}
|
|
|
|
export type BookmarkedSearchesType = Row<'bookmarked_searches'>
|