/** * Settings > Git Keys — SSH credential management */ const { html } = window; const { useState, useEffect, useCallback } = hooks; function fmtDate(d) { if (!d) return '\u2014'; return new Date(d).toLocaleString(undefined, { dateStyle: 'short', timeStyle: 'short' }); } export default function GitKeysSection() { const [keys, setKeys] = useState([]); const [loading, setLoading] = useState(true); const [showAdd, setShowAdd] = useState(false); const load = useCallback(async () => { try { const data = await sw.api.git.credentials.list(); setKeys(data || []); } catch (e) { sw.toast(e.message, 'error'); } finally { setLoading(false); } }, []); useEffect(() => { load(); }, []); async function addKey(e) { e.preventDefault(); const form = e.target; const name = form.name.value.trim(); const key = form.key.value.trim(); if (!name) { sw.toast('Name is required', 'error'); return; } try { await sw.api.git.credentials.create({ name, public_key: key || undefined }); sw.toast('Credential added', 'success'); form.reset(); setShowAdd(false); load(); } catch (e) { sw.toast(e.message, 'error'); } } async function deleteKey(id) { const ok = await sw.confirm('Delete this SSH credential?', true); if (!ok) return; try { await sw.api.git.credentials.del(id); sw.toast('Credential deleted', 'success'); load(); } catch (e) { sw.toast(e.message, 'error'); } } if (loading) return html`