Milestone 6: canvas for health and leaving
Devices report freshness per vault every 30 s (counts only); the canvas shows current / behind / offline, held secrets in red, and a Nudge that reaches the device at its next check-in. Notes kept in two versions can be compared side by side and tidied on the hub's copy. Handovers are reviewed in the vault panel; people can be removed from the team and restored with a one-time link. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
// also has a button in the details panel (X3).
|
||||
|
||||
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { api, type CanvasData, type LogEntry, type Member, type Person, type Role, type Vault } from './api';
|
||||
import { api, type CanvasData, type Comparison, type Health, type LogEntry, type Member, type Person, type Role, type Status, type Vault } from './api';
|
||||
import {
|
||||
HANDLE_T, W, boardHeight, circle, easeBack, lerp, personColor, positions, ribbon, roundRect, vaultColor,
|
||||
type Layout, type Pt,
|
||||
@@ -15,6 +15,37 @@ const roleName = (r: Role) => r.charAt(0).toUpperCase() + r.slice(1);
|
||||
const plural = (n: number, word: string, many = word + 's') => `${n} ${n === 1 ? word : many}`;
|
||||
const keyOf = (m: { vault: string; person: string }) => `${m.vault}|${m.person}`;
|
||||
|
||||
/** Status colors are reserved for status (X6): green current, amber behind or needs a decision, grey offline,
|
||||
* red only for a possible secret held back. */
|
||||
const STATUS: Record<Status, string> = { current: '#2E8B5F', behind: '#E09A2B', offline: '#A9A5B6' };
|
||||
const STATUS_WORDS: Record<Status, string> = { current: 'Current', behind: 'Behind', offline: 'Offline' };
|
||||
const PILL: Record<Status, [string, string]> = { current: ['#E3F2EA', '#1F6B47'], behind: ['#FBEBD3', '#7A4500'], offline: ['#EEECF2', '#5C5770'] };
|
||||
const SECRET_RED = '#C8323B';
|
||||
|
||||
/** A person's freshness is their worst device. */
|
||||
function worst(p: Person): Status {
|
||||
if (!p.devices.length) return 'offline';
|
||||
if (p.devices.some((d) => d.health.status === 'behind')) return 'behind';
|
||||
if (p.devices.some((d) => d.health.status === 'offline')) return 'offline';
|
||||
return 'current';
|
||||
}
|
||||
|
||||
function ago(unix: number | null): string {
|
||||
if (!unix) return 'never';
|
||||
const s = Math.max(0, Date.now() / 1000 - unix);
|
||||
if (s < 90) return 'just now';
|
||||
if (s < 3600) return `${Math.round(s / 60)} min ago`;
|
||||
if (s < 86400) return `${Math.round(s / 3600)} h ago`;
|
||||
return plural(Math.round(s / 86400), 'day') + ' ago';
|
||||
}
|
||||
|
||||
function healthLine(h: Health): string {
|
||||
const waiting = h.waiting > 0 ? `${plural(h.waiting, 'change')} not shared` : '';
|
||||
if (h.status === 'offline') return `Offline · last seen ${ago(h.last_seen)}${waiting ? ' · ' + waiting : ''}`;
|
||||
if (h.status === 'behind') return [waiting, h.last_synced ? `last synced ${ago(h.last_synced)}` : ''].filter(Boolean).join(' · ') || 'Something is held on this device';
|
||||
return `Synced ${ago(h.last_synced)}`;
|
||||
}
|
||||
|
||||
type Sel =
|
||||
| { kind: 'overview'; back?: Sel }
|
||||
| { kind: 'vault'; id: string; back?: Sel }
|
||||
@@ -25,6 +56,12 @@ type Drag =
|
||||
| { kind: 'detach'; key: string; p: Pt }
|
||||
| { kind: 'snap'; key: string; p: Pt };
|
||||
type Toast = { text: string; undo?: () => void };
|
||||
type Sheet =
|
||||
| 'invite'
|
||||
| 'vault'
|
||||
| { kind: 'compare'; vault: Vault; copy: string }
|
||||
| { kind: 'team'; p: Person }
|
||||
| { kind: 'restored'; p: Person; link: string };
|
||||
|
||||
function store(key: string, value?: string): string | null {
|
||||
try {
|
||||
@@ -45,7 +82,7 @@ export function Canvas({ data, reload, onSignOut }: { data: CanvasData; reload:
|
||||
const [drag, setDrag] = useState<Drag | null>(null);
|
||||
const [pinched, setPinched] = useState<{ key: string; p: Pt; t: number } | null>(null);
|
||||
const [toast, setToast] = useState<Toast | null>(null);
|
||||
const [sheet, setSheet] = useState<'invite' | 'vault' | null>(null);
|
||||
const [sheet, setSheet] = useState<Sheet | null>(null);
|
||||
const [onboarded, setOnboarded] = useState(store('lune.onboarded') === '1');
|
||||
const [hidden, setHidden] = useState<Set<string>>(new Set());
|
||||
const [extra, setExtra] = useState<Member[]>([]);
|
||||
@@ -203,6 +240,7 @@ export function Canvas({ data, reload, onSignOut }: { data: CanvasData; reload:
|
||||
const target = (p: Pt) => {
|
||||
let best: string | null = null, bd = 1e9;
|
||||
for (const pr of people) {
|
||||
if (pr.removed) continue;
|
||||
const q = pos(pr.id), d = Math.hypot(p.x - q.x, p.y - q.y);
|
||||
if (d < bd) { bd = d; best = pr.id; }
|
||||
}
|
||||
@@ -278,6 +316,16 @@ export function Canvas({ data, reload, onSignOut }: { data: CanvasData; reload:
|
||||
|
||||
vaults.forEach((v, i) => {
|
||||
const p = pos(v.id), delay = (i * 0.7).toFixed(1), vo = relV(v.id) ? 1 : 0.35;
|
||||
// Amber means a decision is waiting (X6): notes to tidy, handovers to review.
|
||||
const review = v.handovers.filter((h) => h.state === 'received').length, tidy = v.tidy.length;
|
||||
const decide = review + tidy;
|
||||
if (decide > 0) {
|
||||
labels.push({
|
||||
text: tidy && !review ? `${tidy} to tidy` : review && !tidy ? plural(review, 'handover') : `${decide} to decide`,
|
||||
style: { ...pct(p.x + 34, p.y - 40), transform: 'translate(-50%,-50%)', opacity: vo },
|
||||
inner: { display: 'inline-block', whiteSpace: 'nowrap', fontWeight: 700, fontSize: 'max(1.05cqw, 9px)', color: '#7A4500', background: '#FBEBD3', border: '1px solid #E09A2B', borderRadius: 999, padding: '0.15em 0.7em', animationDelay: `${delay}s` },
|
||||
});
|
||||
}
|
||||
blobs.push({ d: roundRect(p.x, p.y, 138, 70, 26), fill: vaultColor(v.id).fill, delay, op: focus && relV(v.id) ? 1 : 0 });
|
||||
labels.push({
|
||||
text: v.name,
|
||||
@@ -286,11 +334,11 @@ export function Canvas({ data, reload, onSignOut }: { data: CanvasData; reload:
|
||||
});
|
||||
});
|
||||
people.forEach((pr, i) => {
|
||||
const p = pos(pr.id), delay = (0.35 + i * 0.6).toFixed(1), po = relP(pr.id) ? 1 : 0.35;
|
||||
if (!pr.invited) blobs.push({ d: circle(p.x, p.y, 38), fill: personColor(pr.id).fill, delay, op: focus && relP(pr.id) ? 1 : 0 });
|
||||
const p = pos(pr.id), delay = (0.35 + i * 0.6).toFixed(1), po = pr.removed ? 0.45 : relP(pr.id) ? 1 : 0.35;
|
||||
if (!pr.invited && !pr.removed) blobs.push({ d: circle(p.x, p.y, 38), fill: personColor(pr.id).fill, delay, op: focus && relP(pr.id) ? 1 : 0 });
|
||||
labels.push({ text: pr.name.charAt(0).toUpperCase(), style: { ...pct(p.x, p.y), transform: 'translate(-50%,-50%)', opacity: po }, inner: { display: 'inline-block', fontWeight: 700, fontSize: 'max(2cqw, 12px)', animationDelay: `${delay}s` } });
|
||||
labels.push({
|
||||
text: pr.invited ? `${pr.name} · invited` : pr.name,
|
||||
text: pr.invited ? `${pr.name} · invited` : pr.removed ? `${pr.name} · removed` : pr.name,
|
||||
style: { ...pct(p.x, p.y + 48), transform: 'translate(-50%,-50%)', opacity: po },
|
||||
inner: { display: 'inline-block', whiteSpace: 'nowrap', fontSize: 'max(1.3cqw, 10px)', animationDelay: `${delay}s` },
|
||||
});
|
||||
@@ -446,12 +494,12 @@ export function Canvas({ data, reload, onSignOut }: { data: CanvasData; reload:
|
||||
return (
|
||||
<g key={d.id} className="fade" opacity={veil ? 0.35 : 1}>
|
||||
<line x1="0" y1="0" x2={cx} y2={cy} stroke="#E2DDF0" strokeWidth="1.5" />
|
||||
<circle cx={cx} cy={cy} r="6.5" fill={c.ring} stroke="#FFFFFF" strokeWidth="2" />
|
||||
<circle cx={cx} cy={cy} r="6.5" fill={d.health.held_secrets > 0 ? SECRET_RED : STATUS[d.health.status]} stroke="#FFFFFF" strokeWidth="2" />
|
||||
</g>
|
||||
);
|
||||
})}
|
||||
<g data-person={pr.name} onClick={() => { if (!drag) setSel({ kind: 'person', id: pr.id }); }} onPointerEnter={() => enter('person', pr.id)} onPointerLeave={leave} style={{ cursor: 'pointer' }}>
|
||||
<circle r="30" fill={pr.id === hot ? c.fill : c.tint} stroke={c.ring} strokeWidth={pr.id === hot ? 6 : on ? 4.5 : 3} strokeDasharray={pr.invited ? '5 5' : 'none'} />
|
||||
<circle r="30" fill={pr.id === hot ? c.fill : c.tint} stroke={pr.invited ? c.ring : pr.removed ? STATUS.offline : STATUS[worst(pr)]} strokeWidth={pr.id === hot ? 6 : on ? 4.5 : 3} strokeDasharray={pr.invited || pr.removed ? '5 5' : 'none'} opacity={pr.removed ? 0.45 : 1} />
|
||||
<circle className="fade" r="34" fill="#F5F3FB" opacity={veil} pointerEvents="none" />
|
||||
</g>
|
||||
</g>
|
||||
@@ -490,7 +538,13 @@ export function Canvas({ data, reload, onSignOut }: { data: CanvasData; reload:
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="bottombar">{hint && <span className={`chipbar${hintHot ? ' hot' : ''}`}>{hint}</span>}</div>
|
||||
<div className="bottombar">
|
||||
{hint && <span className={`chipbar${hintHot ? ' hot' : ''}`}>{hint}</span>}
|
||||
<span className="chipbar legend" style={{ marginLeft: 'auto' }}>
|
||||
{(Object.keys(STATUS) as Status[]).map((s) => <span key={s}><i style={{ background: STATUS[s] }} />{STATUS_WORDS[s]}</span>)}
|
||||
<span><i style={{ background: SECRET_RED }} />Possible secret held</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{!onboarded && manages && vaults.length > 0 && (
|
||||
<div className="coach" role="note" aria-label="Getting started">
|
||||
@@ -508,16 +562,38 @@ export function Canvas({ data, reload, onSignOut }: { data: CanvasData; reload:
|
||||
{sel.kind === 'overview' && <Overview data={data} members={members} log={log} open={open} close={() => setSel(null)} newVault={() => setSheet('vault')} signOut={onSignOut} />}
|
||||
{sel.kind === 'vault' && vault(sel.id) && (
|
||||
<VaultPanel v={vault(sel.id)} data={data} members={members} open={open} close={() => setSel(null)}
|
||||
cycleRole={cycleRole} remove={(m) => revoke(keyOf(m))} grant={grant}
|
||||
cycleRole={cycleRole} remove={(m) => revoke(keyOf(m))} grant={grant} run={run}
|
||||
compare={(copy) => setSheet({ kind: 'compare', vault: vault(sel.id), copy })}
|
||||
toggleDelete={(v) => run(() => api.vaultSetting(v.name, !v.delete_from_devices), v.delete_from_devices ? `Removed people keep a read-only copy of ${v.name}.` : `Removed people's copies of ${v.name} are deleted from their devices.`)} />
|
||||
)}
|
||||
{sel.kind === 'person' && person(sel.id) && (
|
||||
<PersonPanel p={person(sel.id)} data={data} members={members} open={open} close={() => setSel(null)} run={run} />
|
||||
<PersonPanel p={person(sel.id)} data={data} members={members} open={open} close={() => setSel(null)} run={run}
|
||||
removeFromTeam={(p) => setSheet({ kind: 'team', p })}
|
||||
restore={(p) => api.teamRestore(p.name).then((r) => { setSheet({ kind: 'restored', p, link: r.link }); reload(); }).catch((e) => say(e.message))} />
|
||||
)}
|
||||
</aside>
|
||||
)}
|
||||
|
||||
{sheet === 'invite' && <InviteDialog vaults={vaults.filter((v) => v.can_manage)} owner={data.me.owner} close={() => { setSheet(null); reload(); }} />}
|
||||
{typeof sheet === 'object' && sheet?.kind === 'compare' && (
|
||||
<CompareDialog vault={sheet.vault} copy={sheet.copy} canEdit={['edit', 'manage'].includes(members.find((m) => m.vault === sheet.vault.id && m.person === data.me.id)?.role ?? '')}
|
||||
close={() => setSheet(null)}
|
||||
resolve={(keep) => { const s = sheet; setSheet(null); run(async () => say((await api.resolve(s.vault.name, s.copy, keep)).message)); }} />
|
||||
)}
|
||||
{typeof sheet === 'object' && sheet?.kind === 'team' && (
|
||||
<TeamDialog p={sheet.p} data={data} members={members} close={() => setSheet(null)}
|
||||
confirm={() => { const p = sheet.p; setSheet(null); setSel({ kind: 'person', id: p.id }); run(() => api.teamRemove(p.name), `${p.name} was removed from the team. Their devices send unshared work, then delete every vault copy.`); }} />
|
||||
)}
|
||||
{typeof sheet === 'object' && sheet?.kind === 'restored' && (
|
||||
<div className="scrim" onPointerDown={(e) => { if (e.target === e.currentTarget) setSheet(null); }}>
|
||||
<div className="dialog" role="dialog" aria-modal="true" aria-label={`${sheet.p.name} restored`}>
|
||||
<h2 className="disp">{sheet.p.name} is back on the team</h2>
|
||||
<p style={{ margin: 0, lineHeight: 1.5 }}>They start with no vaults — give them some by dragging. Send them this one-time sign-in link (7 days):</p>
|
||||
<pre className="cmd">lunesync join {sheet.link} --name "<their device>"</pre>
|
||||
<div className="actions"><button className="btn btn-primary" onClick={() => setSheet(null)}>Done</button></div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{sheet === 'vault' && <NewVaultDialog close={() => setSheet(null)} create={(name) => { setSheet(null); run(() => api.createVault(name), `${name} is ready. Drag it onto people to share it.`); }} />}
|
||||
|
||||
<div className="toast-wrap" aria-live="polite">
|
||||
@@ -534,7 +610,8 @@ export function Canvas({ data, reload, onSignOut }: { data: CanvasData; reload:
|
||||
|
||||
function Avatar({ p }: { p: Person }) {
|
||||
const c = personColor(p.id);
|
||||
return <span className="avatar" style={{ background: c.tint, borderColor: c.ring, borderStyle: p.invited ? 'dashed' : 'solid' }}>{p.name.charAt(0).toUpperCase()}</span>;
|
||||
const ring = p.invited ? c.ring : p.removed ? STATUS.offline : STATUS[worst(p)];
|
||||
return <span className="avatar" style={{ background: c.tint, borderColor: ring, borderStyle: p.invited || p.removed ? 'dashed' : 'solid' }}>{p.name.charAt(0).toUpperCase()}</span>;
|
||||
}
|
||||
|
||||
function Swatch({ v }: { v: Vault }) {
|
||||
@@ -574,8 +651,9 @@ function Overview({ data, members, log, open, close, newVault, signOut }: {
|
||||
<Avatar p={p} />
|
||||
<span style={{ display: 'flex', flexDirection: 'column', flex: 1, minWidth: 0 }}>
|
||||
<b>{p.name}</b>
|
||||
<span className="sub">{p.invited ? 'Invited, not joined yet' : p.owner ? 'Team owner' : plural(members.filter((m) => m.person === p.id).length, 'vault')}</span>
|
||||
<span className="sub">{p.invited ? 'Invited, not joined yet' : p.removed ? 'Removed from team' : p.owner ? 'Team owner' : plural(members.filter((m) => m.person === p.id).length, 'vault')}</span>
|
||||
</span>
|
||||
{!p.invited && !p.removed && (() => { const st = worst(p), [bg, fg] = PILL[st]; return <span className="pill" style={{ background: bg, color: fg }}>{STATUS_WORDS[st]}</span>; })()}
|
||||
<span aria-hidden="true" className="chev">›</span>
|
||||
</button>
|
||||
))}
|
||||
@@ -598,12 +676,13 @@ function Overview({ data, members, log, open, close, newVault, signOut }: {
|
||||
);
|
||||
}
|
||||
|
||||
function VaultPanel({ v, data, members, open, close, cycleRole, remove, grant, toggleDelete }: {
|
||||
function VaultPanel({ v, data, members, open, close, cycleRole, remove, grant, toggleDelete, run, compare }: {
|
||||
v: Vault; data: CanvasData; members: Member[]; open: (s: Sel) => void; close: () => void;
|
||||
cycleRole: (m: Member) => void; remove: (m: Member) => void; grant: (v: string, p: string) => void; toggleDelete: (v: Vault) => void;
|
||||
run: (action: () => Promise<unknown>, ok?: string) => Promise<void>; compare: (copy: string) => void;
|
||||
}) {
|
||||
const inVault = members.filter((m) => m.vault === v.id);
|
||||
const outside = data.people.filter((p) => !inVault.some((m) => m.person === p.id));
|
||||
const outside = data.people.filter((p) => !p.removed && !inVault.some((m) => m.person === p.id));
|
||||
const mine = inVault.find((m) => m.person === data.me.id);
|
||||
return (
|
||||
<>
|
||||
@@ -612,6 +691,19 @@ function VaultPanel({ v, data, members, open, close, cycleRole, remove, grant, t
|
||||
<CloseButton close={close} />
|
||||
</div>
|
||||
{!v.can_manage && mine && <div className="note">You have {roleName(mine.role)} access. People with Manage decide who else can sync it.</div>}
|
||||
{v.tidy.length > 0 && (
|
||||
<div className="note amber">
|
||||
<b>{plural(v.tidy.length, 'note')} to tidy</b>
|
||||
<span>Changed in two places at once. Both versions are kept, so nothing is lost.</span>
|
||||
{v.tidy.map((t) => (
|
||||
<div key={t.copy} style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
|
||||
<span style={{ flex: 1, minWidth: 0, overflowWrap: 'anywhere' }}>{t.note}</span>
|
||||
<button className="btn btn-small" onClick={() => compare(t.copy)}>Compare</button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{v.handovers.map((h) => <HandoverCard key={h.id} h={h} vault={v} run={run} />)}
|
||||
<div>
|
||||
<h3>People with access</h3>
|
||||
{inVault.map((m) => {
|
||||
@@ -654,14 +746,15 @@ function VaultPanel({ v, data, members, open, close, cycleRole, remove, grant, t
|
||||
);
|
||||
}
|
||||
|
||||
function PersonPanel({ p, data, members, open, close, run }: {
|
||||
function PersonPanel({ p, data, members, open, close, run, removeFromTeam, restore }: {
|
||||
p: Person; data: CanvasData; members: Member[]; open: (s: Sel) => void; close: () => void;
|
||||
run: (action: () => Promise<unknown>, ok?: string) => Promise<void>;
|
||||
run: (action: () => Promise<unknown>, ok?: string) => Promise<void>; removeFromTeam: (p: Person) => void; restore: (p: Person) => void;
|
||||
}) {
|
||||
const [renaming, setRenaming] = useState<{ id: string; value: string } | null>(null);
|
||||
const theirs = members.filter((m) => m.person === p.id);
|
||||
const canEditDevices = p.id === data.me.id || data.me.owner;
|
||||
const eyebrow = p.invited ? 'Invited' : p.owner ? 'Team owner' : 'Team member';
|
||||
const eyebrow = p.invited ? 'Invited' : p.removed ? 'Removed from team' : p.owner ? 'Team owner' : 'Team member';
|
||||
const leaving = data.vaults.flatMap((v) => v.handovers.filter((h) => h.person === p.name && h.state === 'waiting').map((h) => ({ ...h, vault: v })));
|
||||
return (
|
||||
<>
|
||||
<div className="panel-head">
|
||||
@@ -669,7 +762,24 @@ function PersonPanel({ p, data, members, open, close, run }: {
|
||||
<CloseButton close={close} />
|
||||
</div>
|
||||
{p.invited && <div className="note">{p.name} hasn't joined yet. Vaults you give them now arrive once they join with their invite link.</div>}
|
||||
{!p.invited && (
|
||||
{p.removed && (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
|
||||
<p style={{ margin: 0, fontSize: 14, lineHeight: 1.5 }}>This account is disabled. Past changes keep this name in history.</p>
|
||||
{data.me.owner && <button className="btn" style={{ alignSelf: 'flex-start' }} onClick={() => restore(p)}>Restore account</button>}
|
||||
</div>
|
||||
)}
|
||||
{leaving.length > 0 && (
|
||||
<div className="note">
|
||||
<b>Leaving</b>
|
||||
{leaving.map((h) => (
|
||||
<div key={h.id} style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
|
||||
<span>{h.device} hasn't reported in since losing {h.vault.name}. Its unshared work comes back when it's next online.</span>
|
||||
<button className="btn btn-small btn-danger" style={{ alignSelf: 'flex-start' }} onClick={() => run(() => api.handoverDecide(h.id, 'skip'), `${h.device} will delete its copy of ${h.vault.name} without sending anything.`)}>Delete without saving</button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{!p.invited && !p.removed && (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>
|
||||
<h3>Devices</h3>
|
||||
{p.devices.length === 0 && <p className="muted">{canEditDevices ? 'No devices yet.' : "Only their vault managers see someone's devices."}</p>}
|
||||
@@ -683,13 +793,24 @@ function PersonPanel({ p, data, members, open, close, run }: {
|
||||
<button className="btn btn-small" type="button" onClick={() => setRenaming(null)}>Cancel</button>
|
||||
</form>
|
||||
) : (
|
||||
<div className="device-head">
|
||||
<i style={{ width: 12, height: 12, borderRadius: '50%', background: personColor(p.id).ring, display: 'inline-block', flex: 'none' }} />
|
||||
<b style={{ flex: 1 }}>{d.label}</b>
|
||||
</div>
|
||||
<>
|
||||
<div className="device-head">
|
||||
<i style={{ width: 12, height: 12, borderRadius: '50%', background: STATUS[d.health.status], display: 'inline-block', flex: 'none' }} />
|
||||
<b style={{ flex: 1 }}>{d.label}</b>
|
||||
<span className="muted">{STATUS_WORDS[d.health.status]}</span>
|
||||
</div>
|
||||
<span style={{ fontSize: 14, color: '#4A4560' }}>{healthLine(d.health)}</span>
|
||||
{d.health.held_secrets > 0 && (
|
||||
<span className="secret-note">{plural(d.health.held_secrets, 'note')} held back: possible secret, not shared. Its owner decides with <code>lunesync held</code>.</span>
|
||||
)}
|
||||
{d.health.holding && <span className="muted">A big change is held here, waiting for its owner to share or undo it.</span>}
|
||||
</>
|
||||
)}
|
||||
{canEditDevices && renaming?.id !== d.id && (
|
||||
<div className="chips">
|
||||
{d.health.waiting > 0 && (
|
||||
<button className="btn btn-small btn-primary" onClick={() => run(() => api.nudge(d.id), `Nudge sent to ${d.label}. It shares at its next check-in, as soon as it's online.`)}>Nudge</button>
|
||||
)}
|
||||
<button className="btn btn-small" onClick={() => setRenaming({ id: d.id, value: d.label })}>Rename</button>
|
||||
<button className="btn btn-small btn-danger" aria-label={`Remove device ${d.label}`} onClick={() => run(() => api.removeDevice(d.id), `${d.label} is removed. It sends anything unshared, then deletes its vault copies and stops working.`)}>Remove device</button>
|
||||
</div>
|
||||
@@ -710,10 +831,113 @@ function PersonPanel({ p, data, members, open, close, run }: {
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
{data.me.owner && !p.owner && !p.removed && !p.invited && (
|
||||
<div style={{ borderTop: '1px solid #EEEAF6', paddingTop: 16, display: 'flex', flexDirection: 'column', gap: 8 }}>
|
||||
<button className="btn btn-danger" style={{ alignSelf: 'flex-start' }} onClick={() => removeFromTeam(p)}>Remove from team</button>
|
||||
<p className="muted">Ends every vault and device for this person. The account is disabled and can be restored.</p>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/** A handover waiting for a manager: received work to review, or a device that hasn't reported in. */
|
||||
function HandoverCard({ h, vault, run }: { h: Vault['handovers'][number]; vault: Vault; run: (action: () => Promise<unknown>, ok?: string) => Promise<void> }) {
|
||||
const [files, setFiles] = useState<string[] | null>(null);
|
||||
if (h.state === 'waiting') {
|
||||
return (
|
||||
<div className="note">
|
||||
<b>{h.person} is leaving {vault.name}</b>
|
||||
<span>{h.device} hasn't reported in yet. Its unshared work comes to you when it's next online.</span>
|
||||
<button className="btn btn-small btn-danger" style={{ alignSelf: 'flex-start' }} onClick={() => run(() => api.handoverDecide(h.id, 'skip'), `${h.device} will delete its copy without sending anything.`)}>Delete without saving</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<div className="note amber">
|
||||
<b>{h.person}'s last changes from {h.device}</b>
|
||||
<span>These arrived in a final sync after the removal. Review before they join the vault.</span>
|
||||
{files === null ? (
|
||||
<button className="btn btn-small" style={{ alignSelf: 'flex-start' }} onClick={() => api.handoverShow(h.id).then(setFiles).catch(() => setFiles([]))}>Show changes</button>
|
||||
) : (
|
||||
<ul className="files">{files.map((f) => <li key={f}>{f}</li>)}</ul>
|
||||
)}
|
||||
<div className="chips">
|
||||
<button className="btn btn-small btn-primary" onClick={() => run(async () => (await api.handoverDecide(h.id, 'keep')).message, `Kept ${h.person}'s changes in ${vault.name}.`)}>Keep</button>
|
||||
<button className="btn btn-small" onClick={() => run(() => api.handoverDecide(h.id, 'discard'), `${h.person}'s handover was discarded.`)}>Discard</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** Both versions of a note side by side (J3); lines only in one version are highlighted. */
|
||||
function CompareDialog({ vault, copy, canEdit, close, resolve }: {
|
||||
vault: Vault; copy: string; canEdit: boolean; close: () => void; resolve: (keep: 'note' | 'copy' | 'both') => void;
|
||||
}) {
|
||||
const [c, setC] = useState<Comparison | null>(null);
|
||||
const [error, setError] = useState('');
|
||||
useEffect(() => { api.compare(vault.name, copy).then(setC).catch((e) => setError(e.message)); }, [vault, copy]);
|
||||
const column = (title: string, text: string | null, other: string | null, tint: string) => {
|
||||
const others = new Set((other ?? '').split('\n'));
|
||||
return (
|
||||
<div className="cmp-col">
|
||||
<div className="cmp-head">{title}</div>
|
||||
<div className="cmp-body">
|
||||
{text === null ? <span className="muted">Not shown (not a text note, or very large).</span>
|
||||
: text.split('\n').map((line, i) => <div key={i} style={others.has(line) ? undefined : { background: tint, margin: '0 -14px', padding: '0 14px' }}>{line || '\u00a0'}</div>)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
return (
|
||||
<div className="scrim" onPointerDown={(e) => { if (e.target === e.currentTarget) close(); }}>
|
||||
<div className="dialog wide" role="dialog" aria-modal="true" aria-label={`Compare versions of ${c?.note ?? copy}`}>
|
||||
<div><span className="eyebrow">{vault.name} · {c?.note ?? ''}</span><h2 className="disp">Two versions of the same lines</h2></div>
|
||||
{error && <p className="error">{error}</p>}
|
||||
{c && (
|
||||
<div className="cmp">
|
||||
{column(c.note_exists ? 'In the vault' : 'In the vault (removed since)', c.note_text, c.copy_text, '#FBEBD3')}
|
||||
{column(`${c.label}'s version · kept beside it`, c.copy_text, c.note_text, '#E8E1FB')}
|
||||
</div>
|
||||
)}
|
||||
{c && !canEdit && <p className="muted">You have read access, so you can look but not choose.</p>}
|
||||
<div className="actions">
|
||||
<button className="btn" onClick={close}>Keep both for now</button>
|
||||
{c && canEdit && (
|
||||
<>
|
||||
<button className="btn" onClick={() => resolve('both')}>Keep both as separate notes</button>
|
||||
{c.note_exists && <button className="btn" onClick={() => resolve('note')}>Keep the one in the vault</button>}
|
||||
<button className="btn btn-primary" onClick={() => resolve('copy')}>Keep {c.label}'s</button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** The only gesture on the canvas that asks first (X2, A8). */
|
||||
function TeamDialog({ p, data, members, close, confirm }: { p: Person; data: CanvasData; members: Member[]; close: () => void; confirm: () => void }) {
|
||||
const theirs = members.filter((m) => m.person === p.id).map((m) => data.vaults.find((v) => v.id === m.vault)?.name ?? '');
|
||||
const waiting = p.devices.reduce((n, d) => n + d.health.waiting, 0);
|
||||
return (
|
||||
<div className="scrim" onPointerDown={(e) => { if (e.target === e.currentTarget) close(); }}>
|
||||
<div className="dialog" role="dialog" aria-modal="true" aria-label={`Remove ${p.name} from the team?`}>
|
||||
<h2 className="disp">Remove {p.name} from the team?</h2>
|
||||
<p style={{ margin: 0, lineHeight: 1.5 }}>
|
||||
{p.name} is in {plural(theirs.length, 'vault')}{theirs.length ? ` (${theirs.join(', ')})` : ''} on {plural(p.devices.length, 'device')}. All access ends and every vault copy is deleted from those devices.
|
||||
</p>
|
||||
{waiting > 0 && <p className="warn-box">{plural(waiting, 'change')} haven't been shared yet. They'll be sent to the team for review before anything is deleted.</p>}
|
||||
<p className="muted">The account is disabled, not deleted, and can be restored. Past changes keep {p.name}'s name in history. Copies made elsewhere can't be recalled.</p>
|
||||
<div className="actions">
|
||||
<button className="btn" onClick={close}>Cancel</button>
|
||||
<button className="btn btn-primary" style={{ background: '#A52A2F', borderColor: '#A52A2F' }} onClick={confirm}>Remove from team</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function InviteDialog({ vaults, owner, close }: { vaults: Vault[]; owner: boolean; close: () => void }) {
|
||||
const [name, setName] = useState('');
|
||||
const [picked, setPicked] = useState<Set<string>>(new Set());
|
||||
|
||||
Reference in New Issue
Block a user