'use client' import { createContext, useContext, ReactNode, Dispatch, SetStateAction } from 'react' import { DownloadProgress } from '@/types/DownloadProgress' import { ServerVersionsResponse } from '@/types/ServerVersionsResponse' import { Mod } from '@/types/Mod' import { Store } from '@tauri-apps/plugin-store' import { GameVersion } from '@/types/GameVersion' type GlobalCtxType = { serverVersionList: ServerVersionsResponse | null selectedVersionList: string[] setSelectedVersionList: (value: SetStateAction) => void downloadProgress: DownloadProgress[] setDownloadProgress: Dispatch> showPopup: boolean setShowPopup: Dispatch> popupMode: number | null setPopupMode: Dispatch> fadeOut: boolean setFadeOut: Dispatch> managingVersion: string | null setManagingVersion: Dispatch> setSelectedGame: Dispatch> viewingInfoFromDownloads: boolean version: string | null downloadVersions: ( list: Array<{ id: string type: 0 | 1 | 2 modDownload?: number gameId?: number modId?: number modVersion?: string }> ) => Promise category: number setCategory: Dispatch> downloadQueue: string[] setDownloadQueue: Dispatch> closePopup: () => void selectedGame: number | null setViewingInfoFromDownloads: Dispatch> showModInfo: Mod | null setShowModInfo: Dispatch> getSpecialVersionsList: (game?: number) => GameVersion[] settings: Store | null versions: Store | null notificationsAllowed: boolean sidebarAlwaysShowGames: boolean linuxUseWine: boolean linuxWineCommand: string theme: string versionsList: Record modsList: Record> } const GlobalCtx = createContext(null) export const useGlobal = () => { const ctx = useContext(GlobalCtx) if (!ctx) throw new Error('useGlobal must be inside GlobalProvider') return ctx } export const GlobalProvider = ({ children, value }: { children: ReactNode value: GlobalCtxType }) => { return {children} }