-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUpdateDebugModal.tsx
More file actions
104 lines (95 loc) · 3.54 KB
/
Copy pathUpdateDebugModal.tsx
File metadata and controls
104 lines (95 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { useEffect, useRef, useState } from 'react';
import {
ModalCloseButton,
ModalFrame,
modalActionButton,
modalReviewBlock,
} from '../../lib/src/components/design';
import { writeTextToClipboard } from 'dormouse-lib/lib/clipboard';
import { openIssueSearch } from './updater';
interface UpdateDebugModalProps {
onClose: () => void;
failure: { version: string; error?: string };
body: string | null;
}
export function UpdateDebugModal({ onClose, failure, body }: UpdateDebugModalProps) {
const closeButtonRef = useRef<HTMLButtonElement>(null);
const [copied, setCopied] = useState(false);
useEffect(() => {
if (!copied) return;
const id = setTimeout(() => setCopied(false), 2_000);
return () => clearTimeout(id);
}, [copied]);
const handleCopy = async () => {
if (!body) return;
if (await writeTextToClipboard(body)) setCopied(true);
else console.error('[updater] Failed to copy report');
};
const errorPreview = failure.error ?? '';
return (
<ModalFrame
titleId="update-debug-modal-title"
layer="app"
backdrop="strong"
elevation="modal"
padding="none"
overlayClassName="px-4 py-6"
className="flex max-h-[80vh] w-full max-w-[35rem] flex-col overflow-hidden"
initialFocusRef={closeButtonRef}
onEscape={onClose}
>
<div className="flex shrink-0 items-center justify-between border-b border-border bg-surface-raised px-4 py-3">
<h2 id="update-debug-modal-title" className="text-sm font-medium">
Update failed
</h2>
<ModalCloseButton ref={closeButtonRef} onClick={onClose} />
</div>
<div className="space-y-4 overflow-y-auto px-4 py-3">
<div className="space-y-1">
<p className="text-sm">
We couldn't install v{failure.version}. The error was:
</p>
<pre className={modalReviewBlock({ density: 'compact', overflow: 'short' })}>
{errorPreview || '(no error captured)'}
</pre>
</div>
<div className="space-y-1">
<p className="text-sm font-medium">1. Search existing reports</p>
<p className="text-xs text-muted">
Someone may have already hit this. A quick search saves a duplicate report.
</p>
<button
type="button"
onClick={() => openIssueSearch(errorPreview)}
className={modalActionButton({ tone: 'secondary' })}
>
Search GitHub issues
</button>
</div>
<div className="space-y-1">
<p className="text-sm font-medium">2. File a new bug</p>
<p className="text-xs text-muted">
If you can't find an existing bug, copy this report and paste it into a new issue.
</p>
<div className="flex items-center gap-2">
<button
type="button"
onClick={handleCopy}
disabled={!body}
className={modalActionButton({ tone: 'secondary' })}
>
Copy report
</button>
{copied && <span className="text-xs text-foreground">Copied</span>}
</div>
<textarea
readOnly
value={body ?? 'Gathering diagnostic info...'}
className="block h-48 w-full resize-y rounded border border-border bg-app-bg p-2 font-mono text-xs text-foreground focus-visible:outline focus-visible:outline-1 focus-visible:outline-focus-ring"
onFocus={(e) => e.currentTarget.select()}
/>
</div>
</div>
</ModalFrame>
);
}