Skip to content

Commit

Permalink
chore: start migrating away from BlFetcher
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianAndersen committed Feb 3, 2025
1 parent b1f9a8a commit 9ac98b9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
4 changes: 2 additions & 2 deletions frontend/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ThemeProvider } from "@mui/material";
import CssBaseline from "@mui/material/CssBaseline";
import { AppRouterCacheProvider } from "@mui/material-nextjs/v15-appRouter";
import { Metadata } from "next";
import { ReactNode } from "react";
import { ReactNode, Suspense } from "react";

import AuthLinker from "@/components/AuthLinker";
import DynamicHeightProvider from "@/components/DynamicHeightProvider";
Expand Down Expand Up @@ -35,7 +35,7 @@ export default function RootLayout({ children }: { children: ReactNode }) {
<AuthLinker>
{/* CssBaseline kickstart an elegant, consistent, and simple baseline to build upon. */}
<CssBaseline />
{children}
<Suspense>{children}</Suspense>
</AuthLinker>
</ThemeProvider>
</AppRouterCacheProvider>
Expand Down
18 changes: 11 additions & 7 deletions frontend/src/components/BranchSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,24 @@ import { useQuery } from "@tanstack/react-query";
import { usePathname, useRouter } from "next/navigation";
import { useEffect } from "react";

import BlFetcher from "@/api/blFetcher";
import unpack from "@/utils/api/bl-api-request";
import useApiClient from "@/utils/api/useApiClient";
import { useGlobalState } from "@/utils/useGlobalState";

const BranchSelect = ({ isNav }: { isNav?: boolean }) => {
const client = useApiClient();
const branchQuery = {
query: { active: true, sort: "name" },
};
const { data: branches } = useQuery({
queryKey: [
client.$url("collection.branches.getAll", {
query: { active: true, sort: "name" },
}),
],
queryFn: ({ queryKey }) => BlFetcher.get<Branch[]>(queryKey[0] ?? ""),
queryKey: [client.$url("collection.branches.getAll", branchQuery)],
queryFn: () =>
client
.$route("collection.branches.getAll")
.$get(branchQuery)
.then(unpack<Branch[]>),
});
console.log(branches);

const { selectedBranchId, selectBranch } = useGlobalState();

Expand Down
16 changes: 13 additions & 3 deletions frontend/src/components/admin/waiting-list/WaitingList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { Item } from "@boklisten/backend/shared/item/item";
import { Alert, AlertTitle } from "@mui/material";
import { useQuery } from "@tanstack/react-query";

import BlFetcher from "@/api/blFetcher";
import CreateWaitingListEntry from "@/components/admin/waiting-list/CreateWaitingListEntry";
import WaitingListTable from "@/components/admin/waiting-list/WaitingListTable";
import unpack from "@/utils/api/bl-api-request";
import useApiClient from "@/utils/api/useApiClient";

export default function WaitingList() {
Expand All @@ -19,7 +19,11 @@ export default function WaitingList() {
error: itemsError,
} = useQuery({
queryKey: [client.$url("collection.items.getAll")],
queryFn: ({ queryKey }) => BlFetcher.get<Item[]>(queryKey[0] ?? ""),
queryFn: () =>
client
.$route("collection.items.getAll")
.$get()
.then(unpack<Item[]>),
});

const {
Expand All @@ -32,7 +36,13 @@ export default function WaitingList() {
query: { active: true, sort: "name" },
}),
],
queryFn: ({ queryKey }) => BlFetcher.get<Branch[]>(queryKey[0] ?? ""),
queryFn: () =>
client
.$route("collection.branches.getAll")
.$get({
query: { active: true, sort: "name" },
})
.then(unpack<Branch[]>),
});

const {
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/utils/api/bl-api-request.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Unpack data that is encapsulated in a BlApiResponse
export default function unpack<T>(response: unknown) {
return (response as { data: { data: T } }).data.data;
}

0 comments on commit 9ac98b9

Please sign in to comment.