feat: refactor whole bunch of stuff

This commit is contained in:
Max Richter
2025-11-02 19:03:11 +01:00
parent 81ebc8f5e0
commit e6b90cb785
56 changed files with 753 additions and 360 deletions

View File

@@ -2,7 +2,6 @@ import { useEffect, useRef } from "preact/hooks";
import useDebouncedCallback from "@lib/hooks/useDebouncedCallback.ts";
import { IconLoader2, IconSearch } from "@components/icons.tsx";
import { useEventListener } from "@lib/hooks/useEventListener.ts";
import { GenericResource } from "@lib/types.ts";
import { resources } from "@lib/resources.ts";
import { getCookie } from "@lib/string.ts";
import { IS_BROWSER } from "$fresh/runtime.ts";
@@ -11,6 +10,7 @@ import { Rating } from "@components/Rating.tsx";
import { useSignal } from "@preact/signals";
import Image from "@components/Image.tsx";
import { Emoji } from "@components/Emoji.tsx";
import { GenericResource } from "@lib/marka/schema.ts";
export async function fetchQueryResource(url: URL, type = "") {
const query = url.searchParams.get("q");
@@ -46,7 +46,7 @@ export const RedirectSearchHandler = () => {
}, IS_BROWSER ? document?.body : undefined);
}
return <></>;
return;
};
const SearchResultImage = ({ src }: { src: string }) => {
@@ -67,8 +67,9 @@ export const SearchResultItem = (
showEmoji?: boolean;
},
) => {
const resourceType = resources[item.type];
const href = resourceType ? `${resourceType.link}/${item.id}` : "";
const resourceType = resources[item?.content._type];
const href = item?.path.replace("/resources", "").replace(/\.md$/, "");
console.log({ item, href });
return (
<a
href={href}
@@ -77,8 +78,9 @@ export const SearchResultItem = (
{showEmoji && resourceType
? <Emoji class="w-7 h-7" name={resourceType.emoji} />
: ""}
{item.meta?.image && <SearchResultImage src={item.meta?.image} />}
{item?.name}
{item.image && <SearchResultImage src={item.image?.url} />}
{item.content?.headline || item.content?.name ||
item.content?.itemReviewed.name || item?.name}
</a>
);
};
@@ -190,16 +192,16 @@ const Search = (
{data.value?.length && !isLoading.value
? <SearchResultList showEmoji={!type} result={data.value} />
: isLoading.value
? <div />
: (
<div
class="flex items-center gap-2 p-2 my-4 mx-3"
style={{ color: "#818181" }}
>
<Emoji class="w-8 h-8" name="Ghost.png" />
No Results
</div>
)}
? <div />
: (
<div
class="flex items-center gap-2 p-2 my-4 mx-3"
style={{ color: "#818181" }}
>
<Emoji class="w-8 h-8" name="Ghost.png" />
No Results
</div>
)}
</div>
);
};