All files / apps/web/src/pages/_protected/receipts index.tsx

100% Statements 10/10
100% Branches 0/0
100% Functions 6/6
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43                  332x       91x             69x 68x 68x     58x                 157x   68x   90x        
import { createFileRoute } from "@tanstack/react-router";
 
import { ReceiptsScreen } from "~app/features/receipts/receipts-screen";
import { withDefaultLimit } from "~app/utils/store/limit";
import { getTitle } from "~web/utils/i18n";
import { searchParamsWithDefaults } from "~web/utils/navigation";
import { prefetchQueriesWith } from "~web/utils/ssr";
import { getLoaderTrpcClient } from "~web/utils/trpc";
 
export const Route = createFileRoute("/_protected/receipts/")({
	component: ReceiptsScreen,
	staleTime: Infinity,
	...searchParamsWithDefaults("/_protected/receipts/"),
	loaderDeps: ({ search: { offset, limit, filters, sort } }) => ({
		offset,
		limit,
		filters,
		sort,
	}),
	loader: async (ctx) => {
		await ctx.context.i18nContext.loadNamespaces("receipts");
		const trpc = getLoaderTrpcClient(ctx.context);
		const prefetched = await prefetchQueriesWith(
			ctx,
			() =>
				ctx.context.queryClient.fetchQuery(
					trpc.receipts.getPaged.queryOptions({
						limit: withDefaultLimit(ctx.deps.limit, ctx.context),
						orderBy: ctx.deps.sort,
						filters: ctx.deps.filters,
						cursor: ctx.deps.offset,
					}),
				),
			(list) =>
				list.items.map(({ id }) => trpc.receipts.get.queryOptions({ id })),
		);
		return { prefetched };
	},
	head: ({ match }) => ({
		meta: [{ title: getTitle(match.context.i18nContext, "receipts") }],
	}),
});