| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- 'use client';
- import { useState, useEffect, useMemo } from 'react';
- import { Radio } from 'lucide-react';
- import { useLanguage } from '@/lib/i18n/LanguageContext';
- import SlotFilterBar, { LOCATIONS } from '@/components/slots/SlotFilterBar';
- import SlotGrid from '@/components/slots/SlotGrid';
- import { SlotSnapshot } from '@/types';
- import { statsService } from '@/lib/services';
- export default function SlotDashboardPage() {
- const { t } = useLanguage();
- const [loading, setLoading] = useState(true);
- const [snapshots, setSnapshots] = useState<SlotSnapshot[]>([]);
- const [selectedCountryCode, setSelectedCountryCode] = useState('IE');
- const [selectedCity, setSelectedCity] = useState('Dublin');
- const currentCities = useMemo(() => {
- return LOCATIONS.find((l) => l.code === selectedCountryCode)?.cities || [];
- }, [selectedCountryCode]);
- const handleCountryChange = (code: string) => {
- setSelectedCountryCode(code);
- const countryData = LOCATIONS.find((l) => l.code === code);
- if (countryData && countryData.cities.length > 0) {
- setSelectedCity(countryData.cities[0]);
- } else {
- setSelectedCity('');
- }
- };
- const fetchDashboard = async () => {
- setLoading(true);
- try {
- const res = await statsService.getSlotsOverview(selectedCity);
- const data = res?.data || [];
- // 过滤当前城市
- const filtered = data.filter((i: SlotSnapshot) => i.city === selectedCity);
- // 排序: Available > Waitlist > None
- filtered.sort((a: SlotSnapshot, b: SlotSnapshot) => {
- const score = (s: string) => (s === 'Available' ? 3 : s === 'Waitlist' ? 2 : 1);
- return score(b.availability_status) - score(a.availability_status);
- });
- setSnapshots(filtered);
- } catch (e) {
- console.warn('Fetch slots failed', e);
- setSnapshots([]);
- } finally {
- setLoading(false);
- }
- };
- useEffect(() => {
- if (selectedCity) {
- fetchDashboard();
- }
- }, [selectedCity]);
- return (
- <div className="min-h-screen bg-neutral-100 py-6 px-4 sm:px-6 md:py-10 md:px-8 space-y-6 max-w-7xl mx-auto">
- {/* 顶部雷达标头卡片 */}
- <div className="bg-neutral-100 border-2 border-black p-6 sm:p-8 shadow-[6px_6px_0px_#000] text-black">
- <div className="flex flex-wrap items-center justify-between gap-2 border-b-2 border-black pb-3 mb-4 font-mono text-xs font-bold select-none">
- <div className="flex items-center gap-2">
- <span className="w-3 h-3 bg-amber-300 border border-black inline-block animate-pulse" />
- <span className="tracking-widest uppercase">[ {t('slots.title')} ]</span>
- </div>
- <div className="text-neutral-500 font-mono flex items-center gap-1.5">
- <Radio size={14} className="text-black animate-spin" />
- <span>{t('slots.updated_at')}</span>
- </div>
- </div>
- <div className="max-w-3xl space-y-2">
- <h1 className="text-2xl sm:text-3xl font-black tracking-tight text-black uppercase">
- {t('slots.title') || '实时使馆名额雷达监控'}
- </h1>
- <p className="text-xs sm:text-sm text-neutral-600 font-mono leading-relaxed">
- {t('slots.subtitle') || '查看预约名额记录,并留意数据更新时间。'}
- </p>
- </div>
- </div>
- {/* Filter Bar 组件 */}
- <SlotFilterBar
- selectedCountryCode={selectedCountryCode}
- selectedCity={selectedCity}
- currentCities={currentCities}
- onCountryChange={handleCountryChange}
- onCityChange={setSelectedCity}
- onRefresh={fetchDashboard}
- loading={loading}
- />
- {/* Grid List 组件 */}
- <SlotGrid
- loading={loading}
- snapshots={snapshots}
- selectedCity={selectedCity}
- />
- </div>
- );
- }
|