Skip to content

Commit 3c25247

Browse files
committed
fixed bug Filter is deselected sometimes #71
1 parent c571bc3 commit 3c25247

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

src/components/RangeFilter.tsx

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
import React, { useEffect, useState } from "react";
1313
import { useData } from "../context/data";
1414
import { isEqual } from "lodash";
15+
import { react } from "plotly.js";
1516

1617
interface RangeValue {
1718
lower: number;
@@ -23,12 +24,8 @@ const RangeFilter: React.FC = () => {
2324
const { filterValues, setFilterValues, inventoryStats } = useData();
2425

2526
// define the local radius and height state
26-
const [radius, setRadius] = useState<RangeValue | undefined>(
27-
filterValues?.radius
28-
);
29-
const [height, setHeight] = useState<RangeValue | undefined>(
30-
filterValues?.height
31-
);
27+
const [radius, setRadius] = useState<RangeValue | undefined>(undefined);
28+
const [height, setHeight] = useState<RangeValue | undefined>(undefined);
3229

3330
// use effect to set the filter to current filter
3431
useEffect(() => {
@@ -41,11 +38,7 @@ const RangeFilter: React.FC = () => {
4138
if (!height && !!filterValues) {
4239
setHeight({ ...filterValues.height });
4340
}
44-
}, [inventoryStats, radius, height]);
45-
46-
// console.log("filterValues:", filterValues);
47-
// console.log("radius", radius);
48-
// console.log("height", height);
41+
}, [inventoryStats, radius, height, filterValues]);
4942

5043
return (
5144
<IonList>
@@ -63,12 +56,6 @@ const RangeFilter: React.FC = () => {
6356
onIonKnobMoveEnd={(e) =>
6457
e.detail.value ? setHeight(e.detail.value as RangeValue) : null
6558
}
66-
// onIonChange={({ detail }) => {
67-
// if (detail.value) {
68-
// // console.log("e.detail.value:", Object(detail.value));
69-
// setHeight(detail.value as RangeValue);
70-
// }
71-
// }}
7259
pinFormatter={(value: number) => `${value.toFixed(0)}m`}
7360
class="ion-no-padding"
7461
disabled={!height}
@@ -85,7 +72,10 @@ const RangeFilter: React.FC = () => {
8572
<IonLabel position="stacked">Radius</IonLabel>
8673
<IonRange
8774
dualKnobs={true}
88-
value={radius}
75+
value={{
76+
lower: radius?.lower! * 100,
77+
upper: radius?.upper! * 100,
78+
}}
8979
pin={true}
9080
min={(inventoryStats?.data?.radiusMin as number) * 100}
9181
max={(inventoryStats?.data?.radiusMax as number) * 100}
@@ -99,7 +89,7 @@ const RangeFilter: React.FC = () => {
9989
})
10090
: null
10191
}
102-
// disabled={!radius}
92+
disabled={!radius}
10393
>
10494
<IonLabel color="medium" slot="start">
10595
{((inventoryStats?.data?.radiusMin as number) * 100).toFixed(0)}

0 commit comments

Comments
 (0)