From 4501bfb5045a2d381cc2e555d45a01d17286d39c Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Tue, 30 Apr 2024 15:29:38 +0200 Subject: [PATCH] Fix typings post-router upgrade --- .../__snapshots__/SessionHeader.test.tsx.snap | 1 + .../UnverifiedEmailAlert.test.tsx.snap | 1 + frontend/src/routes/__root.tsx | 8 ++++---- .../src/routes/_account.sessions.browsers.tsx | 16 +++++----------- frontend/src/routes/_account.sessions.index.tsx | 12 ++---------- frontend/src/test-utils/router.tsx | 5 ++++- 6 files changed, 17 insertions(+), 26 deletions(-) diff --git a/frontend/src/components/SessionDetail/__snapshots__/SessionHeader.test.tsx.snap b/frontend/src/components/SessionDetail/__snapshots__/SessionHeader.test.tsx.snap index 83c99aa5..99c4b699 100644 --- a/frontend/src/components/SessionDetail/__snapshots__/SessionHeader.test.tsx.snap +++ b/frontend/src/components/SessionDetail/__snapshots__/SessionHeader.test.tsx.snap @@ -6,6 +6,7 @@ exports[` > renders a session header 1`] = ` class="_header_92353c" > > renders a warning when there are unverified You have 2 unverified email addresses. - isForwardPagination(search) - ? { first: search.first, after: search.after } - : { last: search.last, before: search.before }, + loaderDeps: ({ search }): Pagination => paginationSchema.parse(search), async loader({ context, deps: pagination, abortController: { signal } }) { const result = await context.client.query(QUERY, pagination, { diff --git a/frontend/src/routes/_account.sessions.index.tsx b/frontend/src/routes/_account.sessions.index.tsx index 190dffb0..5579aa9d 100644 --- a/frontend/src/routes/_account.sessions.index.tsx +++ b/frontend/src/routes/_account.sessions.index.tsx @@ -23,12 +23,7 @@ import CompatSession from "../components/CompatSession"; import OAuth2Session from "../components/OAuth2Session"; import BrowserSessionsOverview from "../components/UserSessionsOverview/BrowserSessionsOverview"; import { graphql } from "../gql"; -import { - Pagination, - isForwardPagination, - paginationSchema, - usePages, -} from "../pagination"; +import { Pagination, paginationSchema, usePages } from "../pagination"; const PAGE_SIZE = 6; @@ -95,10 +90,7 @@ export const Route = createFileRoute("/_account/sessions/")({ // We paginate backwards, so we need to validate the `last` parameter by default validateSearch: paginationSchema.catch({ last: PAGE_SIZE }), - loaderDeps: ({ search }): Pagination => - isForwardPagination(search) - ? { first: search.first, after: search.after } - : { last: search.last, before: search.before }, + loaderDeps: ({ search }): Pagination => paginationSchema.parse(search), async loader({ context, deps: pagination, abortController: { signal } }) { const [overview, list] = await Promise.all([ diff --git a/frontend/src/test-utils/router.tsx b/frontend/src/test-utils/router.tsx index 005684a0..3fff6ff2 100644 --- a/frontend/src/test-utils/router.tsx +++ b/frontend/src/test-utils/router.tsx @@ -36,4 +36,7 @@ beforeAll(async () => await routerReady); export const DummyRouter: React.FC = ({ children, -}) => children} />; +}) => ( + /** @ts-expect-error: The router we pass doesn't match the "real" router, which is fine for tests */ + children} /> +);