Clean up
This commit is contained in:
parent
b94cf17d75
commit
0c6d207967
41 changed files with 1809 additions and 1204 deletions
|
|
@ -30,10 +30,7 @@ export interface AiFiltersContext {
|
|||
}
|
||||
|
||||
interface UseAiFiltersResult {
|
||||
fetchAiFilters: (
|
||||
query: string,
|
||||
context?: AiFiltersContext
|
||||
) => Promise<AiFiltersResult | null>;
|
||||
fetchAiFilters: (query: string, context?: AiFiltersContext) => Promise<AiFiltersResult | null>;
|
||||
loading: boolean;
|
||||
error: string | null;
|
||||
errorType: AiFilterErrorType | null;
|
||||
|
|
@ -47,7 +44,11 @@ function buildSummary(
|
|||
travelTimeFilters: AiTravelTimeFilter[],
|
||||
matchCount: number
|
||||
): string {
|
||||
const i18n = require('../i18n').default as { t: (key: string, opts?: Record<string, unknown>) => string };
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const i18n = require('../i18n').default as {
|
||||
t: (key: string, opts?: Record<string, unknown>) => string;
|
||||
};
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const { ts } = require('../i18n/server') as { ts: (v: string) => string };
|
||||
const parts: string[] = [];
|
||||
|
||||
|
|
@ -83,10 +84,7 @@ export function useAiFilters(): UseAiFiltersResult {
|
|||
const abortRef = useRef<AbortController | null>(null);
|
||||
|
||||
const fetchAiFilters = useCallback(
|
||||
async (
|
||||
query: string,
|
||||
context?: AiFiltersContext
|
||||
): Promise<AiFiltersResult | null> => {
|
||||
async (query: string, context?: AiFiltersContext): Promise<AiFiltersResult | null> => {
|
||||
abortRef.current?.abort();
|
||||
const controller = new AbortController();
|
||||
abortRef.current = controller;
|
||||
|
|
|
|||
|
|
@ -5,11 +5,9 @@ import { useState, useCallback } from 'react';
|
|||
* @param defaultCollapsed When true, groups start collapsed (tracks expanded groups).
|
||||
* When false (default), groups start expanded (tracks collapsed groups).
|
||||
*/
|
||||
export function useCollapsibleGroups(defaultCollapsed = false): [
|
||||
(name: string) => boolean,
|
||||
(name: string) => void,
|
||||
(name: string) => void,
|
||||
] {
|
||||
export function useCollapsibleGroups(
|
||||
defaultCollapsed = false
|
||||
): [(name: string) => boolean, (name: string) => void, (name: string) => void] {
|
||||
const [toggled, setToggled] = useState<Set<string>>(new Set());
|
||||
|
||||
const isExpanded = useCallback(
|
||||
|
|
|
|||
|
|
@ -134,11 +134,11 @@ export function useDeckLayers({
|
|||
? colorFeatureMeta.values.length
|
||||
: 0;
|
||||
|
||||
// --- Count ranges ---
|
||||
const countRange = useMemo(() => {
|
||||
if (data.length === 0) return { min: 0, max: 1 };
|
||||
if (data.length === 0) return { min: 0, max: 1, total: 0 };
|
||||
let min = Infinity;
|
||||
let max = -Infinity;
|
||||
let total = 0;
|
||||
for (const d of data) {
|
||||
if (viewportBounds) {
|
||||
if (
|
||||
|
|
@ -152,19 +152,21 @@ export function useDeckLayers({
|
|||
const c = d.count as number;
|
||||
if (c < min) min = c;
|
||||
if (c > max) max = c;
|
||||
total += c;
|
||||
}
|
||||
if (min === Infinity) return { min: 0, max: 1 };
|
||||
if (min === max) return { min, max: min + 1 };
|
||||
return { min, max };
|
||||
if (min === Infinity) return { min: 0, max: 1, total: 0 };
|
||||
if (min === max) return { min, max: min + 1, total };
|
||||
return { min, max, total };
|
||||
}, [data, viewportBounds]);
|
||||
|
||||
const countRangeRef = useRef(countRange);
|
||||
countRangeRef.current = countRange;
|
||||
|
||||
const postcodeCountRange = useMemo(() => {
|
||||
if (postcodeData.length === 0) return { min: 0, max: 1 };
|
||||
if (postcodeData.length === 0) return { min: 0, max: 1, total: 0 };
|
||||
let min = Infinity;
|
||||
let max = -Infinity;
|
||||
let total = 0;
|
||||
for (const d of postcodeData) {
|
||||
if (viewportBounds) {
|
||||
const [lng, lat] = d.properties.centroid as [number, number];
|
||||
|
|
@ -179,10 +181,11 @@ export function useDeckLayers({
|
|||
const c = d.properties.count;
|
||||
if (c < min) min = c;
|
||||
if (c > max) max = c;
|
||||
total += c;
|
||||
}
|
||||
if (min === Infinity) return { min: 0, max: 1 };
|
||||
if (min === max) return { min, max: min + 1 };
|
||||
return { min, max };
|
||||
if (min === Infinity) return { min: 0, max: 1, total: 0 };
|
||||
if (min === max) return { min, max: min + 1, total };
|
||||
return { min, max, total };
|
||||
}, [postcodeData, viewportBounds]);
|
||||
|
||||
const postcodeCountRangeRef = useRef(postcodeCountRange);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue