File tree Expand file tree Collapse file tree 3 files changed +48
-7
lines changed
Expand file tree Collapse file tree 3 files changed +48
-7
lines changed Original file line number Diff line number Diff line change 11import { Box } from "@chakra-ui/react" ;
2- import { useState } from "react" ;
2+ import { useEffect , useState } from "react" ;
33import "./app.css" ;
44import Header from "./components/header" ;
55import { Map } from "./components/map" ;
@@ -9,7 +9,26 @@ import { Panel } from "./components/panel";
99import { Toaster } from "./components/ui/toaster" ;
1010
1111function App ( ) {
12- const [ href , setHref ] = useState ( "" ) ;
12+ const [ href , setHref ] = useState (
13+ new URLSearchParams ( location . search ) . get ( "href" ) ?? ""
14+ ) ;
15+
16+ useEffect ( ( ) => {
17+ if ( new URLSearchParams ( location . search ) . get ( "href" ) != href ) {
18+ history . pushState ( null , "" , "?href=" + href ) ;
19+ }
20+ } , [ href ] ) ;
21+
22+ useEffect ( ( ) => {
23+ function handlePopState ( ) {
24+ setHref ( new URLSearchParams ( location . search ) . get ( "href" ) ?? "" ) ;
25+ }
26+
27+ window . addEventListener ( "popstate" , handlePopState ) ;
28+ return ( ) => {
29+ window . removeEventListener ( "popstate" , handlePopState ) ;
30+ } ;
31+ } , [ ] ) ;
1332
1433 return (
1534 < LayersProvider >
@@ -18,7 +37,7 @@ function App() {
1837 </ Box >
1938 < Box zIndex = { 1 } >
2039 < Overlay >
21- < Header setHref = { setHref } > </ Header >
40+ < Header href = { href } setHref = { setHref } > </ Header >
2241 < Panel href = { href } > </ Panel >
2342 </ Overlay >
2443 </ Box >
Original file line number Diff line number Diff line change 66 Menu ,
77 Portal ,
88} from "@chakra-ui/react" ;
9- import { type Dispatch , type SetStateAction } from "react" ;
9+ import { useEffect , useState , type Dispatch , type SetStateAction } from "react" ;
1010import { LuSearch } from "react-icons/lu" ;
1111
1212const EXAMPLES = [
@@ -22,14 +22,36 @@ const EXAMPLES = [
2222] ;
2323
2424export default function Header ( {
25+ href,
2526 setHref,
2627} : {
28+ href : string ;
2729 setHref : Dispatch < SetStateAction < string > > ;
2830} ) {
31+ const [ value , setValue ] = useState ( href ) ;
32+
33+ useEffect ( ( ) => {
34+ setValue ( href ) ;
35+ } , [ href ] ) ;
36+
2937 return (
3038 < HStack py = { 4 } pointerEvents = { "auto" } >
31- < InputGroup w = "full" startElement = { < LuSearch > </ LuSearch > } >
32- < Input flex = { 1 } variant = { "subtle" } rounded = { 4 } > </ Input >
39+ < InputGroup
40+ w = "full"
41+ startElement = { < LuSearch > </ LuSearch > }
42+ as = { "form" }
43+ onSubmit = { ( e ) => {
44+ e . preventDefault ( ) ;
45+ setHref ( value ) ;
46+ } }
47+ >
48+ < Input
49+ flex = { 1 }
50+ variant = { "subtle" }
51+ rounded = { 4 }
52+ value = { value }
53+ onChange = { ( e ) => setValue ( e . currentTarget . value ) }
54+ > </ Input >
3355 </ InputGroup >
3456 < Menu . Root onSelect = { ( details ) => setHref ( details . value ) } >
3557 < Menu . Trigger asChild >
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ export function RawJsonDialogButton({
2323 < Dialog . Root scrollBehavior = { "inside" } size = { "xl" } >
2424 < Dialog . Trigger >
2525 < Tooltip content = "Show raw JSON in a dialog" >
26- < IconButton { ...rest } >
26+ < IconButton { ...rest } as = { "div" } >
2727 < LuSearchCode > </ LuSearchCode >
2828 </ IconButton >
2929 </ Tooltip >
You can’t perform that action at this time.
0 commit comments