Files
supabase/apps/studio/hooks/misc/useDashboardHistory.ts
Charis 180ce515f6 style: require @ imports and sort imports for studio/hooks (#44444)
* **Chores**
* Updated internal module import paths across hook files to use
standardized path aliases for improved code consistency and
maintainability.
2026-04-01 11:48:02 -04:00

32 lines
868 B
TypeScript

import { LOCAL_STORAGE_KEYS, useParams } from 'common'
import { useLocalStorageQuery } from './useLocalStorage'
type DashboardHistory = { editor?: string; sql?: string }
const DEFAULT_HISTORY = { editor: undefined, sql: undefined }
export const useDashboardHistory = () => {
// [Joshen] History should always refer to the project that the user is currently on
const { ref } = useParams()
const [history, setHistory, { isSuccess }] = useLocalStorageQuery<DashboardHistory>(
LOCAL_STORAGE_KEYS.DASHBOARD_HISTORY(ref ?? ''),
DEFAULT_HISTORY
)
const setLastVisitedTable = (id?: string) => {
setHistory({ ...history, editor: id })
}
const setLastVisitedSnippet = (id?: string) => {
setHistory({ ...history, sql: id })
}
return {
history,
setLastVisitedTable,
setLastVisitedSnippet,
isHistoryLoaded: isSuccess,
}
}