Skip to content

Commit

Permalink
feat: save network in query
Browse files Browse the repository at this point in the history
  • Loading branch information
lance10030 committed Aug 8, 2024
1 parent 16cf4aa commit 088bbcf
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/components/NavMenusSection/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from "react";
import { useCallback, useEffect, useState } from "react";
import {
Bars3Icon,
BookOpenIcon,
Expand All @@ -12,19 +12,37 @@ import { Button } from "../Button";
import { NavItem } from "./NavItem";
import { useSnapshot } from "valtio";
import { Network, setNetwork } from "@/store/globalStore";
import { usePathname, useRouter, useSearchParams } from "next/navigation";

const resolveApiUrl = () =>
// TODO
"http://144.76.97.175:8080/swagger/index.html";

export const NavMenusSection: React.FC = () => {
const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false);


const router = useRouter()
const pathname = usePathname()
const searchParams = useSearchParams()
const createQueryString = useCallback(
(value: string) => {
const params = new URLSearchParams(searchParams.toString())
params.set('n', value)
return params.toString()
},
[searchParams]
)
const handleSelectNetwork = (e: Network) => {
setNetwork(e)
router.push(pathname + '?' + createQueryString(e))
}

useEffect(() => {
const n = searchParams.get('n')
if (n) {
setNetwork(n as Network)
}
}, [searchParams])

return (
<div className="relative mx-auto flex max-w-screen-xl flex-wrap items-center justify-between p-4">
<Button
Expand Down

0 comments on commit 088bbcf

Please sign in to comment.