feat: render search on server

This commit is contained in:
2023-08-10 16:59:18 +02:00
parent 61ac1f39e9
commit c29743bd52
9 changed files with 235 additions and 111 deletions

View File

@ -5,6 +5,7 @@ import { Head } from "$fresh/runtime.ts";
import Search, { RedirectSearchHandler } from "@islands/Search.tsx";
import { KMenu } from "@islands/KMenu.tsx";
import { Emoji } from "@components/Emoji.tsx";
import { SearchResult } from "@lib/types.ts";
export type Props = {
children: ComponentChildren;
@ -13,9 +14,12 @@ export type Props = {
url: URL;
description?: string;
context?: { type: string };
searchResults?: SearchResult;
};
export const MainLayout = ({ children, url, title, context }: Props) => {
export const MainLayout = (
{ children, url, title, context, searchResults }: Props,
) => {
const hasSearch = url.search.includes("q=");
return (
@ -49,7 +53,13 @@ export const MainLayout = ({ children, url, title, context }: Props) => {
class="py-5"
style={{ fontFamily: "Work Sans" }}
>
{hasSearch && <Search q={url.searchParams.get("q")} {...context} />}
{hasSearch && (
<Search
q={url.searchParams.get("q")}
{...context}
results={searchResults}
/>
)}
{!hasSearch && children}
</main>
</div>