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,7 @@ import { Signal } from "@preact/signals";
import type { Ingredient, IngredientGroup } from "@lib/recipeSchema.ts";
import { FunctionalComponent } from "preact";
import { unitsOfMeasure } from "@lib/parseIngredient.ts";
import { renderMarkdown } from "@lib/documents.ts";
import { renderMarkdown } from "@lib/markdown.ts";
function formatAmount(num: number) {
if (num === 0) return "";

View File

@@ -1,7 +1,7 @@
import { Movie } from "@lib/resource/movies.ts";
import { TMDBMovie } from "@lib/types.ts";
import { getCookie } from "@lib/string.ts";
import { MenuEntry } from "../types.ts";
import { ReviewResource } from "@lib/marka/schema.ts";
export const addMovieInfos: MenuEntry = {
title: "Add Movie infos",
@@ -9,7 +9,7 @@ export const addMovieInfos: MenuEntry = {
icon: "IconReportSearch",
cb: async (state, context) => {
state.activeState.value = "loading";
const movie = context as Movie;
const movie = context as ReviewResource;
const query = movie.name;
@@ -33,7 +33,7 @@ export const addMovieInfos: MenuEntry = {
});
state.visible.value = false;
state.activeState.value = "normal";
window.location.reload();
globalThis.location.reload();
},
})),
};

View File

@@ -1,7 +1,7 @@
import { MenuEntry } from "@islands/KMenu/types.ts";
import { TMDBSeries } from "@lib/types.ts";
import { getCookie } from "@lib/string.ts";
import { Series } from "@lib/resource/series.ts";
import { ReviewResource } from "@lib/marka/schema.ts";
export const addSeriesInfo: MenuEntry = {
title: "Add Series infos",
@@ -9,7 +9,7 @@ export const addSeriesInfo: MenuEntry = {
icon: "IconReportSearch",
cb: async (state, context) => {
state.activeState.value = "loading";
const series = context as Series;
const series = context as ReviewResource;
const query = series.name;

View File

@@ -1,8 +1,8 @@
import { MenuEntry } from "@islands/KMenu/types.ts";
import { TMDBMovie } from "@lib/types.ts";
import { debounce } from "@lib/helpers.ts";
import { Movie } from "@lib/resource/movies.ts";
import { getCookie } from "@lib/string.ts";
import { ReviewResource } from "@lib/marka/schema.ts";
export const createNewMovie: MenuEntry = {
title: "Create new movie",
@@ -52,9 +52,9 @@ export const createNewMovie: MenuEntry = {
const response = await fetch("/api/movies/" + r.id, {
method: "POST",
});
const movie = await response.json() as Movie;
const movie = await response.json() as ReviewResource;
unsub();
window.location.href = "/movies/" + movie.name;
globalThis.location.href = "/movies/" + movie.name;
},
};
}),

View File

@@ -1,8 +1,8 @@
import { MenuEntry } from "@islands/KMenu/types.ts";
import { TMDBSeries } from "@lib/types.ts";
import { debounce } from "@lib/helpers.ts";
import { Series } from "@lib/resource/series.ts";
import { getCookie } from "@lib/string.ts";
import { ReviewResource } from "@lib/marka/schema.ts";
export const createNewSeries: MenuEntry = {
title: "Create new series",
@@ -54,9 +54,9 @@ export const createNewSeries: MenuEntry = {
const response = await fetch("/api/series/" + r.id, {
method: "POST",
});
const series = await response.json() as Series;
const series = await response.json() as ReviewResource;
unsub();
window.location.href = "/series/" + series.name;
globalThis.location.href = "/series/" + series.name;
},
};
}),

View File

@@ -6,13 +6,16 @@ declare global {
}
export function Link(
{ href, children, class: _class, style }: {
props: {
href?: string;
class?: string;
style?: preact.JSX.CSSProperties;
children: preact.ComponentChildren;
"data-thumb"?: string;
},
) {
const { href, children, class: _class, style } = props;
const thumbhash = props["data-thumb"];
function handleClick() {
if (globalThis.loadingTimeout) {
return;
@@ -41,6 +44,7 @@ export function Link(
href={href}
style={style}
onClick={handleClick}
data-thumb={thumbhash}
class={_class}
>
{children}

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>
);
};