These work

This commit is contained in:
Andras Schmelczer 2026-02-11 21:32:33 +00:00
parent 3599803589
commit 1588c01b19
19 changed files with 260 additions and 201 deletions

View file

@ -95,7 +95,7 @@ export function useFilters({ initialFilters, features }: UseFiltersOptions) {
signal: dragAbortRef.current.signal,
})
.then((res) => res.json())
.then((json: ApiResponse) => setDragData(json.features || []))
.then((json: ApiResponse) => setDragData(json.features))
.catch((err) => logNonAbortError('Failed to fetch drag data', err));
},
[filters, features]

View file

@ -9,7 +9,7 @@ import type {
ApiResponse,
} from '../types';
import { buildFilterString, apiUrl, logNonAbortError, authHeaders } from '../lib/api';
import { POSTCODE_ZOOM_THRESHOLD } from '../lib/map-utils';
import { POSTCODE_ZOOM_THRESHOLD } from '../lib/consts';
import { COLOR_RANGE_LOW_PERCENTILE, COLOR_RANGE_HIGH_PERCENTILE } from '../lib/consts';
/** Return the p-th percentile (0100) from a sorted array via linear interpolation. */
@ -101,7 +101,7 @@ export function useMapData({
})
);
const json: { features: PostcodeFeature[] } = await res.json();
setPostcodeData(json.features || []);
setPostcodeData(json.features);
setRawData([]);
} else {
const params = new URLSearchParams({
@ -121,7 +121,7 @@ export function useMapData({
})
);
const json: ApiResponse = await res.json();
setRawData(json.features || []);
setRawData(json.features);
setPostcodeData([]);
}
} catch (err) {

View file

@ -51,25 +51,19 @@ export function useSavedSearches(userId: string | null) {
try {
const params = window.location.search.replace(/^\?/, '');
// Try to capture a screenshot via the screenshot endpoint
let screenshotBlob: Blob | null = null;
try {
const screenshotUrl = apiUrl('screenshot', new URLSearchParams(params));
const res = await fetch(screenshotUrl);
if (res.ok) {
screenshotBlob = await res.blob();
}
} catch {
// Screenshot is optional — save without it
// Capture a screenshot via the screenshot endpoint
const screenshotUrl = apiUrl('screenshot', new URLSearchParams(params));
const screenshotRes = await fetch(screenshotUrl);
if (!screenshotRes.ok) {
throw new Error(`Screenshot failed: ${screenshotRes.status} ${screenshotRes.statusText}`);
}
const screenshotBlob = await screenshotRes.blob();
const formData = new FormData();
formData.append('user', userId);
formData.append('name', name);
formData.append('params', params);
if (screenshotBlob) {
formData.append('screenshot', screenshotBlob, 'screenshot.png');
}
formData.append('screenshot', screenshotBlob, 'screenshot.png');
await pb.collection('saved_searches').create(formData);
await fetchSearches();