Files
o2o-weather/frontend/src/b/sheetContext.ts
T

28 lines
862 B
TypeScript

import type { MyGak } from './myGakState'
import { createContext, use } from 'react'
export type SharePayload = { title: string; slides: HTMLElement[] }
type CommentsState = { type: 'comments'; postId: number; draft?: string }
export type SheetState =
| { type: 'gak'; indexId: number }
| { type: 'article'; articleId: number }
| { type: 'share'; share: SharePayload }
| CommentsState
| { type: 'seasonWeek' }
| { type: 'login'; then?: CommentsState }
| { type: 'me' }
| { type: 'region' }
| { type: 'mix'; shared?: MyGak }
| null
export type SheetApi = { open: (s: Exclude<SheetState, null>) => void; close: () => void }
export const SheetContext = createContext<SheetApi | null>(null)
export function useSheet() {
const ctx = use(SheetContext)
if (!ctx) throw new Error('useSheet must be used inside SheetProvider')
return ctx
}