mirror of
https://github.com/supabase/supabase.git
synced 2026-10-10 20:05:06 +03:00
Add all the outstanding pieces for state management of new command menu: - Pages state (handles routing between command menu views, e.g., docs search, AI, etc.) - View state (handles opening and closing and initiation (needed for lazy loading)) - Query state (handles active search term)
40 lines
970 B
TypeScript
40 lines
970 B
TypeScript
import { proxy } from 'valtio'
|
|
|
|
type DialogSize = 'small' | 'tiny' | 'medium' | 'large' | 'xlarge' | 'xxlarge' | 'xxxlarge'
|
|
|
|
type IViewState = {
|
|
initiated: boolean
|
|
init: () => void
|
|
open: boolean
|
|
setOpen: (open: boolean) => void
|
|
toggleOpen: () => void
|
|
isNavigating: boolean
|
|
setIsNavigating: (isNavigating: boolean) => void
|
|
size: DialogSize
|
|
setSize: (size: DialogSize) => void
|
|
}
|
|
|
|
const initViewState = () => {
|
|
const state: IViewState = proxy({
|
|
initiated: false,
|
|
init: () => !state.initiated && (state.initiated = true),
|
|
open: false,
|
|
setOpen: (open) => {
|
|
state.init()
|
|
state.open = open
|
|
},
|
|
toggleOpen: () => {
|
|
state.init()
|
|
state.open = !state.open
|
|
},
|
|
isNavigating: false,
|
|
setIsNavigating: (isNavigating) => (state.isNavigating = isNavigating),
|
|
size: 'large',
|
|
setSize: (size) => (state.size = size),
|
|
})
|
|
return state
|
|
}
|
|
|
|
export { initViewState }
|
|
export type { DialogSize, IViewState }
|