Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
tot
Browse files Browse the repository at this point in the history
  • Loading branch information
greg6775 committed Nov 18, 2024
1 parent 33c1d10 commit 1095cb7
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 210 deletions.
2 changes: 1 addition & 1 deletion deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"shared/": "./pages/shared/",
"zod/": "https://deno.land/x/zod@v3.23.8/",
// "webgen/": "../WebGen/"
"webgen/": "https://raw.githubusercontent.com/lucsoft/WebGen/2d77f48/"
"webgen/": "https://raw.githubusercontent.com/lucsoft/WebGen/f53d3dd/"
},
"lock": false,
"compilerOptions": {
Expand Down
6 changes: 3 additions & 3 deletions pages/music/views/menu.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { activeUser } from "shared/helper.ts";
import { API, Chart, count, HeavyList, LoadingSpinner, Navigation, placeholder, stupidErrorAlert } from "shared/mod.ts";
import { asRef, asState, Button, Component, Entry, Grid, isMobile, ref } from "webgen/mod.ts";
import { API, Chart, count, placeholder, stupidErrorAlert } from "shared/mod.ts";
import { asRef, asRefRecord, Component, Entry, Grid, isMobile, ref } from "webgen/mod.ts";
import { Artist, Drop, DropType, Payout } from "../../../spec/music.ts";
import { ArtistEntry, DropEntry, musicList } from "./list.ts";
import { createArtistSheet } from "./table.ts";

export const menuState = asState({
export const menuState = asRefRecord({
published: <Drop[] | "loading"> "loading",
unpublished: <Drop[] | "loading"> "loading",
drafts: <Drop[] | "loading"> "loading",
Expand Down
4 changes: 3 additions & 1 deletion pages/shared/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ function shouldLoginPage() {
throw "aborting javascript here";
}

export const sheetStack = Sheets()
export const sheetStack = Sheets();

sheetStack
.setMinWidth("auto")
.setWidth("auto");

Expand Down
128 changes: 21 additions & 107 deletions pages/shared/list.ts
Original file line number Diff line number Diff line change
@@ -1,109 +1,23 @@
// import { asRef, asState, Box, Button, CenterV, Component, Empty, Horizontal, Label, MIcon, Refable, Reference, Vertical } from "webgen/mod.ts";
// import { LoadingSpinner } from "./components.ts";
// import { displayError, External } from "./restSpec.ts";
import { Grid, Label, Reference } from "webgen/mod.ts";
import { External } from "./restSpec.ts";

// // TODO: don't rerender the complete list on update. virtual list?
// export const HeavyList = <T>(items: Refable<External<T[]> | "loading" | T[]>, map: (val: T) => Component) =>
// new class extends Component {
// placeholder = Box();
// loadMore = async (_offset: number, _limit: number) => {};
// paging = asState({ enabled: false, limit: 30 });
export const placeholder = (title: string, subtitle: string) =>
Grid(
Label(title)
.setTextSize("4xl")
.setFontWeight("bold")
.addClass("list-title"),
Label(subtitle)
.setTextSize("xl"),
).setGap("1rem").setMargin("100px 0 0").setAttribute("align", "center");

// constructor() {
// super();
// console.debug("HeavyList got constructed");
// const list = asRef(items);
// list.listen((val: External<T[]> | "loading" | T[]) => {
// this.wrapper.textContent = "";
// if (val === "loading") {
// this.wrapper.append(
// LoadingSpinner().draw(),
// );
// } else if ("status" in val) {
// if (val.status === "fulfilled") {
// this.wrapper.append(
// this.paging.$enabled.map(() =>
// this.#canLoadMore(val.value.length)
// ? Vertical(
// ...val.value.length == 0 ? [this.placeholder] : val.value.map((x) => map(x))
// .filter((_, index) => index % this.paging.limit !== 1),
// Horizontal(
// Button("Load More").onPromiseClick(() => this.loadMore(val.value.length, this.paging.limit)),
// )
// .setMargin("0 0 var(--gap)"),
// )
// .setGap()
// : Vertical(
// ...val.value.length == 0 ? [this.placeholder] : val.value.map((x) => map(x)),
// )
// .setGap()
// )
// .asRefComponent()
// .draw(),
// );
// } else {
// this.wrapper.append(
// Horizontal(
// Vertical(
// MIcon("error"),
// Label(displayError(val.reason)),
// )
// .setAlignItems("center")
// .setGap("calc(var(--gap) * 0.25)")
// .addClass("error-message"),
// )
// .draw(),
// );
// }
// } else {
// this.wrapper.append(
// Vertical(
// ...val.length == 0 ? [this.placeholder] : val.map((x) => map(x)),
// this.paging.$enabled.map(() => this.paging.enabled ? Button("Load More").setMargin("0 0 var(--gap)").onPromiseClick(() => this.loadMore(val.length - 2, this.paging.limit + 1)) : Empty()).asRefComponent().removeFromLayout(),
// )
// .setGap()
// .draw(),
// );
// }
// });
// }
// #canLoadMore(length: number) {
// return this.paging.enabled && (length % this.paging.limit == 1);
// }
// enablePaging(loadMore: (offset: number, limit: number) => Promise<void>, limit = 30) {
// this.paging.enabled = true;
// this.paging.limit = limit;
// this.loadMore = loadMore;
// return this;
// }

// setPlaceholder(val: Component) {
// this.placeholder = val;
// return this;
// }
// }();

// export const placeholder = (title: string, subtitle: string) =>
// CenterV(
// Label(title)
// .setTextSize("4xl")
// .setFontWeight("bold")
// .addClass("list-title"),
// Label(subtitle)
// .setTextSize("xl"),
// ).setMargin("100px 0 0").setGap("1rem").setAttribute("align", "center");

// export async function loadMore<T>(source: Reference<External<T[]> | "loading">, func: () => Promise<External<T[]>>) {
// const data = source.getValue();
// if (data !== "loading" && data.status !== "rejected") {
// const rsp = await func();
// if (rsp.status == "rejected") {
// source.setValue(rsp);
// } else {
// source.setValue({
// status: "fulfilled",
// value: [...data.value, ...rsp.value],
// });
// }
// }
// }
export async function loadMore<T>(source: Reference<External<T[]> | "loading">, func: () => Promise<External<T[]>>) {
const data = source.getValue();
if (data !== "loading" && data.status !== "rejected") {
const rsp = await func();
source.value = rsp.status == "rejected" ? rsp : {
status: "fulfilled",
value: [...data.value, ...rsp.value],
};
}
}
7 changes: 3 additions & 4 deletions pages/shared/navigation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// import { assert } from "@std/assert";
// import { asRef, Box, Component, Empty, Entry, Grid, isMobile, isRef, Label, MIcon, Refable, Reference, Taglist, Vertical } from "webgen/mod.ts";
// import { HeavyList } from "./list.ts";
// import { alwaysRef, asRef, Box, Component, Empty, Entry, Grid, isMobile, isRef, Label, Refable, Reference } from "webgen/mod.ts";
// import "./navigation.css";

// export interface ClickHandler {
Expand Down Expand Up @@ -36,7 +35,7 @@

// for (const segment of pathSegments) {
// if (currentNode?.children) {
// const childNode = asRef(currentNode.children).getValue().find(
// const childNode = alwaysRef(currentNode.children).getValue().find(
// (child) => !(child instanceof Component) && child.id === segment,
// ) as MenuNode | undefined;

Expand All @@ -60,7 +59,7 @@

// for (const segment of pathSegments) {
// if (currentNode?.children) {
// const childNode = asRef(currentNode.children).getValue().find(
// const childNode = alwaysRef(currentNode.children).getValue().find(
// (child) => !(child instanceof Component) && child.id === segment,
// ) as MenuNode | undefined;

Expand Down
10 changes: 5 additions & 5 deletions pages/user/signin.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { assert } from "@std/assert";
import { Footer } from "shared/footer.ts";
import { RegisterAuthRefresh } from "shared/helper.ts";
import { API, LoadingSpinner } from "shared/mod.ts";
import { Body, Box, Button, ButtonStyle, Color, Component, createElement, Custom, Grid, Horizontal, Image, isMobile, Label, LinkButton, Spacer, TextInput, Vertical } from "webgen/mod.ts";
import { API } from "shared/mod.ts";
import { appendBody, Box, Color, Component, Content, Empty, Grid, Image, isMobile, Label, TextInput, WebGenTheme } from "webgen/mod.ts";
import "../../assets/css/main.css";
import { discordLogo, googleLogo } from "../../assets/imports.ts";
import { DynaNavigation } from "../../components/nav.ts";
Expand All @@ -28,9 +28,9 @@ const ErrorMessage = () =>
.asRefComponent()
.removeFromLayout();

Body(Vertical(
appendBody(WebGenTheme(Content(Grid(
DynaNavigation("Home"),
Box().addClass("background-image"),
Empty().addClass("background-image"),
Box(
Grid(
isMobile.map((small) =>
Expand Down Expand Up @@ -207,6 +207,6 @@ Body(Vertical(
),
).addClass("auth-area"),
Footer(),
));
))));

await handleStateChange();
Loading

0 comments on commit 1095cb7

Please sign in to comment.