diverse änderungen

This commit is contained in:
marco committed 2026-11-05 15:17:01 +01:00
1 parent 0e7b53e558
commit 54d5e58798
60 files changed
+1637 -122

No files matched your search

@@ -0,0 +1,39 @@
'use client';
import { useEffect, useState } from 'react';
import { api_proconParameterValues } from '@/actions/parameter/api-parameter';
import type { ProconParameterValues } from '@/types/parameter';
export function useProconParameterValues(anlageId?: string, version?: number | string) {
const [data, setData] = useState<ProconParameterValues | null>(null);
const [loading, setLoading] = useState(false);
const [error, setError] = useState('');
const [refresh, setRefresh] = useState(0);
useEffect(() => {
if (!anlageId) { setData(null); return; }
let active = true;
setLoading(true); setError(''); setData(null);
api_proconParameterValues().then(result => {
if (!active) return;
if (!result.success) { setError(result.error); return; }
if (result.data.anlageId !== anlageId) { setError('Anlage geändert. Seite neu laden.'); return; }
setData(result.data);
}).catch(() => { if (active) setError('ProCon-Werte konnten nicht geladen werden.'); })
.finally(() => { if (active) setLoading(false); });
return () => { active = false; };
}, [anlageId, version, refresh]);
return { data, loading, error, reload: () => setRefresh(current => current + 1) };
}
export default function ProconParameterValue({ parameterNr, state }: {
parameterNr: number; state: ReturnType<typeof useProconParameterValues>; disabled?: boolean;
}) {
if (state.loading) return <span>Laden ...</span>;
if (state.error || !state.data) return <span>Nicht verfuegbar</span>;
const matches = state.data.values.filter(value => value.parameterNr === parameterNr);
if (!matches.length) return <span>Nicht in ProCon vorhanden</span>;
return <div>{matches.map(value => <div key={String(value.definitionId)+'-'+value.parameterId}>
{matches.length > 1 && 'ID '+value.parameterId+': '}
{value.parameterId === null ? 'Kein gespeicherter Wert' : value.wert ?? '(leer)'}
</div>)}</div>;
}