feat: add temporal Mol explorer
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { formatError } from '../lib/formatError'
|
||||
import { temporalApi } from '../services/api/temporal'
|
||||
import type { TemporalComparisonResponse, VectorSelectionBBox } from '../types'
|
||||
|
||||
export function useTemporalComparison(selectedProjectId: string | null) {
|
||||
const [temporalComparison, setTemporalComparison] = useState<TemporalComparisonResponse | null>(null)
|
||||
const [temporalComparisonLoading, setTemporalComparisonLoading] = useState(false)
|
||||
const [temporalComparisonError, setTemporalComparisonError] = useState<string | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
setTemporalComparison(null)
|
||||
setTemporalComparisonError(null)
|
||||
}, [selectedProjectId])
|
||||
|
||||
const clearTemporalComparison = () => {
|
||||
setTemporalComparison(null)
|
||||
setTemporalComparisonError(null)
|
||||
}
|
||||
|
||||
const compareTemporalSnapshots = async (
|
||||
earlierDatasetId: string,
|
||||
laterDatasetId: string,
|
||||
bbox: VectorSelectionBBox,
|
||||
): Promise<TemporalComparisonResponse | null> => {
|
||||
if (!selectedProjectId) {
|
||||
setTemporalComparisonError('Open eerst een project om evoluties te vergelijken.')
|
||||
return null
|
||||
}
|
||||
if (!earlierDatasetId || !laterDatasetId) {
|
||||
setTemporalComparisonError('Kies twee meetmomenten uit dezelfde tijdreeks.')
|
||||
return null
|
||||
}
|
||||
|
||||
setTemporalComparisonLoading(true)
|
||||
setTemporalComparisonError(null)
|
||||
try {
|
||||
const result = await temporalApi.compare(selectedProjectId, {
|
||||
earlier_dataset_id: earlierDatasetId,
|
||||
later_dataset_id: laterDatasetId,
|
||||
bbox,
|
||||
preview_limit: 500,
|
||||
})
|
||||
setTemporalComparison(result)
|
||||
return result
|
||||
} catch (error) {
|
||||
setTemporalComparison(null)
|
||||
setTemporalComparisonError(formatError(error, 'De evolutieanalyse is mislukt.'))
|
||||
return null
|
||||
} finally {
|
||||
setTemporalComparisonLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
temporalComparison,
|
||||
temporalComparisonLoading,
|
||||
temporalComparisonError,
|
||||
compareTemporalSnapshots,
|
||||
clearTemporalComparison,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user