Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Reset Selection button to district filter #148

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
10 changes: 10 additions & 0 deletions app/components/ClearFilter/ClearFilterButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// import { ClearFilterBtnProps, ClearFilterBtn } from ".";

// export interface ClearFileringBtnProps
// extends Pick<ClearFilterBtnProps, "onClear"> {
// path: string | null;
// }

// export function ClearFilteringBtn({path} :ClearFileringBtnProps) {
// return <ClearFilterBtn />
// }
Empty file.
34 changes: 34 additions & 0 deletions app/components/ClearFilter/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { useState } from "react";
import { Button } from "@nycplanning/streetscape";
import { useNavigate } from "@remix-run/react";

export interface ClearFilterBtnProps {
onClear: () => void;
buttonLabel?: string;
}

export function ClearFilterBtn({
onClear,
buttonLabel = "Reset Selections",
}: ClearFilterBtnProps) {
const [isClearing, setIsClearing] = useState(false);
const navigate = useNavigate();

const handleClear = async () => {
setIsClearing(true);
try {
await onClear();
navigate("/");
} catch (error) {
console.error("Error clearing selections:", error);
} finally {
setIsClearing(false);
}
};

return (
<Button width="full" mt={4} onClick={handleClear} isDisabled={isClearing}>
{buttonLabel}
</Button>
);
}
11 changes: 7 additions & 4 deletions app/components/atlas.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,20 @@ import type { MapView, MapViewState } from "@deck.gl/core";
export const MAX_ZOOM = 20;
export const MIN_ZOOM = 10;

const INITIAL_VIEW_STATE = {
export const INITIAL_VIEW_STATE = {
longitude: -74.0008,
latitude: 40.7018,
zoom: 10,
bearing: 0,
pitch: 0,
};

export function Atlas() {
interface AtlasProps {
viewState: MapViewState;
setViewState: React.Dispatch<React.SetStateAction<MapViewState>>;
}

export function Atlas({ viewState, setViewState }: AtlasProps) {
const capitalProjectsLayer = useCapitalProjectsLayer();
const capitalProjectBudgetedGeoJsonLayer =
useCapitalProjectBudgetedGeoJsonLayer();
Expand All @@ -52,8 +57,6 @@ export function Atlas() {
style: widgetStyles,
});

const [viewState, setViewState] = useState<MapViewState>(INITIAL_VIEW_STATE);

return (
<DeckGL<MapView>
viewState={viewState}
Expand Down
1 change: 0 additions & 1 deletion app/extensions/FlyToGeoJsonExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
} from "@deck.gl/core";
import { bbox } from "@turf/bbox";
import { Geometry } from "geojson";
import { MIN_ZOOM, MAX_ZOOM } from "../components/atlas.client";

export class FlyToGeoJsonExtension extends LayerExtension {
updateState(
Expand Down
25 changes: 22 additions & 3 deletions app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
useRouteError,
useSearchParams,
} from "@remix-run/react";
import { Atlas } from "./components/atlas.client";
import { Atlas, INITIAL_VIEW_STATE } from "./components/atlas.client";
import { ClientOnly } from "remix-utils/client-only";
import { Overlay } from "./components/Overlay";
import {
Expand All @@ -43,7 +43,7 @@ import {
} from "./components/GoToDistrictBtn";
import { GoToCommunityDistrictBtn } from "./components/GoToDistrictBtn/GoToCommunityDistrictBtn";
import { WelcomePanel } from "./components/WelcomePanel";
import { useEffect } from "react";
import { useEffect, useState } from "react";
import {
analytics,
initializeMatomoTagManager,
Expand All @@ -56,6 +56,8 @@ import {
DistrictType,
SearchParamChanges,
} from "./utils/types";
import { ClearFilterBtn } from "./components/ClearFilter";
import { FlyToInterpolator, MapViewState } from "@deck.gl/core";

export const links: LinksFunction = () => {
return [
Expand Down Expand Up @@ -156,6 +158,7 @@ export default function App() {
initializeMatomoTagManager("SmoWWpiD");
initFullStoryAnalytics();
}, []);
const [viewState, setViewState] = useState<MapViewState>(INITIAL_VIEW_STATE);
const navigate = useNavigate();
const { pathname } = useLocation();
const [searchParams, setSearchParams] = useSearchParams();
Expand Down Expand Up @@ -202,13 +205,28 @@ export default function App() {

const goToNextDistrict = goToDistrict(pathname);

const clearSelections = () => {
setSearchParams({});
updateSearchParams({
districtType: null,
boroughId: null,
districtId: null,
});

setViewState({
...INITIAL_VIEW_STATE,
transitionDuration: 2000,
transitionInterpolator: new FlyToInterpolator(),
});
};

return (
<Document>
<StreetscapeProvider>
<ClientOnly>
{() => (
<>
<Atlas />{" "}
<Atlas viewState={viewState} setViewState={setViewState} />{" "}
<Overlay>
<Flex
direction={"column"}
Expand Down Expand Up @@ -267,6 +285,7 @@ export default function App() {
)}
</FilterMenu>
<WelcomePanel />
<ClearFilterBtn onClear={clearSelections} />
</Flex>
<Flex
direction={{ base: "column-reverse", lg: "column" }}
Expand Down
Loading