Å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.
28 lines
901 B
TypeScript
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 }
|
|
}
|