diff --git a/packages/playground/src/App.tsx b/packages/playground/src/App.tsx
index 42d93bb..4c1c46f 100644
--- a/packages/playground/src/App.tsx
+++ b/packages/playground/src/App.tsx
@@ -7,10 +7,11 @@ import { ThemeProvider } from '@/components/darkmode-toggle/theme-provider'
import { StatementProvider } from '@/contexts/statement-context-provider'
import { FilesProvider } from '@/contexts/files-context-provider'
import { SchemaProvider } from '@/contexts/schema-context-provider'
+import { ChatProvider } from '@/contexts/chat-context-provider'
+import { EditorExampleWithSelect } from '@/examples/editor-example-with-select'
import { EditorExample } from '@/examples/editor-example'
-import { ChatProvider } from './contexts/chat-context-provider'
-import { EditorExampleWithSelect } from './examples/editor-example-with-select'
+import { UrlStateProvider } from '@/hooks/use-url-state'
const queryClient = new QueryClient({
defaultOptions: {
@@ -44,17 +45,15 @@ function App() {
const params = new URLSearchParams(window.location.search)
const example = params.get('example')
const withSelect = params.get('with_select')
-
const editorTheme = params.get('theme') ?? 'oneDark'
if (example !== null) {
if (withSelect !== null) {
return (
-
+
+
+
)
}
diff --git a/packages/playground/src/contexts/files-context-provider.tsx b/packages/playground/src/contexts/files-context-provider.tsx
index fd47907..fc24788 100644
--- a/packages/playground/src/contexts/files-context-provider.tsx
+++ b/packages/playground/src/contexts/files-context-provider.tsx
@@ -1,4 +1,4 @@
-import React, { useMemo } from 'react'
+import React, { useMemo, useState } from 'react'
import {
addFile,
delFile,
@@ -18,9 +18,9 @@ function FilesLoader() {
}
export function FilesProvider(props: { children: React.ReactNode }) {
- const [allFiles, setAllFiles] = React.useState([])
- const [openedFiles, setOpenedFiles] = React.useState([])
- const [activeFileId, setActiveFileId] = React.useState(null)
+ const [allFiles, setAllFiles] = useState([])
+ const [openedFiles, setOpenedFiles] = useState([])
+ const [activeFileId, setActiveFileId] = useState(null)
const ctxValue = useMemo(
() => ({
diff --git a/packages/playground/src/contexts/schema-context-provider.tsx b/packages/playground/src/contexts/schema-context-provider.tsx
index 30e4a51..319dace 100644
--- a/packages/playground/src/contexts/schema-context-provider.tsx
+++ b/packages/playground/src/contexts/schema-context-provider.tsx
@@ -1,4 +1,4 @@
-import React, { useMemo } from 'react'
+import React, { useMemo, useState } from 'react'
import { getSchema } from '@/api/tidbcloud/schema-api'
import { SchemaContext, SchemaRes } from './schema-context'
@@ -10,7 +10,7 @@ function SchemaLoader() {
}
export function SchemaProvider(props: { children: React.ReactNode }) {
- const [schema, setSchema] = React.useState(null)
+ const [schema, setSchema] = useState(null)
const ctxValue = useMemo(
() => ({ loadSchema: getSchema, schema, setSchema }),
diff --git a/packages/playground/src/contexts/statement-context-provider.tsx b/packages/playground/src/contexts/statement-context-provider.tsx
index 1c6975e..7915d75 100644
--- a/packages/playground/src/contexts/statement-context-provider.tsx
+++ b/packages/playground/src/contexts/statement-context-provider.tsx
@@ -1,4 +1,4 @@
-import React, { useMemo } from 'react'
+import React, { useMemo, useState } from 'react'
import { SqlStatement } from '@tidbcloud/codemirror-extension-sql-parser'
@@ -6,7 +6,7 @@ import { runSQL } from '@/api/tidbcloud/statement-api'
import { StatementContext } from './statement-context'
export function StatementProvider(props: { children: React.ReactNode }) {
- const [runResult, setRunResult] = React.useState({})
+ const [runResult, setRunResult] = useState({})
const runStatement = (_fileId: string, statement: SqlStatement) => {
return runSQL({ database: statement.database, sql: statement.content })
diff --git a/packages/playground/src/examples/editor-example-with-select.tsx b/packages/playground/src/examples/editor-example-with-select.tsx
index 047b9a9..21ca97a 100644
--- a/packages/playground/src/examples/editor-example-with-select.tsx
+++ b/packages/playground/src/examples/editor-example-with-select.tsx
@@ -1,4 +1,4 @@
-import { useEffect, useState } from 'react'
+import { useEffect } from 'react'
import { EnterFullScreenIcon, GitHubLogoIcon } from '@radix-ui/react-icons'
@@ -15,16 +15,13 @@ import { Button } from '@/components/ui/button'
import { useTheme } from '@/components/darkmode-toggle/theme-provider'
import { EditorExample } from './editor-example'
+import { useExampleUrlState } from './url-state'
+
+function ExampleSelect() {
+ const { example, setExample } = useExampleUrlState()
-function ExampleSelect({
- value,
- onChange
-}: {
- value: string
- onChange: (v: string) => void
-}) {
return (
-