Apply Color By metric change instantly without data re-fetch
The metric dropdown only updated form state, requiring "Apply Filters" to take effect — which re-fetched identical data and remounted the Map, making the result look unchanged. Now the Select's onValueChange immediately propagates the metric to queryParameters, so the Map re-renders in-place with the new color scheme, legend, and hex values.
This commit is contained in:
parent
5e2c5923f6
commit
e2247be700
2 changed files with 13 additions and 3 deletions
|
|
@ -7,7 +7,7 @@ import AlertError from './components/AlertError';
|
||||||
import LoginModal from './components/LoginModal';
|
import LoginModal from './components/LoginModal';
|
||||||
import AuthCallback from './components/AuthCallback';
|
import AuthCallback from './components/AuthCallback';
|
||||||
import { Map } from './components/Map';
|
import { Map } from './components/Map';
|
||||||
import { FilterPanel, type ParameterValues, DEFAULT_FILTER_VALUES } from './components/FilterPanel';
|
import { FilterPanel, type ParameterValues, DEFAULT_FILTER_VALUES, Metric } from './components/FilterPanel';
|
||||||
import { Header } from './components/Header';
|
import { Header } from './components/Header';
|
||||||
import { StatsBar, type ViewMode } from './components/StatsBar';
|
import { StatsBar, type ViewMode } from './components/StatsBar';
|
||||||
import { ListView } from './components/ListView';
|
import { ListView } from './components/ListView';
|
||||||
|
|
@ -162,6 +162,10 @@ function App() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleMetricChange = (metric: Metric) => {
|
||||||
|
setQueryParameters(prev => prev ? { ...prev, metric } : null);
|
||||||
|
};
|
||||||
|
|
||||||
const handlePropertyClick = (property: PropertyProperties, _coordinates: [number, number]) => {
|
const handlePropertyClick = (property: PropertyProperties, _coordinates: [number, number]) => {
|
||||||
setHighlightedProperty(property.url);
|
setHighlightedProperty(property.url);
|
||||||
// Optionally: pan map to coordinates
|
// Optionally: pan map to coordinates
|
||||||
|
|
@ -254,6 +258,7 @@ function App() {
|
||||||
<div className="hidden md:block w-64 shrink-0 h-full overflow-hidden">
|
<div className="hidden md:block w-64 shrink-0 h-full overflow-hidden">
|
||||||
<FilterPanel
|
<FilterPanel
|
||||||
onSubmit={onSubmit}
|
onSubmit={onSubmit}
|
||||||
|
onMetricChange={handleMetricChange}
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
listingCount={listingData?.features.length}
|
listingCount={listingData?.features.length}
|
||||||
/>
|
/>
|
||||||
|
|
@ -270,6 +275,7 @@ function App() {
|
||||||
<SheetContent side="left" className="w-80 p-0">
|
<SheetContent side="left" className="w-80 p-0">
|
||||||
<FilterPanel
|
<FilterPanel
|
||||||
onSubmit={onSubmit}
|
onSubmit={onSubmit}
|
||||||
|
onMetricChange={handleMetricChange}
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
listingCount={listingData?.features.length}
|
listingCount={listingData?.features.length}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,7 @@ export interface ParameterValues {
|
||||||
|
|
||||||
interface FilterPanelProps {
|
interface FilterPanelProps {
|
||||||
onSubmit: (action: 'fetch-data' | 'visualize', fromValues: ParameterValues) => void;
|
onSubmit: (action: 'fetch-data' | 'visualize', fromValues: ParameterValues) => void;
|
||||||
|
onMetricChange?: (metric: Metric) => void;
|
||||||
isLoading?: boolean;
|
isLoading?: boolean;
|
||||||
listingCount?: number;
|
listingCount?: number;
|
||||||
}
|
}
|
||||||
|
|
@ -89,7 +90,7 @@ const formSchema = z.object({
|
||||||
|
|
||||||
type FormValues = z.infer<typeof formSchema>;
|
type FormValues = z.infer<typeof formSchema>;
|
||||||
|
|
||||||
export function FilterPanel({ onSubmit, isLoading, listingCount }: FilterPanelProps) {
|
export function FilterPanel({ onSubmit, onMetricChange, isLoading, listingCount }: FilterPanelProps) {
|
||||||
const [availableFromRawInput, setAvailableFromRawInput] = useState("now");
|
const [availableFromRawInput, setAvailableFromRawInput] = useState("now");
|
||||||
const [selectedFurnishTypes, setSelectedFurnishTypes] = useState<FurnishType[]>([]);
|
const [selectedFurnishTypes, setSelectedFurnishTypes] = useState<FurnishType[]>([]);
|
||||||
|
|
||||||
|
|
@ -202,7 +203,10 @@ export function FilterPanel({ onSubmit, isLoading, listingCount }: FilterPanelPr
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel className="text-xs">Color by</FormLabel>
|
<FormLabel className="text-xs">Color by</FormLabel>
|
||||||
<Select onValueChange={field.onChange} defaultValue={field.value}>
|
<Select onValueChange={(value) => {
|
||||||
|
field.onChange(value);
|
||||||
|
onMetricChange?.(value as Metric);
|
||||||
|
}} defaultValue={field.value}>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<SelectTrigger className="h-8 text-sm">
|
<SelectTrigger className="h-8 text-sm">
|
||||||
<SelectValue placeholder="Metric" />
|
<SelectValue placeholder="Metric" />
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue