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

Commit

Permalink
feat: enable search paging
Browse files Browse the repository at this point in the history
  • Loading branch information
Schlauer-Hax committed Aug 13, 2024
1 parent 75ee8f1 commit aba6136
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
6 changes: 3 additions & 3 deletions pages/admin/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ export const state = asState({
oauth: <External<OAuthApp[]> | "loading"> "loading",
files: <External<File[]> | "loading"> "loading",
wallets: <External<Wallet[]> | "loading"> "loading",
search: <SearchResult[]> [],
searchStats: <External<{ total: number; took: number }> | "loading"> "loading",
search: <External<SearchResult[]> | "loading"> "loading",
searchQuery: <string> "",
});

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 type SearchResult = { _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" };

export const reviewState = asState({
// deno-lint-ignore no-explicit-any
Expand Down
10 changes: 5 additions & 5 deletions pages/admin/views/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,11 @@ export const adminMenu = Navigation({
title: ref`Search`,
children: [
TextInput("text", "Search").onChange(debounce(async (data) => {
if (!data) return;
state.search = asState([{ _index: "searching" }]);
const elasticresults = await API.admin.search(data ?? "").then(stupidErrorAlert);
state.search = asState(elasticresults.hits.hits);
state.searchStats = asState({ total: elasticresults.hits.total.value, took: elasticresults.took });
state.searchQuery = data;
state.search = await API.admin.search(data ?? "").then(stupidErrorAlert);
}, 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, (it) => {
switch (it._index) {
case "transcripts":
Expand Down Expand Up @@ -107,7 +106,8 @@ export const adminMenu = Navigation({
console.log("Unimplemented Type", it);
return placeholder("Unimplemented Type", "Please implement");
})
.setPlaceholder(placeholder("No Results", "No results found.")),
.setPlaceholder(placeholder("No Results", "No results found."))
.enablePaging((offset, limit) => loadMore(state.$search, () => API.admin.search(state.searchQuery, offset, limit))),
],
},
{
Expand Down
3 changes: 2 additions & 1 deletion pages/shared/restSpec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Artist, BugReport, Drop, DropType, File, Group, Meta, OAuthApp, Payout, RequestPayoutResponse, Server, ServerAudit, ServerCreate, ServerTypes, Song, StoreItems, Wallet } from "../../spec/music.ts";
import { SearchResult } from "../admin/state.ts";
import { ProfileData } from "./helper.ts";

export const Permissions = [
Expand Down Expand Up @@ -273,7 +274,7 @@ export const API = {
return fetch(`${API.BASE_URL}admin/search/${query}?${paging}`, {
headers: headers(API.getToken()),
})
.then(json<object[]>())
.then(json<SearchResult[]>())
.catch(reject)
},
files: {
Expand Down

0 comments on commit aba6136

Please sign in to comment.