[ui] objects searchable/selectable from edit box

feat/vaults
Tomáš Mládek 2022-01-27 21:28:42 +01:00
parent 6b5b8f4bb9
commit fc6212855a
No known key found for this signature in database
GPG Key ID: ED21612889E75EC5
2 changed files with 35 additions and 2 deletions

View File

@ -2,6 +2,7 @@
import { debounce } from "lodash";
import type { IValue } from "upend/types";
import { baseSearch, baseSearchOnce, getObjects } from "../../util/search";
import UpObject from "../display/UpObject.svelte";
import IconButton from "./IconButton.svelte";
import Input from "./Input.svelte";
@ -17,6 +18,11 @@
let options: SelectorOption[] = [];
const updateOptions = debounce(async (query: string) => {
if (query.length == 0) {
options = [];
return;
}
switch (type) {
case "attribute":
const req = await fetch("/api/all/attributes");
@ -30,6 +36,25 @@
});
break;
case "value":
const result = await baseSearchOnce(query);
const objects = await getObjects(result.entries);
options = [
{
value: {
t: "Value",
c: query,
},
},
...objects.slice(0, 25).map(([address, label]) => {
return {
value: {
t: "Address",
c: address,
},
} as SelectorOption;
}),
];
break;
}
}, 200);
@ -98,7 +123,11 @@
{#if option.attribute}
{option.attribute}
{:else if option.value}
RESOLVING LOGIC
{#if option.value.t == "Address"}
<UpObject address={String(option.value.c)} />
{:else}
{option.value.c}
{/if}
{/if}
</li>
{/each}

View File

@ -1,11 +1,15 @@
import type { UpEntry } from "upend";
import type { ListingResult } from "upend/types";
import { fetchEntry, query as queryFn } from "../lib/entity";
import { fetchEntry, query as queryFn, queryOnce } from "../lib/entity";
export function baseSearch(query: string) {
return queryFn(() => `(matches ? ? (contains "${query}"))`);
}
export function baseSearchOnce(query: string) {
return queryOnce(`(matches ? ? (contains "${query}"))`);
}
export async function getObjects(
entries: UpEntry[]
): Promise<[string, string][]> {