mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 04:27:21 +00:00
reduce schema manager query log to debug, fix useSearch
This commit is contained in:
@@ -333,7 +333,7 @@ export class SchemaManager {
|
||||
|
||||
if (config.force) {
|
||||
try {
|
||||
$console.log("[SchemaManager]", sql);
|
||||
$console.debug("[SchemaManager]", sql);
|
||||
await qb.execute();
|
||||
} catch (e) {
|
||||
throw new Error(`Failed to execute query: ${sql}: ${(e as any).message}`);
|
||||
|
||||
@@ -2,7 +2,7 @@ import { decodeSearch, encodeSearch, mergeObject } from "core/utils";
|
||||
import { isEqual, transform } from "lodash-es";
|
||||
import { useLocation, useSearch as useWouterSearch } from "wouter";
|
||||
import { type s, parse } from "core/object/schema";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
|
||||
export type UseSearchOptions<Schema extends s.TAnySchema = s.TAnySchema> = {
|
||||
defaultValue?: Partial<s.StaticCoerced<Schema>>;
|
||||
@@ -18,21 +18,24 @@ export function useSearch<Schema extends s.TAnySchema = s.TAnySchema>(
|
||||
const [value, setValue] = useState<s.StaticCoerced<Schema>>(
|
||||
options?.defaultValue ?? ({} as any),
|
||||
);
|
||||
const _defaults = mergeObject(
|
||||
// @ts-ignore
|
||||
schema.template({ withOptional: true }),
|
||||
options?.defaultValue ?? {},
|
||||
);
|
||||
|
||||
const defaults = useMemo(() => {
|
||||
return mergeObject(
|
||||
// @ts-ignore
|
||||
schema.template({ withOptional: true }),
|
||||
options?.defaultValue ?? {},
|
||||
);
|
||||
}, [JSON.stringify({ schema, dflt: options?.defaultValue })]);
|
||||
|
||||
useEffect(() => {
|
||||
const initial =
|
||||
searchString.length > 0 ? decodeSearch(searchString) : (options?.defaultValue ?? {});
|
||||
const v = parse(schema, Object.assign({}, _defaults, initial)) as any;
|
||||
const v = parse(schema, Object.assign({}, defaults, initial)) as any;
|
||||
setValue(v);
|
||||
}, [searchString, JSON.stringify(options?.defaultValue), location]);
|
||||
|
||||
function set<Update extends Partial<s.StaticCoerced<Schema>>>(update: Update): void {
|
||||
const search = getWithoutDefaults(Object.assign({}, value, update), _defaults);
|
||||
const search = getWithoutDefaults(Object.assign({}, value, update), defaults);
|
||||
const prepared = options?.beforeEncode?.(search) ?? search;
|
||||
const encoded = encodeSearch(prepared, { encode: false });
|
||||
navigate(location + (encoded.length > 0 ? "?" + encoded : ""));
|
||||
|
||||
Reference in New Issue
Block a user