feat: some shit

This commit is contained in:
2023-08-08 11:03:20 +02:00
parent eb1d065f1f
commit dccb6a6ecf
9 changed files with 95 additions and 19 deletions

View File

@ -0,0 +1,52 @@
import { MenuEntry } from "@islands/KMenu/types.ts";
import { TMDBMovie } from "@lib/types.ts";
import { getCookie } from "@lib/string.ts";
import { Series } from "@lib/resource/series.ts";
export const addMovieInfos: MenuEntry = {
title: "Add Movie infos",
meta: "",
icon: "IconReportSearch",
cb: async (state, context) => {
state.activeState.value = "loading";
const movie = context as Series;
const query = movie.name;
const response = await fetch(
`/api/tmdb/query?q=${encodeURIComponent(query)}&type=serie`,
);
const json = await response.json() as TMDBMovie[];
const menuID = `result/${movie.name}`;
state.menus[menuID] = {
title: "Select",
entries: json.map((m) => ({
title: `${m.title} released ${m.release_date}`,
cb: async () => {
state.activeState.value = "loading";
await fetch(`/api/movies/enhance/${movie.name}/`, {
method: "POST",
body: JSON.stringify({ tmdbId: m.id }),
});
state.visible.value = false;
state.activeState.value = "normal";
window.location.reload();
},
})),
};
state.activeMenu.value = menuID;
state.activeState.value = "normal";
},
visible: () => {
const loc = globalThis["location"];
if (!getCookie("session_cookie")) return false;
return (loc?.pathname?.includes("movie") &&
!loc.pathname.endsWith("movies")) ||
(loc?.pathname?.includes("series") && !loc.pathname.endsWith("series"));
},
};

View File

@ -14,14 +14,13 @@ import { isLocalImage } from "@lib/string.ts";
export const RedirectSearchHandler = () => {
useEventListener("keydown", (e: KeyboardEvent) => {
if (e?.target?.nodeName == "INPUT") return;
if (
e.key === "?" &&
window.location.search === ""
) {
window.location.href += "?q=";
}
});
}, document?.body);
return <></>;
};
@ -136,13 +135,14 @@ const SearchComponent = (
debouncedFetchData(q);
}, []);
console.log({ data, isLoading });
return (
<div class="mt-2">
<div
class="flex items-center gap-1 rounded-xl w-full shadow-2xl"
style={{ background: "#2B2930", color: "#818181" }}
>
{isLoading
{isLoading && searchQuery
? <IconLoader2 class="w-4 h-4 ml-4 mr-2 animate-spin" />
: <IconSearch class="w-4 h-4 ml-4 mr-2" />}
<input