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";
|
2023-08-10 16:59:18 +02:00
|
|
|
import { SearchResult } from "@lib/types.ts";
|
2023-07-26 13:47:01 +02:00
|
|
|
|
|
|
|
export type Props = {
|
|
|
|
children: ComponentChildren;
|
|
|
|
title?: string;
|
|
|
|
name?: string;
|
2023-07-30 21:43:09 +02:00
|
|
|
url: URL;
|
2023-07-26 13:47:01 +02:00
|
|
|
description?: string;
|
2023-08-06 00:33:06 +02:00
|
|
|
context?: { type: string };
|
2023-08-10 16:59:18 +02:00
|
|
|
searchResults?: SearchResult;
|
2023-07-26 13:47:01 +02:00
|
|
|
};
|
|
|
|
|
2023-08-10 16:59:18 +02:00
|
|
|
export const MainLayout = (
|
|
|
|
{ children, url, title, context, searchResults }: Props,
|
|
|
|
) => {
|
2023-09-08 13:33:29 +02:00
|
|
|
const _url = typeof url === "string" ? new URL(url) : url;
|
|
|
|
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
|
|
|
};
|