Skip to content

Commit 456e487

Browse files
Toggle all hotspots from add hotspot modal
1 parent 786207c commit 456e487

File tree

3 files changed

+48
-13
lines changed

3 files changed

+48
-13
lines changed

frontend/modals/AddHotspot.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import useTripMutation from "hooks/useTripMutation";
1212
export default function AddHotspot() {
1313
const [query, setQuery] = React.useState("");
1414
const [selectedIndex, setSelectedIndex] = React.useState(0);
15-
const { open } = useModal();
16-
const { trip } = useTrip();
15+
const { open, close } = useModal();
16+
const { trip, showAllHotspots, setShowAllHotspots } = useTrip();
1717
const { hotspots } = useFetchHotspots(true);
1818

1919
const addHotspotMutation = useTripMutation<HotspotInput>({
@@ -87,6 +87,20 @@ export default function AddHotspot() {
8787
autoFocus
8888
onChange={(e: any) => setQuery(e.target.value)}
8989
/>
90+
{!showAllHotspots && (
91+
<p className="text-[12px] text-gray-700 -mt-3">
92+
<button
93+
type="button"
94+
className="text-sky-600 font-bold"
95+
onClick={() => {
96+
setShowAllHotspots(true);
97+
close();
98+
}}
99+
>
100+
Or view hotspot map
101+
</button>
102+
</p>
103+
)}
90104
<div className="flex flex-col gap-2">
91105
{!!slicedResults?.length && <p className="text-[13px] text-gray-600">Select a hotspot to add</p>}
92106
{slicedResults.map((it, index) => {

frontend/pages/[tripId]/index.tsx

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,21 @@ import NotFound from "components/NotFound";
1717

1818
export default function Trip() {
1919
const { open } = useModal();
20-
const [showAll, setShowAll] = React.useState(false);
21-
const [showSatellite, setShowSatellite] = React.useState(false);
22-
const { trip, canEdit, is404, setSelectedSpecies } = useTrip();
20+
const {
21+
trip,
22+
canEdit,
23+
is404,
24+
setSelectedSpecies,
25+
showAllHotspots,
26+
setShowAllHotspots,
27+
showSatellite,
28+
setShowSatellite,
29+
} = useTrip();
2330
const { user } = useUser();
2431
const [isAddingMarker, setIsAddingMarker] = React.useState(false);
2532

2633
const savedHotspots = trip?.hotspots || [];
27-
const { hotspots, hotspotLayer } = useFetchHotspots(showAll);
34+
const { hotspots, hotspotLayer } = useFetchHotspots(showAllHotspots);
2835

2936
const savedHotspotMarkers = savedHotspots.map((it) => ({
3037
lat: it.lat,
@@ -49,7 +56,7 @@ export default function Trip() {
4956

5057
React.useEffect(() => {
5158
if (tripIsLoaded && tripIsNew) {
52-
setShowAll(true);
59+
setShowAllHotspots(true);
5360
}
5461
}, [tripIsLoaded, tripIsNew]);
5562

@@ -68,9 +75,9 @@ export default function Trip() {
6875
<main className="flex h-[calc(100%-60px-55px)] relative">
6976
<div className="absolute top-4 right-4 sm:left-4 sm:right-auto flex flex-col gap-3 z-10">
7077
<MapButton
71-
onClick={() => setShowAll((prev) => !prev)}
72-
tooltip={showAll ? "Hide hotspots" : "Show hotspots"}
73-
active={showAll}
78+
onClick={() => setShowAllHotspots((prev) => !prev)}
79+
tooltip={showAllHotspots ? "Hide hotspots" : "Show hotspots"}
80+
active={showAllHotspots}
7481
>
7582
<Icon name="mapFlatPin" />
7683
</MapButton>
@@ -114,15 +121,15 @@ export default function Trip() {
114121
onHotspotClick={hotspotClick}
115122
markers={markers}
116123
customMarkers={customMarkers}
117-
hotspotLayer={showAll && hotspotLayer}
124+
hotspotLayer={showAllHotspots && hotspotLayer}
118125
bounds={trip.bounds}
119126
addingMarker={isAddingMarker}
120127
onDisableAddingMarker={() => setIsAddingMarker(false)}
121128
showSatellite={showSatellite}
122129
/>
123130
)}
124131
{isAddingMarker && (
125-
<div className="flex absolute top-0 left-1/2 bg-white text-gray-600 text-sm px-4 py-2 -translate-x-1/2 rounded-b-lg w-full max-w-xs z-10 text-center">
132+
<div className="flex absolute top-0 left-1/2 bg-white text-gray-600 text-sm px-4 py-2 -translate-x-1/2 rounded-b-lg w-full max-w-xs z-10 text-center justify-between">
126133
<div>
127134
Click anywhere on map to add marker
128135
<br />
@@ -137,7 +144,7 @@ export default function Trip() {
137144
enter coordinates
138145
</button>
139146
</div>
140-
<CloseButton onClick={() => setIsAddingMarker(false)} className="ml-auto" />
147+
<CloseButton onClick={() => setIsAddingMarker(false)} />
141148
</div>
142149
)}
143150
</div>

frontend/providers/trip.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,13 @@ type ContextT = {
2929
selectedMarkerId?: string;
3030
halo?: HaloT;
3131
dateRangeLabel: string;
32+
showAllHotspots: boolean;
33+
showSatellite: boolean;
3234
setSelectedSpecies: (species?: SelectedSpecies) => void;
3335
setSelectedMarkerId: (id?: string) => void;
3436
setHalo: (data?: HaloT) => void;
37+
setShowAllHotspots: (show: boolean | ((prev: boolean) => boolean)) => void;
38+
setShowSatellite: (show: boolean | ((prev: boolean) => boolean)) => void;
3539
refetch: () => void;
3640
};
3741

@@ -44,13 +48,17 @@ const initialState = {
4448
isOwner: false,
4549
is404: false,
4650
dateRangeLabel: "",
51+
showAllHotspots: false,
52+
showSatellite: false,
4753
};
4854

4955
export const TripContext = React.createContext<ContextT>({
5056
...initialState,
5157
setSelectedSpecies: () => {},
5258
setSelectedMarkerId: () => {},
5359
setHalo: () => {},
60+
setShowAllHotspots: () => {},
61+
setShowSatellite: () => {},
5462
refetch: () => {},
5563
});
5664

@@ -93,6 +101,8 @@ const TripProvider = ({ children }: Props) => {
93101
const [selectedSpecies, setSelectedSpecies] = React.useState<SelectedSpecies>();
94102
const [selectedMarkerId, setSelectedMarkerId] = React.useState<string>();
95103
const [halo, setHalo] = React.useState<HaloT>(); // Used to highlight selected geoJSON feature
104+
const [showAllHotspots, setShowAllHotspots] = React.useState(false);
105+
const [showSatellite, setShowSatellite] = React.useState(false);
96106
const is404 = !!auth?.currentUser && !!id && !trip && !isLoading;
97107

98108
const dateRangeLabel =
@@ -112,6 +122,8 @@ const TripProvider = ({ children }: Props) => {
112122
setSelectedSpecies,
113123
setSelectedMarkerId,
114124
setHalo,
125+
setShowAllHotspots,
126+
setShowSatellite,
115127
refetch,
116128
invites: invites || null,
117129
canEdit,
@@ -124,6 +136,8 @@ const TripProvider = ({ children }: Props) => {
124136
selectedMarkerId,
125137
halo,
126138
dateRangeLabel,
139+
showAllHotspots,
140+
showSatellite,
127141
}}
128142
>
129143
{children}

0 commit comments

Comments
 (0)