26 lines
784 B
TypeScript
26 lines
784 B
TypeScript
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' }
|
|
| 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
|
|
}
|