feat: add initial add article command
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
import { Menu } from "@islands/KMenu/types.ts";
|
||||
import { Movie } from "@lib/resource/movies.ts";
|
||||
import { TMDBMovie } from "@lib/types.ts";
|
||||
import { isValidUrl } from "@lib/helpers.ts";
|
||||
|
||||
export const menus: Record<string, Menu> = {
|
||||
main: {
|
||||
@ -14,6 +15,35 @@ export const menus: Record<string, Menu> = {
|
||||
},
|
||||
visible: () => false,
|
||||
},
|
||||
{
|
||||
title: "Create new article",
|
||||
meta: "",
|
||||
cb: (state) => {
|
||||
state.menus["input_link"] = {
|
||||
title: "Link:",
|
||||
entries: [],
|
||||
};
|
||||
state.activeMenu.value = "input_link";
|
||||
|
||||
const unsub = state.commandInput.subscribe(async (value) => {
|
||||
if (isValidUrl(value)) {
|
||||
unsub();
|
||||
|
||||
state.activeState.value = "loading";
|
||||
|
||||
const response = await fetch("/api/articles/create?url=" + value);
|
||||
const newArticle = await response.json();
|
||||
|
||||
if (newArticle?.id) {
|
||||
window.location.href = "/articles/" + newArticle.id;
|
||||
}
|
||||
|
||||
state.visible.value = false;
|
||||
}
|
||||
});
|
||||
},
|
||||
visible: () => true,
|
||||
},
|
||||
{
|
||||
title: "Clear Cache",
|
||||
cb: async (state) => {
|
||||
@ -59,13 +89,14 @@ export const menus: Record<string, Menu> = {
|
||||
})),
|
||||
};
|
||||
|
||||
console.log({ state });
|
||||
|
||||
state.activeMenu.value = menuID;
|
||||
|
||||
state.activeState.value = "normal";
|
||||
},
|
||||
visible: () => false,
|
||||
visible: () => {
|
||||
const loc = globalThis["location"];
|
||||
return loc?.pathname?.includes("movie");
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Reload Page",
|
||||
|
@ -3,6 +3,7 @@ import { Signal } from "@preact/signals";
|
||||
export type MenuState = {
|
||||
activeMenu: Signal<string>;
|
||||
activeState: Signal<"error" | "normal" | "loading">;
|
||||
commandInput: Signal<string>;
|
||||
visible: Signal<boolean>;
|
||||
menus: Record<string, Menu>;
|
||||
};
|
||||
|
Reference in New Issue
Block a user