All files / apps/web/src/pages/_protected/debts/peer/$id index.tsx

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

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 44 45 46 47 48 49 50 51 52                    332x     79x         59x 59x 59x     51x                                 49x     245x   59x   76x        
import { createFileRoute } from "@tanstack/react-router";
 
import { PeerDebtsScreen } from "~app/features/peer-debts/peer-debts-screen";
import { withDefaultLimit } from "~app/utils/store/limit";
import { SETTINGS_STORE_NAME } from "~app/utils/store/settings";
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/debts/peer/$id/")({
	component: PeerDebtsScreen,
	...searchParamsWithDefaults("/_protected/debts/peer/$id/"),
	loaderDeps: ({ search: { offset, limit } }) => ({
		offset,
		limit,
	}),
	loader: async (ctx) => {
		await ctx.context.i18nContext.loadNamespaces("debts");
		const trpc = getLoaderTrpcClient(ctx.context);
		const prefetched = await prefetchQueriesWith(
			ctx,
			async () => {
				const [peerPaged] = await Promise.all([
					ctx.context.queryClient.fetchQuery(
						trpc.debts.getByPeerPaged.queryOptions({
							peerId: ctx.params.id,
							limit: withDefaultLimit(ctx.deps.limit, ctx.context),
							cursor: ctx.deps.offset,
							filters: {
								showResolved:
									ctx.context.initialValues[SETTINGS_STORE_NAME]
										.showResolvedDebts,
							},
						}),
					),
					ctx.context.queryClient.fetchQuery(
						trpc.debts.getAllPeer.queryOptions({ peerId: ctx.params.id }),
					),
				]);
				return peerPaged;
			},
			({ items }) =>
				items.map((debtId) => trpc.debts.get.queryOptions({ id: debtId })),
		);
		return { prefetched };
	},
	head: ({ match }) => ({
		meta: [{ title: getTitle(match.context.i18nContext, "peerDebts") }],
	}),
});