Files
hapi/web/src/lib/app-context.tsx
T
weishu 3bac5c7bc6 feat(web): integrate TanStack React Router for client-side routing
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
2025-12-20 16:49:10 +08:00

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
}