test/1114/app/routes/weather.tsx

55 lines
2.1 KiB
TypeScript
Raw Normal View History

2025-11-14 18:38:11 +08:00
import REACT, { use, useEffect } from 'react'
import { Loader2 } from 'lucide-react';
2025-11-14 18:51:33 +08:00
import { WeatherCard } from '@/components/weather/WeatherCard'
import { useWeatherStore } from '@/store/weatherStore'
2025-11-14 18:38:11 +08:00
import { toast } from 'sonner'
export function meta() {
return [
{ title: "天气查询页面" },
{ name: "description", content: "查询天气信息" }
]
}
export default function Weather() {
2025-11-14 18:51:33 +08:00
const { currentWeather, isLoading, error, setError } = useWeatherStore()
2025-11-14 18:38:11 +08:00
useEffect(() => {
if (error) {
toast.error(error)
2025-11-14 18:51:33 +08:00
setError("")
2025-11-14 18:38:11 +08:00
}
2025-11-14 18:51:33 +08:00
}, [error, setError])
2025-11-14 18:38:11 +08:00
return (
<div className="flex flex-col items-center justify-center h-screen">
<div className="flex flex-col items-center justify-center">
<header className="flex flex-col items-center justify-center">
<h1 className="text-4xl font-bold"></h1>
<p className="text-sm"></p>
</header>
{isLoading && !currentWeather && (
<div className="flex flex-col items-center justify-center">
<div className="flex flex-col items-center justify-center">
<div className='flex flex-col items-center justify-center'>
<div className="animate-spin rounded-full h-20 w-20 border-t-2 border-b-2 border-gray-900">
</div>
<div className="text-gray-900 text-lg font-bold">
<Loader2 className="h-10 w-10 animate-spin" />
</div>
</div>
<p className="text-gray-900 text-lg font-bold"> ...</p>
</div>
</div>
)}
{!isLoading || currentWeather ? (
<div className="flex flex-col items-center justify-center">
<WeatherCard />
</div>
) : null}
</div>
</div>
)
}