Files
accounted/lib/hooks/use-ui-state.ts
T
admin e7f0070e84
masterplan-lock / check (push) Successful in 19s
ci / sonar (push) Failing after 21s
security / scan (push) Failing after 1m37s
fix(restore): återställ default branch-filer som raderades av docs-publiceringen (7e33543)
Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i
server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma
strängvärde byggs med konkatenering i stället för att matcha mönstret.
2026-11-10 09:37:22 +01:00

28 lines
901 B
TypeScript

'use client'
import useSWR from 'swr'
import { createClient } from '@/lib/supabase/client'
import type { UserUiState } from '@/types'
/**
* Client-side read of user_preferences.ui_state (nav folds, split-button
* last-used modes). RLS scopes the select to the caller's own row. Pages
* use this to seed SplitButton's initial mode; writes go through
* lib/ui-state/client (POST /api/user/ui-state).
*
* Errors (including a not-yet-migrated ui_state column) degrade to an
* empty state: the UI falls back to its defaults.
*/
export function useUiState() {
const { data } = useSWR<UserUiState>('user-ui-state', async () => {
const supabase = createClient()
const { data: row } = await supabase
.from('user_preferences')
.select('ui_state')
.maybeSingle()
return (row?.ui_state as UserUiState) ?? {}
})
return { uiState: data, loaded: data !== undefined }
}