Files
superlist/apps/web/src/routes/_authenticated/route.tsx
Jose Selesan aa170de8d1 feat(web): show pending items on the installed app icon
Keep the Badging API count equal to the primary list's pending items, update it from optimistic changes and the list's SSE stream (shared across pages), and re-sync when the app returns to the foreground.

On iOS the badge needs notification permission, so Settings offers to enable it; Android does not support numeric web app badges.
2026-10-29 14:20:21 -03:00

63 lines
2.1 KiB
TypeScript

import { createFileRoute, Outlet, redirect } from '@tanstack/react-router'
import { AppBadge } from '@/components/app-badge'
import { InstallPrompt } from '@/components/install-prompt'
import { AppHeader } from '@/components/layout/app-header'
import { AppSidebar } from '@/components/layout/app-sidebar'
import { BottomNav } from '@/components/layout/bottom-nav'
import { SidebarInset, SidebarProvider } from '@/components/ui/sidebar'
import { Skeleton } from '@/components/ui/skeleton'
import { authClient, useSession } from '@/lib/auth-client'
export const Route = createFileRoute('/_authenticated')({
// Guard before anything renders or loads: without a session we bounce the
// user to `/sign-in`, keeping the current URL so we can return after login.
// Redirecting here (instead of rendering <Navigate>) also keeps child loaders
// from firing API calls that would only answer 401.
beforeLoad: async ({ location }) => {
const { data: session } = await authClient.getSession()
if (!session) {
throw redirect({ to: '/sign-in', search: { redirect: location.href }, replace: true })
}
},
component: AuthenticatedLayout,
})
/**
* Layout for every authenticated page. The session lives in BetterAuth (Hono
* API); `beforeLoad` already guarantees one, so while the reactive session
* resolves (or right after signing out, before navigating away) we render a
* loader.
*/
function AuthenticatedLayout() {
const { data: session, isPending } = useSession()
if (isPending || !session) {
return <SessionLoading />
}
return (
<SidebarProvider>
<AppBadge />
<AppSidebar />
<SidebarInset>
<AppHeader />
<div className="flex flex-1 flex-col gap-4 p-4 pb-[calc(5rem+env(safe-area-inset-bottom))] md:gap-6 md:p-6 md:pb-6">
<Outlet />
</div>
<BottomNav />
<InstallPrompt />
</SidebarInset>
</SidebarProvider>
)
}
function SessionLoading() {
return (
<div className="space-y-4 p-6">
<Skeleton className="h-8 w-48" />
<Skeleton className="h-64 w-full" />
</div>
)
}