feat(webui): "Last searched" options in header
parent
8f00f73b69
commit
2d8c9623fa
|
@ -19,15 +19,36 @@
|
|||
|
||||
let selector: Selector;
|
||||
|
||||
let lastSearched: SelectorValue[] = [];
|
||||
|
||||
function addLastSearched(value: SelectorValue) {
|
||||
switch (value.t) {
|
||||
case "Address":
|
||||
lastSearched = lastSearched.filter(
|
||||
(v) => v.t !== "Address" || v.c !== value.c,
|
||||
);
|
||||
break;
|
||||
case "Attribute":
|
||||
lastSearched = lastSearched.filter(
|
||||
(v) => v.t !== "Attribute" || v.name !== value.name,
|
||||
);
|
||||
break;
|
||||
}
|
||||
lastSearched.unshift(value);
|
||||
lastSearched = lastSearched.slice(0, 10);
|
||||
}
|
||||
|
||||
async function onInput(event: CustomEvent<SelectorValue>) {
|
||||
const value = event.detail;
|
||||
if (!value) return;
|
||||
|
||||
switch (value.t) {
|
||||
case "Address":
|
||||
addLastSearched(value);
|
||||
navigate(`/browse/${value.c}`);
|
||||
break;
|
||||
case "Attribute":
|
||||
addLastSearched(value);
|
||||
{
|
||||
const attributeAddress = await api.componentsToAddress({
|
||||
t: "Attribute",
|
||||
|
@ -74,7 +95,7 @@
|
|||
placeholder={$i18n.t("Search or add")}
|
||||
on:input={onInput}
|
||||
bind:this={selector}
|
||||
emptyOptions={[]}
|
||||
emptyOptions={lastSearched}
|
||||
>
|
||||
<Icon name="search" slot="prefix" />
|
||||
</Selector>
|
||||
|
|
Loading…
Reference in New Issue