Untitled Document
Untitled Document
—--------------------------------------------
interface SelectInputProps {
label: string;
options: string[];
value: string;
onChange: (value: string) => void;
}
import {
useSectors,
useSubsectors,
useIndicators,
useCountries,
useYears,
useRanks,
} from "../useApi";
import { useStore } from "../store";
switch (type) {
case "sector":
options = sectors || [sector];
value = sector;
onChange = setSector;
break;
case "subsector":
options = subsectors || [subsector];
value = subsector;
onChange = setSubsector;
break;
case "indicator":
options = indicators || [
indicator,
];
value = indicator;
onChange = setIndicator;
break;
case "country":
options = countries || [country];
value = country;
onChange = setCountry;
break;
case "year":
options = years || [year];
value = year;
onChange = setYear;
break;
}
useEffect(() => {
if (options.length > 0 && !options.includes(value)) {
onChange(options[0]);
}
}, [options, value, onChange]);
return (
<div className="mb-4">
<label className="block text-white">{label}</label>
<select
value={value}
onChange={(e) => onChange(e.target.value)}
className="mt-1 block w-full bg-gray-700 text-white border border-gray-600 rounded-md
shadow-sm focus:border-blue-500 focus:ring focus:ring-blue-500 focus:ring-opacity-50"
>
{options.map((option) => (
<option key={option} value={option}>
{option}
</option>
))}
</select>
</div>
);
};
return (
<div className="mb-4">
<label className="block text-white">{label}</label>
<input
type="range"
min={min}
max={max}
value={rank}
onChange={(e) => setRank(Number(e.target.value))}
className="mt-1 block w-full"
/>
<span className="block text-center text-white">{rank}</span>
</div>
);
};
—-------------------
import {create} from 'zustand';
interface AppState {
sector: string;
subsector: string;
indicator: string;
country: string;
year: string;
rank: number;
setSector: (sector: string) => void;
setSubsector: (subsector: string) => void;
setIndicator: (indicator: string) => void;
setCountry: (country: string) => void;
setYear: (year: string) => void;
setRank: (rank: number) => void;
}