40 lines
1.5 KiB
TypeScript
40 lines
1.5 KiB
TypeScript
import type { MyGak } from './myGakState'
|
|
import type { WeatherWhyPayload } from './weatherWhy'
|
|
import { createContext, use } from 'react'
|
|
/** square: 1:1 비율일 때 slides 대신 찍을 틀 (없으면 slides). url: 같이 보낼 링크 (없으면 사이트 주소) */
|
|
export type SharePayload = { title: string; slides: HTMLElement[]; square?: HTMLElement[]; url?: string }
|
|
|
|
/** 댓글이 달린 곳: 운영 포스트 또는 사람 글 */
|
|
export type CommentTarget = { postId: number } | { talkId: number }
|
|
type CommentsState = { type: 'comments'; draft?: string } & CommentTarget
|
|
|
|
export type SheetState =
|
|
| { type: 'gak'; indexId: number }
|
|
| { type: 'article'; articleId: number }
|
|
| { type: 'share'; share: SharePayload }
|
|
| CommentsState
|
|
| { type: 'seasonWeek' }
|
|
| { type: 'login'; then?: CommentsState; why?: 'level' }
|
|
| { type: 'me' }
|
|
| { type: 'region' }
|
|
| { type: 'mix'; shared?: MyGak }
|
|
| { type: 'myGak'; gak: MyGak; shot?: HTMLElement | null }
|
|
| { type: 'install' }
|
|
| { type: 'weatherWhy'; why: WeatherWhyPayload }
|
|
| { type: 'tarot' }
|
|
| { type: 'level' }
|
|
| { type: 'levelUp'; level: number }
|
|
| { type: 'gameHelp' }
|
|
| { type: 'contact' }
|
|
| 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
|
|
}
|