mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
Resolve a "Maximum update depth exceeded" render loop in ScheduleJobDialog while prompt templates are loading, and add accessibility labels across the frontend. Also unregister the service worker in dev to avoid stale caches. - ScheduleJobDialog: use a stable EMPTY_TEMPLATES constant and split template matching into its own effect keyed on [templates, job, open] instead of running inside the init effect that depends on templates - Add ScheduleJobDialog.loading.test.tsx regression test for the loading state - serviceWorker: unregister existing registrations and clear caches in DEV so stale workers do not serve outdated assets locally - App: replace shell div with semantic <main> - SettingsDialog: add sr-only DialogTitle for screen readers - Add aria-labels to icon-only buttons in back-button, combobox, header, GlobalSchedules, and Repos - index.html: add mobile-web-app-capable meta
258 lines
7.0 KiB
TypeScript
258 lines
7.0 KiB
TypeScript
|
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
import { createBrowserRouter, RouterProvider, Outlet, useNavigate, useLocation } from 'react-router-dom'
|
|
import { useEffect, useRef, useCallback } from 'react'
|
|
import { Toaster } from 'sonner'
|
|
import { Repos } from './pages/Repos'
|
|
import { RepoDetail } from './pages/RepoDetail'
|
|
import { SessionDetail } from './pages/SessionDetail'
|
|
import { Schedules } from './pages/Schedules'
|
|
import { GlobalSchedules } from './pages/GlobalSchedules'
|
|
import { Login } from './pages/Login'
|
|
import { Register } from './pages/Register'
|
|
import { Setup } from './pages/Setup'
|
|
import { AssistantRedirect } from './pages/AssistantRedirect'
|
|
import { SettingsDialog } from './components/settings/SettingsDialog'
|
|
import { VersionNotifier } from './components/VersionNotifier'
|
|
import { PwaUpdatePrompt } from '@/components/PwaUpdatePrompt'
|
|
import { MobileTabBar } from '@/components/navigation/MobileTabBar'
|
|
import { MobileSheetHost } from '@/components/navigation/MobileSheetHost'
|
|
import { RouteErrorBoundary } from '@/components/ui/route-error-boundary'
|
|
import { DesktopSidebar } from '@/components/navigation/DesktopSidebar'
|
|
import { useTheme } from './hooks/useTheme'
|
|
import { useRightEdgeSwipe, useSwipeBack } from './hooks/useMobile'
|
|
import { useMobileTabBar } from '@/hooks/useMobileTabBar'
|
|
import { TTSProvider } from './contexts/TTSContext'
|
|
import { AuthProvider } from './contexts/AuthContext'
|
|
import { EventProvider, usePermissions, useEventContext } from '@/contexts/EventContext'
|
|
import { SwipeNavigationProvider, useSwipeNavigation } from '@/contexts/SwipeNavigationContext'
|
|
import { PermissionRequestDialog } from './components/session/PermissionRequestDialog'
|
|
import { SSHHostKeyDialog } from './components/ssh/SSHHostKeyDialog'
|
|
import { loginLoader, setupLoader, registerLoader, protectedLoader } from './lib/auth-loaders'
|
|
import { getSwipeBackTarget } from '@/lib/navigation'
|
|
import { useAuth } from '@/hooks/useAuth'
|
|
import { useServerHealth } from '@/hooks/useServerHealth'
|
|
|
|
const queryClient = new QueryClient({
|
|
defaultOptions: {
|
|
queries: {
|
|
staleTime: 1000 * 10,
|
|
refetchOnWindowFocus: true,
|
|
},
|
|
},
|
|
})
|
|
|
|
function SSHHostKeyDialogWrapper() {
|
|
const { sshHostKey } = useEventContext()
|
|
return (
|
|
<SSHHostKeyDialog
|
|
request={sshHostKey.request}
|
|
onRespond={async (requestId, response) => {
|
|
await sshHostKey.respond(requestId, response === 'accept')
|
|
}}
|
|
/>
|
|
)
|
|
}
|
|
|
|
function HealthMonitor() {
|
|
const { isAuthenticated } = useAuth()
|
|
useServerHealth(isAuthenticated)
|
|
return null
|
|
}
|
|
|
|
function PermissionDialogWrapper() {
|
|
const {
|
|
current: currentPermission,
|
|
pendingCount,
|
|
respond: respondToPermission,
|
|
showDialog,
|
|
setShowDialog,
|
|
} = usePermissions()
|
|
|
|
return (
|
|
<PermissionRequestDialog
|
|
permission={currentPermission}
|
|
pendingCount={pendingCount}
|
|
isFromDifferentSession={false}
|
|
onRespond={respondToPermission}
|
|
open={showDialog}
|
|
onOpenChange={setShowDialog}
|
|
repoDirectory={null}
|
|
/>
|
|
)
|
|
}
|
|
|
|
function AppShell() {
|
|
const navigate = useNavigate()
|
|
const location = useLocation()
|
|
const rootRef = useRef<HTMLDivElement>(null)
|
|
const { openSheet, open } = useMobileTabBar()
|
|
useTheme()
|
|
|
|
const swipeNav = useSwipeNavigation()
|
|
|
|
const getRouteSwipeBackTarget = useCallback(
|
|
() => getSwipeBackTarget(location.pathname, location.search),
|
|
[location.pathname, location.search]
|
|
)
|
|
|
|
const canSwipeBack = useCallback(
|
|
() => !swipeNav?.isSuspended() && getRouteSwipeBackTarget() !== null,
|
|
[swipeNav, getRouteSwipeBackTarget]
|
|
)
|
|
|
|
const handleSwipeBack = useCallback(() => {
|
|
const target = getRouteSwipeBackTarget()
|
|
if (target) navigate(target)
|
|
}, [getRouteSwipeBackTarget, navigate])
|
|
|
|
const { bind: bindRouteSwipe } = useSwipeBack(
|
|
() => {},
|
|
{
|
|
enabled: true,
|
|
suspendsRouteSwipe: false,
|
|
canBack: canSwipeBack,
|
|
onBack: handleSwipeBack,
|
|
}
|
|
)
|
|
|
|
const canOpenMoreWithSwipe = () => {
|
|
return /^\/repos\/[^/]+\/sessions\/[^/]+$/.test(location.pathname) && !openSheet
|
|
}
|
|
|
|
const { bind: bindMoreSwipe } = useRightEdgeSwipe(
|
|
() => open('more'),
|
|
{
|
|
enabled: canOpenMoreWithSwipe(),
|
|
edgeWidth: 32,
|
|
threshold: 60,
|
|
}
|
|
)
|
|
|
|
useEffect(() => {
|
|
const cleanup = bindRouteSwipe(rootRef.current)
|
|
return () => {
|
|
cleanup?.()
|
|
}
|
|
}, [bindRouteSwipe])
|
|
|
|
useEffect(() => {
|
|
const cleanup = bindMoreSwipe(rootRef.current)
|
|
return () => {
|
|
cleanup?.()
|
|
}
|
|
}, [bindMoreSwipe])
|
|
|
|
useEffect(() => {
|
|
const channel = new BroadcastChannel('notification-click')
|
|
channel.onmessage = (event: MessageEvent) => {
|
|
const data = event.data as { url?: string } | null | undefined
|
|
if (typeof data?.url === 'string') {
|
|
navigate(data.url)
|
|
}
|
|
}
|
|
return () => channel.close()
|
|
}, [navigate])
|
|
|
|
return (
|
|
<AuthProvider>
|
|
<EventProvider>
|
|
<div ref={rootRef} className="flex h-dvh w-full min-w-0">
|
|
<DesktopSidebar />
|
|
<main className="flex-1 min-w-0 min-h-0 flex flex-col">
|
|
<Outlet />
|
|
</main>
|
|
</div>
|
|
<MobileTabBar />
|
|
<MobileSheetHost />
|
|
<PermissionDialogWrapper />
|
|
<SSHHostKeyDialogWrapper />
|
|
<SettingsDialog />
|
|
<HealthMonitor />
|
|
<VersionNotifier />
|
|
<PwaUpdatePrompt />
|
|
<Toaster
|
|
position="bottom-right"
|
|
expand={false}
|
|
richColors
|
|
closeButton
|
|
duration={2500}
|
|
/>
|
|
</EventProvider>
|
|
</AuthProvider>
|
|
)
|
|
}
|
|
|
|
const router = createBrowserRouter([
|
|
{
|
|
element: <AppShell />,
|
|
errorElement: <RouteErrorBoundary />,
|
|
children: [
|
|
{
|
|
path: '/login',
|
|
element: <Login />,
|
|
loader: loginLoader,
|
|
},
|
|
{
|
|
path: '/register',
|
|
element: <Register />,
|
|
loader: registerLoader,
|
|
},
|
|
{
|
|
path: '/setup',
|
|
element: <Setup />,
|
|
loader: setupLoader,
|
|
},
|
|
{
|
|
path: '/',
|
|
element: <Repos />,
|
|
loader: protectedLoader,
|
|
},
|
|
{
|
|
path: '/assistant',
|
|
element: <AssistantRedirect />,
|
|
loader: protectedLoader,
|
|
},
|
|
{
|
|
path: '/repos/:id',
|
|
element: <RepoDetail />,
|
|
loader: protectedLoader,
|
|
},
|
|
{
|
|
path: '/repos/:id/assistant',
|
|
element: <AssistantRedirect />,
|
|
loader: protectedLoader,
|
|
},
|
|
{
|
|
path: '/repos/:id/sessions/:sessionId',
|
|
element: <SessionDetail />,
|
|
loader: protectedLoader,
|
|
},
|
|
{
|
|
path: '/repos/:id/schedules',
|
|
element: <Schedules />,
|
|
loader: protectedLoader,
|
|
},
|
|
{
|
|
path: '/schedules',
|
|
element: <GlobalSchedules />,
|
|
loader: protectedLoader,
|
|
},
|
|
],
|
|
},
|
|
])
|
|
|
|
function App() {
|
|
return (
|
|
<QueryClientProvider client={queryClient}>
|
|
<TTSProvider>
|
|
<SwipeNavigationProvider>
|
|
<RouterProvider router={router} />
|
|
</SwipeNavigationProvider>
|
|
</TTSProvider>
|
|
</QueryClientProvider>
|
|
)
|
|
}
|
|
|
|
export default App
|