- 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
33 lines
1,022 B
TypeScript
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,
|
|
});
|