mirror of
https://github.com/wu736139669/hapi.git
synced 2026-10-31 23:31:39 +00:00
Replace state-based screen navigation with proper URL-based routing. This includes: - New router configuration with routes for sessions, machines, and spawn pages - App context provider to share API and token across the app - useAppGoBack hook for handling browser and Telegram back navigation - Refactored App component to render outlet and use router hooks - Memory history for Telegram app, browser history for web
29 lines
670 B
TypeScript
29 lines
670 B
TypeScript
import { createContext, useContext, type ReactNode } from 'react'
|
|
import type { ApiClient } from '@/api/client'
|
|
|
|
type AppContextValue = {
|
|
api: ApiClient
|
|
token: string
|
|
}
|
|
|
|
const AppContext = createContext<AppContextValue | null>(null)
|
|
|
|
export function AppContextProvider(props: {
|
|
value: AppContextValue
|
|
children: ReactNode
|
|
}) {
|
|
return (
|
|
<AppContext.Provider value={props.value}>
|
|
{props.children}
|
|
</AppContext.Provider>
|
|
)
|
|
}
|
|
|
|
export function useAppContext(): AppContextValue {
|
|
const context = useContext(AppContext)
|
|
if (!context) {
|
|
throw new Error('AppContext is not available')
|
|
}
|
|
return context
|
|
}
|