fix: make search usable again

This commit is contained in:
Max Richter
2025-11-05 00:42:53 +01:00
parent 7664abe089
commit 581f1c1926
9 changed files with 120 additions and 62 deletions

View File

@@ -12,17 +12,25 @@ export type Props = {
searchResults?: GenericResource[];
};
function getQFromUrl(u: string | URL): string | null {
try {
const _u = typeof u === "string" ? new URL(u) : u;
return _u?.searchParams.get("q");
} catch (_e) {
return null;
}
}
export const MainLayout = (
{ children, url, context, searchResults }: Props,
) => {
const _url = typeof url === "string" ? new URL(url) : url;
const hasSearch = _url?.search?.includes("q=");
const q = getQFromUrl(url);
if (hasSearch) {
if (typeof q === "string") {
return (
<Search
q={_url.searchParams.get("q") || ""}
{...context}
q={q}
results={searchResults}
/>
);