From 75ee8f170cfaf426ec5ef86706fbaa7d7d532963 Mon Sep 17 00:00:00 2001 From: Schlauer-Hax Date: Tue, 13 Aug 2024 21:47:06 +0800 Subject: [PATCH] remove duplicate code --- pages/admin/state.ts | 4 +++- pages/admin/views/menu.ts | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pages/admin/state.ts b/pages/admin/state.ts index 639ef05..6992d03 100644 --- a/pages/admin/state.ts +++ b/pages/admin/state.ts @@ -13,10 +13,12 @@ export const state = asState({ oauth: | "loading"> "loading", files: | "loading"> "loading", wallets: | "loading"> "loading", - search: <({ _index: "transcripts"; _source: Transcript } | { _index: "drops"; _source: Drop } | { _index: "servers"; _source: Server } | { _index: "users"; _source: ProfileData } | { _index: "files"; _source: File } | { _index: "none" } | { _index: "searching" })[]>[], + search: [], searchStats: | "loading"> "loading", }); +export type SearchResult = { _index: "transcripts"; _source: Transcript } | { _index: "drops"; _source: Drop } | { _index: "servers"; _source: Server } | { _index: "users"; _source: ProfileData } | { _index: "files"; _source: File } | { _index: "none" } | { _index: "searching" }; + export const reviewState = asState({ // deno-lint-ignore no-explicit-any drop: undefined, diff --git a/pages/admin/views/menu.ts b/pages/admin/views/menu.ts index 2ce301d..88c9607 100644 --- a/pages/admin/views/menu.ts +++ b/pages/admin/views/menu.ts @@ -3,8 +3,8 @@ import { sumOf } from "@std/collections"; import loader from "https://esm.sh/@monaco-editor/loader@1.4.0"; import { API, HeavyList, loadMore, Navigation, placeholder, stupidErrorAlert } from "shared/mod.ts"; import { asRef, asState, Box, Button, Color, Custom, Entry, Grid, Horizontal, isMobile, Label, lazy, ref, SheetDialog, Spacer, Table, TextInput, Vertical } from "webgen/mod.ts"; -import { Drop, DropType, File, Server, Transcript } from "../../../spec/music.ts"; -import { activeUser, ProfileData, sheetStack, showProfilePicture } from "../../shared/helper.ts"; +import { DropType } from "../../../spec/music.ts"; +import { activeUser, sheetStack, showProfilePicture } from "../../shared/helper.ts"; import { upload } from "../loading.ts"; import { state } from "../state.ts"; import { ReviewEntry } from "./entryReview.ts"; @@ -54,7 +54,7 @@ export const adminMenu = Navigation({ state.searchStats = asState({ total: elasticresults.hits.total.value, took: elasticresults.took }); }, 1000)), state.$searchStats.map((it) => (it === "loading" || it.status === "rejected") ? Box() : Label(`${state.$searchStats.getValue().took}ms | ${state.$searchStats.getValue().total} Entries`)).asRefComponent(), - HeavyList(state.$search.map((it) => it as ({ _index: "transcripts"; _source: Transcript } | { _index: "drops"; _source: Drop } | { _index: "servers"; _source: Server } | { _index: "users"; _source: ProfileData } | { _index: "files"; _source: File } | { _index: "user-events"; _source: object } | { _index: "none" } | { _index: "searching" })[]), (it) => { + HeavyList(state.$search, (it) => { switch (it._index) { case "transcripts": return Entry(