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

32 lines
1.1 KiB
TypeScript

import type { MyGak } from './myGakState'
import type { WeatherWhyPayload } from './weatherWhy'
import { createContext, use } from 'react'
/** square: 1:1 비율일 때 slides 대신 찍을 틀 (없으면 slides) */
export type SharePayload = { title: string; slides: HTMLElement[]; square?: 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 }
| { type: 'install' }
| { type: 'weatherWhy'; why: WeatherWhyPayload }
| 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
}