soulsync/webui/src/routes/stats/route.tsx
Antti Kettunen ca84aa2e65
fix(webui): harden stats route fallback flows
- make listening status prefetch optional so /stats still renders on status failures
- normalize no-stats-yet cache responses into the existing empty stats state
- restore streaming fallback when library track resolution errors
- add route and API regression coverage for the review fixes
2026-05-23 21:23:32 +03:00

33 lines
1,022 B
TypeScript

import { createFileRoute, redirect } from '@tanstack/react-router';
import { getProfileHomePath } from '@/platform/shell/bridge';
import { listeningStatsStatusQueryOptions, statsCachedQueryOptions } from './-stats.api';
import { statsSearchSchema } from './-stats.types';
import { StatsPage } from './-ui/stats-page';
export const Route = createFileRoute('/stats')({
validateSearch: statsSearchSchema,
beforeLoad: ({ context }) => {
const { bridge } = context.shell;
if (!bridge.isPageAllowed('stats')) {
throw redirect({ href: getProfileHomePath(bridge), replace: true });
}
},
loaderDeps: ({ search }) => ({
range: search.range,
}),
loader: async ({ context, deps }) => {
await Promise.all([
context.queryClient.ensureQueryData(statsCachedQueryOptions(deps.range)),
context.queryClient
.fetchQuery({
...listeningStatsStatusQueryOptions(),
retry: false,
})
.catch(() => undefined),
]);
},
component: StatsPage,
});