memorium/islands/KMenu/commands.ts

79 lines
2.2 KiB
TypeScript
Raw Normal View History

2023-07-31 04:19:04 +02:00
import { Menu } from "@islands/KMenu/types.ts";
2023-08-04 13:48:12 +02:00
import { addMovieInfos } from "@islands/KMenu/commands/add_movie_infos.ts";
import { createNewMovie } from "@islands/KMenu/commands/create_movie.ts";
import { createNewArticle } from "@islands/KMenu/commands/create_article.ts";
2023-08-04 22:35:25 +02:00
import { getCookie } from "@lib/string.ts";
2023-08-08 21:50:23 +02:00
import { addSeriesInfo } from "@islands/KMenu/commands/add_series_infos.ts";
2023-08-10 18:59:23 +02:00
import { createNewSeries } from "@islands/KMenu/commands/create_series.ts";
2023-07-31 04:19:04 +02:00
export const menus: Record<string, Menu> = {
main: {
title: "Run",
entries: [
2023-08-01 18:35:35 +02:00
{
title: "Clear Cache",
2023-08-02 13:11:17 +02:00
icon: "IconRefresh",
2023-08-01 18:35:35 +02:00
cb: async (state) => {
state.activeState.value = "loading";
await fetch("/api/cache", {
method: "DELETE",
});
state.activeState.value = "normal";
state.visible.value = false;
},
2023-08-04 22:35:25 +02:00
visible: () => {
if (!getCookie("session_cookie")) return false;
return true;
},
},
{
title: "Login",
icon: "IconLogin",
cb: () => {
const url = new URL(window.location.href);
url.pathname = "/api/auth/login";
url.searchParams.set(
"redirect",
encodeURIComponent(window.location.pathname),
);
window.location.href = url.href;
2023-08-04 22:35:25 +02:00
},
visible: () => {
return !getCookie("session_cookie");
},
},
2023-08-06 17:47:26 +02:00
{
title: "Search",
icon: "IconSearch",
cb: () => {
window.location.href += "?q=";
},
visible: () => {
return !!getCookie("session_cookie") && window.location.search === "";
},
},
2023-08-04 22:35:25 +02:00
{
title: "Logout",
icon: "IconLogout",
cb: () => {
const url = new URL(window.location.href);
url.pathname = "/api/auth/logout";
url.searchParams.set(
"redirect",
encodeURIComponent(window.location.pathname),
);
window.location.href = url.href;
2023-08-04 22:35:25 +02:00
},
visible: () => {
return !!getCookie("session_cookie");
},
2023-08-01 18:35:35 +02:00
},
2023-08-08 21:50:23 +02:00
addSeriesInfo,
2023-08-04 13:48:12 +02:00
createNewArticle,
createNewMovie,
2023-08-10 18:59:23 +02:00
createNewSeries,
2023-08-04 13:48:12 +02:00
addMovieInfos,
2023-07-31 04:19:04 +02:00
],
},
};