Skip to content

Commit e72125c

Browse files
committed
use useSQLQueryState hook
1 parent dd58930 commit e72125c

File tree

5 files changed

+19
-8
lines changed

5 files changed

+19
-8
lines changed

packages/explorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/explore/Explorer.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use client";
22

33
import { useParams } from "next/navigation";
4-
import { parseAsString, useQueryState } from "nuqs";
4+
import { useQueryState } from "nuqs";
55
import { Hex } from "viem";
66
import { useEffect, useState } from "react";
77
import { useChain } from "../../../../hooks/useChain";
@@ -12,15 +12,16 @@ import { indexerForChainId } from "../../../../utils/indexerForChainId";
1212
import { SQLEditor } from "./SQLEditor";
1313
import { TableSelector } from "./TableSelector";
1414
import { TablesViewer } from "./TablesViewer";
15-
import { usePaginationQueryState } from "./hooks/usePaginationQueryState";
15+
import { usePaginationQueryState } from "./hooks/usePaginationState";
16+
import { useSQLQueryState } from "./hooks/useSQLQueryState";
1617

1718
export function Explorer() {
1819
const { worldAddress } = useParams();
1920
const { id: chainId } = useChain();
2021
const indexer = indexerForChainId(chainId);
2122
const [isLiveQuery, setIsLiveQuery] = useState(false);
2223
const [{ pageSize }] = usePaginationQueryState();
23-
const [query, setQuery] = useQueryState("query", parseAsString.withDefault(""));
24+
const { query, setQuery } = useSQLQueryState();
2425
const [selectedTableId] = useQueryState("tableId");
2526
const prevSelectedTableId = usePrevious(selectedTableId);
2627
const { data: tables } = useTablesQuery();

packages/explorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/explore/SQLEditor.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import { CommandIcon, CornerDownLeft, LoaderIcon, PauseIcon, PlayIcon } from "lucide-react";
44
import { KeyCode, KeyMod, editor } from "monaco-editor/esm/vs/editor/editor.api";
5-
import { useQueryState } from "nuqs";
65
import { useEffect, useRef, useState } from "react";
76
import { useForm } from "react-hook-form";
87
import { Table } from "@latticexyz/config";
@@ -13,7 +12,8 @@ import { Form, FormField } from "../../../../../../components/ui/Form";
1312
import { cn } from "../../../../../../utils";
1413
import { useTableDataQuery } from "../../../../queries/useTableDataQuery";
1514
import { PAGE_SIZE_OPTIONS, monacoOptions } from "./consts";
16-
import { usePaginationQueryState } from "./hooks/usePaginationQueryState";
15+
import { usePaginationQueryState } from "./hooks/usePaginationState";
16+
import { useSQLQueryState } from "./hooks/useSQLQueryState";
1717
import { useMonacoSuggestions } from "./useMonacoSuggestions";
1818
import { useQueryValidator } from "./useQueryValidator";
1919
import { getLimitOffset } from "./utils/getLimitOffset";
@@ -29,8 +29,8 @@ export function SQLEditor({ table, isLiveQuery, setIsLiveQuery }: Props) {
2929
const containerRef = useRef<HTMLDivElement>(null);
3030
const [isFocused, setIsFocused] = useState(false);
3131
const [isUserTriggeredRefetch, setIsUserTriggeredRefetch] = useState(false);
32-
const [query, setQuery] = useQueryState("query", { defaultValue: "" });
3332
const [pagination, setPagination] = usePaginationQueryState();
33+
const { query, setQuery } = useSQLQueryState();
3434

3535
const validateQuery = useQueryValidator(table);
3636
const {

packages/explorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/explore/TablesViewer.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ import { indexerForChainId } from "../../../../utils/indexerForChainId";
3434
import { EditableTableCell } from "./EditableTableCell";
3535
import { ExportButton } from "./ExportButton";
3636
import { PAGE_SIZE_OPTIONS } from "./consts";
37-
import { usePaginationQueryState } from "./hooks/usePaginationQueryState";
37+
import { usePaginationQueryState } from "./hooks/usePaginationState";
38+
import { useSQLQueryState } from "./hooks/useSQLQueryState";
3839
import { getLimitOffset } from "./utils/getLimitOffset";
3940
import { typeSortingFn } from "./utils/typeSortingFn";
4041

@@ -50,7 +51,7 @@ type Props = {
5051
export function TablesViewer({ table, isLiveQuery }: Props) {
5152
const { id: chainId } = useChain();
5253
const indexer = indexerForChainId(chainId);
53-
const [query, setQuery] = useQueryState("query", parseAsString.withDefault(""));
54+
const { query, setQuery } = useSQLQueryState();
5455
const [globalFilter, setGlobalFilter] = useQueryState("filter", parseAsString.withDefault(""));
5556
const [sorting, setSorting] = useQueryState("sort", parseAsJson<SortingState>().withDefault(initialSortingState));
5657
const [pagination, setPagination] = usePaginationQueryState();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { parseAsString, useQueryState } from "nuqs";
2+
3+
export function useSQLQueryState() {
4+
const [query, setQuery] = useQueryState("query", parseAsString.withDefault(""));
5+
return {
6+
query: decodeURIComponent(query),
7+
setQuery: (value: string) => setQuery(encodeURIComponent(value)),
8+
};
9+
}

0 commit comments

Comments
 (0)