[ui] switch away from `query()` taking `() => string`

feat/vaults
Tomáš Mládek 2022-02-06 22:27:56 +01:00
parent a83149e746
commit f35d614a83
No known key found for this signature in database
GPG Key ID: ED21612889E75EC5
5 changed files with 9 additions and 16 deletions

View File

@ -28,10 +28,9 @@
$: allTypeAddresses = ($entity?.attr["IS"] || []).map((attr) => attr.value.c);
$: allTypeEntries = query(
() =>
`(matches (in ${allTypeAddresses
.map((addr) => `"${addr}"`)
.join(" ")}) ? ?)`
`(matches (in ${allTypeAddresses
.map((addr) => `"${addr}"`)
.join(" ")}) ? ?)`
).result;
let allTypes: { [key: string]: UpType } = {};

View File

@ -73,9 +73,7 @@
const addressesString = addresses.map((addr) => `"${addr}"`).join(" ");
labelListing = query(
() => `(matches (in ${addressesString}) "LBL" ? )`
).result;
labelListing = query(`(matches (in ${addressesString}) "LBL" ? )`).result;
}
// Sorting

View File

@ -34,12 +34,11 @@ export async function fetchEntry(address: string) {
return listing.entries[0];
}
export function query(query: () => string) {
const queryString = typeof query === "string" ? query : query();
console.debug(`Querying: ${queryString}`);
export function query(query: string) {
console.debug(`Querying: ${query}`);
const { data, error, revalidate } = useSWR<ListingResult, unknown>(
"/api/query",
{ method: "POST", body: queryString }
{ method: "POST", body: query }
);
const result = derived(data, ($values) => {

View File

@ -4,8 +4,7 @@ import { query as queryFn, queryOnce } from "../lib/entity";
export function baseSearch(query: string) {
return queryFn(
() =>
`(or (matches ? (contains "${query}") ?) (matches ? ? (contains "${query}")))`
`(or (matches ? (contains "${query}") ?) (matches ? ? (contains "${query}")))`
);
}

View File

@ -19,9 +19,7 @@
);
})();
const { result: lastVisitedQuery } = query(
() => `(matches ? "LAST_VISITED" ? )`
);
const { result: lastVisitedQuery } = query(`(matches ? "LAST_VISITED" ? )`);
$: lastVisited = ($lastVisitedQuery?.entries || [])
.filter((e) => e.value.t == "Number")
.sort((a, b) => (b.value.c as number) - (a.value.c as number))