Files
memorium/islands/KMenu/commands/create_recommendations.ts

33 lines
925 B
TypeScript

import { MenuEntry } from "@islands/KMenu/types.ts";
import { fetchStream } from "@lib/helpers.ts";
import { getCookie } from "@lib/string.ts";
export const updateAllRecommendations: MenuEntry = {
title: "Update all recommendations",
meta: "",
icon: "IconSquareRoundedPlus",
cb: (state) => {
state.activeState.value = "loading";
fetchStream("/api/recommendation/all", (chunk) => {
if (chunk.type === "error") {
state.activeState.value = "error";
state.loadingText.value = chunk.message;
} else if (chunk.type === "finished") {
setTimeout(() => {
globalThis.location.reload();
}, 500);
} else {
state.loadingText.value = chunk.message;
}
});
},
visible: () => {
if (!getCookie("session_cookie")) return false;
if (
!globalThis?.location?.pathname?.includes("movies")
) return false;
return true;
},
};