From f0ebf2f6a83e909fc8faa7d0869a1819008aa66a Mon Sep 17 00:00:00 2001 From: lucsoft Date: Wed, 19 Apr 2023 17:47:30 +0200 Subject: [PATCH] feat(menu): Add menubaraction --- pages/admin/views/menu.ts | 2 +- pages/music/views/menu.ts | 8 ++++++++ pages/shared/Menu.ts | 7 ++++--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/pages/admin/views/menu.ts b/pages/admin/views/menu.ts index 28d7fb91..124f8140 100644 --- a/pages/admin/views/menu.ts +++ b/pages/admin/views/menu.ts @@ -1,4 +1,4 @@ -import { Reactive, Vertical } from "https://raw.githubusercontent.com/lucsoft/WebGen/3f922fc/mod.ts"; +import { Reactive, Vertical } from "webgen/mod.ts"; import { state } from "../state.ts"; import { Menu } from "../../shared/Menu.ts"; import { activeUser } from "../../manager/helper.ts"; diff --git a/pages/music/views/menu.ts b/pages/music/views/menu.ts index e33237c1..788b29ce 100644 --- a/pages/music/views/menu.ts +++ b/pages/music/views/menu.ts @@ -6,10 +6,18 @@ import { getListCount } from "../../shared/listCount.ts"; import { musicList } from "./list.ts"; import { DropType } from "../../../spec/music.ts"; import { LoadingSpinner } from "../../shared/components.ts"; +import { API } from "../../manager/RESTSpec.ts"; export const musicMenu = () => Reactive(state, "loaded", () => Menu({ title: activeUser.username ? `Hi ${activeUser.username} 👋` : `Hello 👋`, id: "/", + menuBarAction: { + title: "Submit new Drop", + onclick: async () => { + const id = await API.music(API.getToken()).post(); + location.href = `/music/new-drop?id=${id}`; + } + }, categories: { "published/": { title: `Published ${getListCount(state.published)}`, diff --git a/pages/shared/Menu.ts b/pages/shared/Menu.ts index 5bb535df..84b0ebe6 100644 --- a/pages/shared/Menu.ts +++ b/pages/shared/Menu.ts @@ -1,4 +1,4 @@ -import { Box, ButtonComponent, Component, PlainText, Reactive, State, Vertical } from "webgen/mod.ts"; +import { Box, ButtonComponent, Component, Reactive, State, Vertical } from "webgen/mod.ts"; import { ActionBar, Link } from "../manager/misc/actionbar.ts"; import { Entry } from "../manager/misc/Entry.ts"; @@ -19,6 +19,7 @@ interface MenuItem { interface RootMenuItem extends MenuItem { categories?: { [ group in `${string}/` ]: Omit }; + menuBarAction?: Link, } const FilterLastItem = (_: MenuItem, index: number, list: MenuItem[]): boolean => index != list.length - 1; @@ -93,7 +94,7 @@ export const Menu = (rootMenu: RootMenuItem) => new class extends Component { ); return Vertical( - ActionBar(active.title, undefined, undefined, list), + ActionBar(active.title, undefined, rootMenu.menuBarAction, list), this.renderList(active.items), active.custom?.(activeEntries.map(x => x.id).join("") + active.id) ?? null ); @@ -106,7 +107,7 @@ export const Menu = (rootMenu: RootMenuItem) => new class extends Component { selected: key == this.getActivePath().at(-1)!.id.replace("+", ""), onclick: () => this.nav.active = rootMenu.id + key }; - })); + }), rootMenu.menuBarAction); } private renderList(active?: MenuItem[]): Component | null {