memorium/islands/KMenu/commands.ts

81 lines
2.1 KiB
TypeScript
Raw Normal View History

2023-07-31 04:19:04 +02:00
import { Menu } from "@islands/KMenu/types.ts";
2023-08-01 17:50:00 +02:00
import { Movie } from "@lib/resource/movies.ts";
2023-07-31 04:19:04 +02:00
import { TMDBMovie } from "@lib/types.ts";
export const menus: Record<string, Menu> = {
main: {
title: "Run",
entries: [
{
title: "Close menu",
meta: "",
cb: (state) => {
state.visible.value = false;
},
visible: () => false,
},
2023-08-01 18:35:35 +02:00
{
title: "Clear Cache",
cb: async (state) => {
state.activeState.value = "loading";
await fetch("/api/cache", {
method: "DELETE",
});
state.activeState.value = "normal";
state.visible.value = false;
},
},
2023-07-31 04:19:04 +02:00
{
title: "Add Movie infos",
meta: "",
cb: async (state, context) => {
state.activeState.value = "loading";
const movie = context as Movie;
2023-07-31 17:21:17 +02:00
const query = movie.name;
2023-07-31 04:19:04 +02:00
const response = await fetch(
`/api/tmdb/query?q=${encodeURIComponent(query)}`,
);
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";
2023-08-01 18:35:35 +02:00
await fetch(`/api/movies/enhance/${movie.name}/`, {
2023-07-31 17:21:17 +02:00
method: "POST",
body: JSON.stringify({ tmdbId: m.id }),
});
2023-07-31 04:19:04 +02:00
state.visible.value = false;
state.activeState.value = "normal";
window.location.reload();
2023-07-31 04:19:04 +02:00
},
})),
};
console.log({ state });
state.activeMenu.value = menuID;
state.activeState.value = "normal";
},
visible: () => false,
},
{
title: "Reload Page",
meta: "",
cb: () => {
window.location.reload();
},
visible: () => false,
},
],
},
};