Skip to content

Commit

Permalink
Dashboard: disable subsections filter to keep map zoom
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannaPeanut committed Dec 8, 2023
1 parent b694b78 commit d0fd423
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/pages/[projectSlug]/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BlitzPage, Routes, useParam, useRouterQuery } from "@blitzjs/next"
import { useQuery } from "@blitzjs/rpc"
import { Suspense } from "react"
import { Suspense, useEffect, useState } from "react"
import { MapProvider } from "react-map-gl"
import { CalenderDashboard } from "src/calendar-entries/components"
import { SuperAdminLogData } from "src/core/components/AdminBox/SuperAdminLogData"
Expand Down Expand Up @@ -31,15 +31,19 @@ export const ProjectDashboardWithQuery = () => {
refetchOnWindowFocus: false,
},
)

// We use the URL param `operator` to filter the UI
// Docs: https://blitzjs.com/docs/route-params-query#use-router-query
const params = useRouterQuery()
const filteredSubsections = params.operator
? subsections.filter(
(sec) => typeof params.operator === "string" && sec.operator?.slug === params.operator,
)
: subsections
const [filteredSubsections, setFilteredSubsections] = useState(subsections)

useEffect(() => {
const newFilteredSubsections = params.operator
? subsections.filter(
(sec) => typeof params.operator === "string" && sec.operator?.slug === params.operator,
)
: subsections
setFilteredSubsections(newFilteredSubsections)
}, [params.operator, subsections])

if (!subsections.length) {
return (
Expand Down Expand Up @@ -81,6 +85,7 @@ export const ProjectDashboardWithQuery = () => {
)}

<OperatorFilterDropdown />

<MapProvider>
{Boolean(filteredSubsections.length) ? (
<ProjectMap subsections={filteredSubsections} />
Expand Down

0 comments on commit d0fd423

Please sign in to comment.