import { Link, useLocation } from 'react-router-dom' import { useEffect, useState } from 'react' import { listInitiatives } from '../api/initiatives.js' import { useProgramScope } from '../context/ProgramScopeContext.jsx' import { LoadingState } from './LoadingState.jsx' import { scopedPath } from '../utils/routes.js' export function RequireInitiativeScope({ children, lead }) { const location = useLocation() const { initiativeId, applyFromInitiative } = useProgramScope() const [initiatives, setInitiatives] = useState(null) const basePath = location.pathname.replace(/\/$/, '') || location.pathname useEffect(() => { if (initiativeId) return let cancelled = false listInitiatives() .then((data) => { if (!cancelled) setInitiatives(data) }) .catch(() => { if (!cancelled) setInitiatives([]) }) return () => { cancelled = true } }, [initiativeId]) if (initiativeId) { return children } if (initiatives === null) { return } return ( Vorhaben wählen {lead || 'Dieser Modus braucht ein Vorhaben als Scope-Filter.'} {initiatives.length === 0 ? ( Noch keine Vorhaben angelegt. ) : ( {initiatives.map((item) => ( applyFromInitiative(item.id)} > {item.title} ))} )} ) }
{lead || 'Dieser Modus braucht ein Vorhaben als Scope-Filter.'}
Noch keine Vorhaben angelegt.