add some basic search functionality

This commit is contained in:
2024-07-15 04:30:05 +02:00
parent 55257f3bb4
commit c935314c4f
16 changed files with 226 additions and 5 deletions

60
web/src/app/sok/page.tsx Normal file
View File

@ -0,0 +1,60 @@
import { graphql } from "@/gql";
import { getClient } from "@/app/client";
import { SearchContainer } from "@/components/search/SearchContainer";
import { Suspense } from "react";
export default async function Page({
searchParams,
}: {
searchParams?: {
q?: string;
};
}) {
const { q: query } = searchParams ?? {};
let results = [];
if (query) {
const searchQuery = graphql(`
query search($query: String) {
results: search(query: $query) {
__typename
... on NewsPage {
id
title
}
... on EventPage {
id
title
}
... on GenericPage {
id
title
}
... on VenuePage {
id
title
}
... on AssociationPage {
id
title
associationType
}
}
}
`);
const { data, error } = await getClient().query(searchQuery, {
query: query,
});
results = (data?.results ?? []) as any;
}
return (
<main className="site-main" id="main">
<Suspense key={query}>
<SearchContainer query={query ?? ""} results={results} />
</Suspense>
</main>
);
}