Compare commits
No commits in common. "39ac8592c3eb2a902485329554171d44eb2b288c" and "8c3bfc9b4a243f58dd70c5d3c63f0dc95bd73775" have entirely different histories.
39ac8592c3
...
8c3bfc9b4a
|
|
@ -14,7 +14,6 @@ export function WeatherSearchForm() {
|
|||
setCity(e.target.value);
|
||||
if (inputError) {
|
||||
setInputError('');
|
||||
};
|
||||
}
|
||||
|
||||
const handleFormSubmit = async (e: FormEvent<HTMLFormElement>) => {
|
||||
|
|
@ -34,18 +33,6 @@ export function WeatherSearchForm() {
|
|||
}
|
||||
await searchWeather(trimmedCity);
|
||||
|
||||
if (trimmedCity.length < 2) {
|
||||
setInputError('请输入至少2个字符');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!/^[a-zA-Z\s]+$/.test(trimmedCity)) {
|
||||
setInputError('请输入字母和空格');
|
||||
return;
|
||||
}
|
||||
await searchWeather(trimmedCity);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className='p-6 border-6 border-b-slate-200/50 '>
|
||||
<form onSubmit={handleFormSubmit} className="space-by-3">
|
||||
|
|
@ -67,16 +54,10 @@ export function WeatherSearchForm() {
|
|||
<AlertCircle className="inline w-4 h-4 text-red-500 mt-0.5" />
|
||||
<p className="text-red-500 text-xs">{inputError}</p>
|
||||
</div>
|
||||
|
||||
|
||||
)
|
||||
}
|
||||
|
||||
<div className='flex gap-2'>
|
||||
<Button type="submit" disabled={isLoading || !city.trim()} className="mt-4 w-full">
|
||||
|
||||
|
||||
|
||||
{isLoading ? <>
|
||||
<Loader2 className="animate-spin w-5 h-5 text-white" />
|
||||
<span>搜索中...</span>
|
||||
|
|
@ -85,22 +66,15 @@ export function WeatherSearchForm() {
|
|||
<span>搜索天气</span>
|
||||
</>)}
|
||||
</Button>
|
||||
|
||||
{currentWeather && (
|
||||
<Button type="button" variant="outline" onClick={refreshWeather} disabled={isLoading} className="mt-4 w-full" title='刷新数据'>
|
||||
<RefreshCw className={cn("w-5 h-5", isLoading && "animate-spin")} />
|
||||
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
|
||||
</form>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue