import React from 'react' import { Loader2, Save, Plug, RefreshCw, Unplug } from 'lucide-react' import { useTranslation } from '../../i18n' import { useFormatDate } from '../../hooks/useDateFormat' import { useDawarichConnection } from '../../hooks/useDawarichConnection' import DawarichIcon from '../shared/DawarichIcon' import Section from './Section' import ToggleSwitch from './ToggleSwitch' import { SETTINGS_BUTTON, SETTINGS_BUTTON_DANGER, SETTINGS_BUTTON_PRIMARY, SettingRow, SettingRows, StatusPill } from './settingsKit' import { EditorField, GRID_2, INPUT } from '../shared/dialogParts' import { fs } from '../shared/DialogShell' /** * Settings → Integrations → Dawarich. * * All of the behaviour is in `useDawarichConnection`, shared with the phone * twin; this file is markup. The layout follows the AirTrail and LLM sections * so the three read as one shelf: fields side by side, the switches as rows, * the actions under them and the connection state as a pill in the band. * * The status block below the fields is the part that earns its space: a * connection to somebody else's server fails in ways they can act on — a wrong * key, a certificate, an instance that is simply off — and "not connected" with * no reason is the version of this card that generates support questions. */ export default function DawarichConnectionSection(): React.ReactElement { const { t } = useTranslation() const S = useDawarichConnection() return (
}> {S.connected ? t('dawarich.connected') : t('dawarich.notConnected')} } >
S.setUrl(e.target.value)} placeholder="https://dawarich.example.com" className={INPUT} /> S.setApiKey(e.target.value)} autoComplete="off" placeholder={S.connected && !S.apiKey ? '••••••••' : t('dawarich.apiKeyPlaceholder')} className={INPUT} />
} /> } />
{S.connected && ( )} {/* The way out sits apart from the everyday actions, on the far right. */} {S.connected && ( )}
) } /** * Where the connection stands, in the place where it helps someone decide what * to do next: what the last sync did, and which parts of their instance TREK * could actually reach. * * Its own component because the phone twin renders the same three facts in a * different frame, and because it is the bit that keeps growing. */ function DawarichConnectionStatus({ state, }: { state: ReturnType }): React.ReactElement | null { const { t } = useTranslation() const { formatDateTime } = useFormatDate() if (!state.connected && !state.probeMessage) return null const missing: string[] = [] if (state.capabilities) { if (!state.capabilities.visits) missing.push(t('dawarich.capability.visits')) if (!state.capabilities.tracks && !state.capabilities.points) missing.push(t('dawarich.capability.track')) if (!state.capabilities.locations) missing.push(t('dawarich.capability.locations')) if (!state.capabilities.visitedCities) missing.push(t('dawarich.capability.visitedCities')) } return (
{state.probeMessage &&

{state.probeMessage}

} {state.connected && (

{state.lastSyncAt ? t('dawarich.lastSync', { when: formatDateTime(new Date(state.lastSyncAt)) }) : t('dawarich.neverSynced')} {state.lastSyncState === 'partial' && `, ${t('dawarich.syncPartial')}`}

)} {state.lastSyncError && (

{state.lastSyncError}

)} {state.capabilities?.serverVersion && (

{t('dawarich.serverVersion', { version: state.capabilities.serverVersion })}

)} {missing.length > 0 && (

{t('dawarich.capability.missing', { features: missing.join(', ') })}

)}
) }