Skip to content

Commit

Permalink
feat(menu): Add menubaraction
Browse files Browse the repository at this point in the history
  • Loading branch information
lucsoft committed Apr 19, 2023
1 parent c4392e3 commit f0ebf2f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pages/admin/views/menu.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
8 changes: 8 additions & 0 deletions pages/music/views/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`,
Expand Down
7 changes: 4 additions & 3 deletions pages/shared/Menu.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -19,6 +19,7 @@ interface MenuItem {

interface RootMenuItem extends MenuItem {
categories?: { [ group in `${string}/` ]: Omit<MenuItem, "id"> };
menuBarAction?: Link,
}

const FilterLastItem = (_: MenuItem, index: number, list: MenuItem[]): boolean => index != list.length - 1;
Expand Down Expand Up @@ -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
);
Expand All @@ -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 {
Expand Down

0 comments on commit f0ebf2f

Please sign in to comment.