Refactor shared data source selection for dashboard and map

This commit is contained in:
2026-04-21 17:56:59 +02:00
parent e244a85291
commit 86a7336ac0
5 changed files with 33 additions and 4 deletions

View File

@@ -17,6 +17,7 @@ import { TopCountriesBarChart } from "../components/TopCountriesBarChart";
import { TopCountriesPieChart } from "../components/TopCountriesPieChart";
import { useCommonSectionStyles } from "../components/commonStyles";
import { useDashboardCountryData } from "../hooks/useDashboardCountryData";
import { getDataSource } from "../utils/queryUtils";
import type { BanOriginFilter, TimeRange } from "../types/ban";
@@ -71,7 +72,7 @@ export function DashboardPage(): React.JSX.Element {
const [timeRange, setTimeRange] = useState<TimeRange>("24h");
const [originFilter, setOriginFilter] = useState<BanOriginFilter>("all");
const source = timeRange === "24h" ? "fail2ban" : "archive";
const source = getDataSource(timeRange);
const { countries, countryNames, isLoading: countryLoading, error: countryError, reload: reloadCountry } =
useDashboardCountryData(timeRange, originFilter, source);

View File

@@ -25,6 +25,7 @@ import { WorldMap } from "../components/WorldMap";
import { useMapData } from "../hooks/useMapData";
import { useMapColorThresholds } from "../hooks/useMapColorThresholds";
import { MapBansTable } from "./map/MapBansTable";
import { getDataSource } from "../utils/queryUtils";
import type { TimeRange } from "../types/map";
import type { BanOriginFilter } from "../types/ban";
@@ -96,7 +97,7 @@ export function MapPage(): React.JSX.Element {
const [page, setPage] = useState<number>(1);
const [pageSize, setPageSize] = useState<number>(100);
const source = range === "24h" ? "fail2ban" : "archive";
const source = getDataSource(range);
const { countries, countryNames, bans, total, loading, error, refresh } =
useMapData(range, originFilter, source, selectedCountry ?? undefined);