's'
This commit is contained in:
@@ -10,7 +10,9 @@ import CityModal from "../components/CityModal";
|
||||
import Footer from "@/app/components/Footer";
|
||||
import { cities, type City } from "../data/cities";
|
||||
import { HOME_CONFIG } from "@/config";
|
||||
import { useDevDebug } from "@/app/context/DevDebugContext";
|
||||
import { apiFetch } from "@/app/lib/api-client";
|
||||
import { cityWeatherKey, type CityWeatherMap } from "@/app/lib/city-weather";
|
||||
import { mediaUrl } from "@/app/lib/media";
|
||||
|
||||
const {
|
||||
@@ -177,6 +179,7 @@ export default function Home() {
|
||||
const [sortBy, setSortBy] = useState("score");
|
||||
const [cityModal, setCityModal] = useState<City | null>(null);
|
||||
const [liveCities, setLiveCities] = useState<City[]>(cities);
|
||||
const [cityWeather, setCityWeather] = useState<CityWeatherMap>({});
|
||||
const [homeContent, setHomeContent] = useState<ContentItem[]>(FALLBACK_HOME_CONTENT);
|
||||
const [homeStats, setHomeStats] = useState<HomeStats>(fallbackStats);
|
||||
const [memberPhotos, setMemberPhotos] = useState(fallbackMemberPhotos);
|
||||
@@ -184,6 +187,7 @@ export default function Home() {
|
||||
const [communityStats, setCommunityStats] = useState(fallbackCommunityStats);
|
||||
const locale = useLocale();
|
||||
const { t } = useTranslation("home");
|
||||
const { isFeatureVisible } = useDevDebug();
|
||||
|
||||
useEffect(() => {
|
||||
apiFetch<{ ok: boolean; items: City[] }>("/api/cities")
|
||||
@@ -193,6 +197,13 @@ export default function Home() {
|
||||
}
|
||||
})
|
||||
.catch(() => setLiveCities(cities));
|
||||
apiFetch<{ ok: boolean; items: CityWeatherMap }>("/api/weather/cities")
|
||||
.then((data) => {
|
||||
if (data.items && typeof data.items === "object") {
|
||||
setCityWeather(data.items);
|
||||
}
|
||||
})
|
||||
.catch(() => setCityWeather({}));
|
||||
apiFetch<{ ok: boolean; items: ContentItem[] }>("/api/content/home")
|
||||
.then((data) => {
|
||||
const items = (data.items || [])
|
||||
@@ -260,19 +271,22 @@ export default function Home() {
|
||||
return safetyOrder(b.safety) - safetyOrder(a.safety);
|
||||
case "nomads":
|
||||
return b.nomadsNow - a.nomadsNow;
|
||||
case "temperature":
|
||||
return b.temperature - a.temperature;
|
||||
case "temperature": {
|
||||
const tempA = cityWeather[cityWeatherKey(a)]?.temperature ?? a.temperature;
|
||||
const tempB = cityWeather[cityWeatherKey(b)]?.temperature ?? b.temperature;
|
||||
return tempB - tempA;
|
||||
}
|
||||
default:
|
||||
return b.overallScore - a.overallScore;
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}, [activeFilter, sortBy, liveCities]);
|
||||
}, [activeFilter, sortBy, liveCities, cityWeather]);
|
||||
|
||||
const homepageFeatureContent = useMemo(
|
||||
() => pickHomepageFeatureContent(homeContent),
|
||||
[homeContent]
|
||||
);
|
||||
const homepageFeatureContent = useMemo(() => {
|
||||
if (!isFeatureVisible("home.rightFeatureCards")) return [];
|
||||
return pickHomepageFeatureContent(homeContent);
|
||||
}, [homeContent, isFeatureVisible]);
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-[#fafafa] dark:bg-gray-950">
|
||||
@@ -442,6 +456,7 @@ export default function Home() {
|
||||
key={city.id}
|
||||
city={city}
|
||||
rank={i + 1}
|
||||
liveWeather={cityWeather[cityWeatherKey(city)] ?? null}
|
||||
onClick={() => setCityModal(city)}
|
||||
/>
|
||||
))}
|
||||
@@ -467,7 +482,7 @@ export default function Home() {
|
||||
isOpen={!!cityModal}
|
||||
onClose={() => setCityModal(null)}
|
||||
/>
|
||||
<Footer />
|
||||
<Footer minimal />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user