33 lines
727 B
TypeScript
Raw Normal View History

2023-07-26 13:47:01 +02:00
import { ComponentChildren } from "preact";
2025-01-05 21:58:07 +01:00
import Search from "@islands/Search.tsx";
2025-01-18 00:46:05 +01:00
import { GenericResource } from "@lib/types.ts";
2023-07-26 13:47:01 +02:00
export type Props = {
children: ComponentChildren;
title?: string;
name?: string;
2025-01-18 00:46:05 +01:00
url: URL | string;
2023-07-26 13:47:01 +02:00
description?: string;
2023-08-06 00:33:06 +02:00
context?: { type: string };
2025-01-05 23:14:19 +01:00
searchResults?: GenericResource[];
2023-07-26 13:47:01 +02:00
};
2023-08-10 16:59:18 +02:00
export const MainLayout = (
2025-01-18 00:46:05 +01:00
{ children, url, context, searchResults }: Props,
2023-08-10 16:59:18 +02:00
) => {
2023-09-08 13:33:29 +02:00
const _url = typeof url === "string" ? new URL(url) : url;
2025-01-18 00:46:05 +01:00
const hasSearch = _url?.search?.includes("q=");
2023-08-06 00:33:06 +02:00
2023-09-08 13:33:29 +02:00
if (hasSearch) {
return (
<Search
q={_url.searchParams.get("q")}
{...context}
results={searchResults}
/>
);
}
return <>{children}</>;
2023-07-26 13:47:01 +02:00
};