import React, { useState, useEffect, useRef } from "react"; import { PrimaryButton, DefaultButton, Stack, Text, ProgressIndicator, MessageBar, MessageBarType, } from "@fluentui/react"; import { SyncResult } from "../../models/types"; import { ProfileManager } from "../../services/profile-manager"; import { SyncEngine } from "../../services/sync-engine"; interface Props { profileId: string; onBack: () => void; } export const SyncView: React.FC = ({ profileId, onBack }) => { const pm = new ProfileManager(); const profile = pm.getProfile(profileId); const [running, setRunning] = useState(false); const [progress, setProgress] = useState([]); const [result, setResult] = useState(null); const logRef = useRef(null); const addProgress = (msg: string) => { setProgress((prev) => [...prev, `[${new Date().toLocaleTimeString("de-DE")}] ${msg}`]); }; useEffect(() => { if (logRef.current) { logRef.current.scrollTop = logRef.current.scrollHeight; } }, [progress]); const handleSync = async () => { if (!profile) return; setRunning(true); setProgress([]); setResult(null); addProgress("Synchronisation gestartet..."); const engine = new SyncEngine(); const syncResult = await engine.syncProfile(profile, (msg) => { addProgress(msg); }); setResult(syncResult); setRunning(false); addProgress("Fertig."); }; if (!profile) { return ( Profil nicht gefunden. ); } return (
Synchronisation
Profil: {profile.name} {profile.starfaceConnection.host} ({profile.starfaceAddressBook.name}) {" ↔ "} {profile.outlookFolderName}
{!running && !result && ( )} {running && ( )} {progress.length > 0 && (
{progress.map((msg, i) => ( {msg} ))}
)} {result && (
{result.errors.length === 0 ? ( Synchronisation erfolgreich abgeschlossen! ) : ( Synchronisation mit {result.errors.length} Fehler(n) abgeschlossen. )}
{result.created} Erstellt
{result.updated} Aktualisiert
{result.errors.length} Fehler
{result.errors.length > 0 && (
Fehler: {result.errors.map((err, i) => ( {err} ))}
)}
)}
); };