Files
geointel/frontend/src/hooks/useMapSelectionDataset.ts
T
JensandClaude Opus 5 596bbb0e8c Vertaal 56 Engelse foutteksten in de Nederlandse interface
Deze verschenen zodra de backend geen eigen melding meegaf: de terugvalteksten
van formatError en de controles vóór een handeling. Een operator kreeg dan
"Failed to load exports" of "Select a project first" te zien, midden in een
verder Nederlandse werkbank.

Dit is geen meertaligheidsvraagstuk maar inconsistentie binnen de taal die het
product al spreekt. De teksten volgen nu de bestaande toon: benoemen wat er
misging of wat er eerst nodig is, in actieve vorm, zonder excuus.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-23 15:10:07 +02:00

61 lines
2.2 KiB
TypeScript

import { useState } from 'react'
import type { DatasetCreateResponse, VectorSelectionBBox } from '../types'
import { formatError } from '../lib/formatError'
import { datasetsApi } from '../services/api'
interface UseMapSelectionDatasetOptions {
selectedProjectId: string | null
selectedDataset: DatasetCreateResponse | null
isVectorDatasetType: (datasetType: string) => boolean
loadProjectData: (projectId: string) => Promise<unknown>
loadDatasetDetails: (projectId: string, dataset: DatasetCreateResponse) => Promise<void>
setMapLayerVisible: (visible: boolean) => void
}
export function useMapSelectionDataset({
selectedProjectId,
selectedDataset,
isVectorDatasetType,
loadProjectData,
loadDatasetDetails,
setMapLayerVisible,
}: UseMapSelectionDatasetOptions) {
const [selectionDatasetSaving, setSelectionDatasetSaving] = useState(false)
const [selectionDatasetError, setSelectionDatasetError] = useState<string | null>(null)
const [latestSelectionDataset, setLatestSelectionDataset] = useState<DatasetCreateResponse | null>(null)
const deriveMapSelectionDataset = async (bbox: VectorSelectionBBox, areaId?: string) => {
if (!selectedProjectId || !selectedDataset || !isVectorDatasetType(selectedDataset.dataset_type)) {
setSelectionDatasetError('Kies eerst een vectorbron om het gebied als bron te bewaren.')
return null
}
setSelectionDatasetSaving(true)
setSelectionDatasetError(null)
try {
const derived = await datasetsApi.deriveVectorSelection(selectedProjectId, selectedDataset.id, {
bbox: { ...bbox, crs: 'EPSG:4326' },
area_id: areaId,
limit: 250,
output_name: `${selectedDataset.name.replace(/\.(geo)?json$/i, '')}-selection-dataset`,
})
setLatestSelectionDataset(derived)
await loadProjectData(selectedProjectId)
await loadDatasetDetails(selectedProjectId, derived)
setMapLayerVisible(true)
return derived
} catch (error) {
setSelectionDatasetError(formatError(error, 'Het gebied kon niet als bron worden bewaard'))
return null
} finally {
setSelectionDatasetSaving(false)
}
}
return {
selectionDatasetSaving,
selectionDatasetError,
latestSelectionDataset,
deriveMapSelectionDataset,
}
}