Skip to content

Commit

Permalink
feat: read from nuqs on server
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinWu098 committed Dec 5, 2024
1 parent 67dd9b7 commit 5dd681a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/app/search/page.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { Suspense } from "react";
import { searchParamsCache } from "@/app/search/searchParams";
import { Search } from "@/components/search/search";
import { UNIVERSITY_GE } from "@/lib/constants";
import { queryDatabase } from "@/lib/utils/query-db";
import { SearchParams } from "nuqs";

export default async function Page({
searchParams,
}: {
searchParams: Promise<{ [key: string]: string | string[] | undefined }>;
searchParams: Promise<SearchParams>;
}) {
// ! fix me
const searchUniversity = (await searchParams)["university"] as string;
const searchGE = (await searchParams)["ge"] as string;
const { university: searchUniversity, ge: searchGe } =
await searchParamsCache.parse(searchParams);

const university = searchUniversity || Object.keys(UNIVERSITY_GE)[0];
const ge = searchGE || UNIVERSITY_GE[university][0];
const ge = searchGe || UNIVERSITY_GE[university][0];

const coursesResponse = await queryDatabase(university, ge).catch((e) => {
console.error(e);
Expand Down
6 changes: 6 additions & 0 deletions src/app/search/searchParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { createSearchParamsCache, parseAsString } from "nuqs/server";

export const searchParamsCache = createSearchParamsCache({
university: parseAsString.withDefault("University of California, Irvine"),
ge: parseAsString.withDefault("GE IV"),
});

0 comments on commit 5dd681a

Please sign in to comment.