Skip to content

Commit de17ca8

Browse files
committed
feat(weather): enhance options modal with loading state and reduce input delay
1 parent fa1d8d2 commit de17ca8

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/layouts/weather/components/options-modal.component.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ export function WeatherOptionsModal({ onClose, show }: WeatherOptionsModalProps)
1515

1616
const [inputValue, setInputValue] = useState<string | null>('')
1717

18-
const { data: relatedCities, isSuccess } = useGetRelatedCities(inputValue || '')
18+
const {
19+
data: relatedCities,
20+
isSuccess,
21+
isLoading,
22+
} = useGetRelatedCities(inputValue || '')
1923

2024
const handleInputChange = (value: string) => {
2125
if (value === '') {
@@ -26,7 +30,7 @@ export function WeatherOptionsModal({ onClose, show }: WeatherOptionsModalProps)
2630
// delay the request to prevent too many requests
2731
setTimeout(() => {
2832
setInputValue(value)
29-
}, 2000) // 2 seconds
33+
}, 1000) // 1 seconds
3034
}
3135

3236
function handleSelect(selected: string) {
@@ -94,6 +98,11 @@ export function WeatherOptionsModal({ onClose, show }: WeatherOptionsModalProps)
9498
</div>
9599
)}
96100
</div>
101+
{isLoading && (
102+
<div className="flex items-center justify-center p-2">
103+
<div className="w-6 h-6 ease-linear border-4 border-t-4 border-gray-200 rounded-full loader"></div>
104+
</div>
105+
)}
97106
{isSuccess && relatedCities && relatedCities.length > 0 && (
98107
<div className="p-2">
99108
{relatedCities.map((city) => (

0 commit comments

Comments
 (0)