diff --git a/frontend/src/App.svelte b/frontend/src/App.svelte index bdf2f49..89ccf37 100644 --- a/frontend/src/App.svelte +++ b/frontend/src/App.svelte @@ -98,6 +98,14 @@ let renameValue = '' let renameError = '' + // ===== Sync state ===== + let showSettings = false + let syncStatus = null + let syncLoading = false + let syncServerUrl = '' + let syncApiKey = '' + let syncResult = '' + const tabs = [ { id: 'overview', label: 'Обзор' }, { id: 'notes', label: 'Заметки' }, @@ -138,6 +146,7 @@ window.addEventListener('keydown', handleKeydown) loading = false + loadSyncStatus() }) onDestroy(() => { @@ -882,6 +891,53 @@ error = String(e) } } + + // ===== Sync ===== + async function loadSyncStatus() { + try { + syncStatus = await wailsCall('SyncStatus') + } catch (e) { + syncStatus = { configured: false, serverUrl: '', deviceId: '', unpushedOps: 0, lastSyncAt: '' } + } + } + + function openSettings() { + showSettings = true + syncServerUrl = syncStatus?.serverUrl || '' + syncApiKey = '' + syncResult = '' + } + + function closeSettings() { + showSettings = false + syncResult = '' + } + + async function saveSyncConfig() { + syncLoading = true + syncResult = '' + try { + await wailsCall('SyncConfigure', syncServerUrl, syncApiKey) + syncResult = 'ok' + await loadSyncStatus() + } catch (e) { + syncResult = 'err: ' + String(e) + } + syncLoading = false + } + + async function runSyncNow() { + syncLoading = true + syncResult = '' + try { + const r = await wailsCall('SyncNow') + syncResult = 'pushed ' + r.pushed + ', pulled ' + r.pulled + ' (rev ' + r.serverRevision + ')' + await loadSyncStatus() + } catch (e) { + syncResult = 'err: ' + String(e) + } + syncLoading = false + }