[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); $: allTypeAddresses = ($entity?.attr["IS"] || []).map((attr) => attr.value.c);
$: allTypeEntries = query( $: allTypeEntries = query(
() => `(matches (in ${allTypeAddresses
`(matches (in ${allTypeAddresses .map((addr) => `"${addr}"`)
.map((addr) => `"${addr}"`) .join(" ")}) ? ?)`
.join(" ")}) ? ?)`
).result; ).result;
let allTypes: { [key: string]: UpType } = {}; let allTypes: { [key: string]: UpType } = {};

View File

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

View File

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

View File

@ -4,8 +4,7 @@ import { query as queryFn, queryOnce } from "../lib/entity";
export function baseSearch(query: string) { export function baseSearch(query: string) {
return queryFn( 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( const { result: lastVisitedQuery } = query(`(matches ? "LAST_VISITED" ? )`);
() => `(matches ? "LAST_VISITED" ? )`
);
$: lastVisited = ($lastVisitedQuery?.entries || []) $: lastVisited = ($lastVisitedQuery?.entries || [])
.filter((e) => e.value.t == "Number") .filter((e) => e.value.t == "Number")
.sort((a, b) => (b.value.c as number) - (a.value.c as number)) .sort((a, b) => (b.value.c as number) - (a.value.c as number))