forked from Dimillian/CodexMonitor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMobileRemoteWorkspacePrompt.tsx
More file actions
100 lines (96 loc) · 3.14 KB
/
MobileRemoteWorkspacePrompt.tsx
File metadata and controls
100 lines (96 loc) · 3.14 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
import { useEffect, useRef } from "react";
import { ModalShell } from "../../design-system/components/modal/ModalShell";
type MobileRemoteWorkspacePromptProps = {
value: string;
error: string | null;
recentPaths: string[];
onChange: (value: string) => void;
onRecentPathSelect: (path: string) => void;
onCancel: () => void;
onConfirm: () => void;
};
export function MobileRemoteWorkspacePrompt({
value,
error,
recentPaths,
onChange,
onRecentPathSelect,
onCancel,
onConfirm,
}: MobileRemoteWorkspacePromptProps) {
const textareaRef = useRef<HTMLTextAreaElement | null>(null);
const focusTextareaAtEnd = () => {
const textarea = textareaRef.current;
if (!textarea) {
return;
}
textarea.focus();
const end = textarea.value.length;
textarea.setSelectionRange(end, end);
};
useEffect(() => {
focusTextareaAtEnd();
}, []);
return (
<ModalShell
ariaLabel="Add remote workspace paths"
className="mobile-remote-workspace-modal"
cardClassName="mobile-remote-workspace-modal-card"
onBackdropClick={onCancel}
>
<div className="mobile-remote-workspace-modal-content">
<div className="ds-modal-title">Add project directories</div>
<div className="ds-modal-subtitle">
Enter directories on the connected server.
</div>
<label className="ds-modal-label" htmlFor="mobile-remote-workspace-paths">
Paths
</label>
<textarea
id="mobile-remote-workspace-paths"
ref={textareaRef}
className="ds-modal-textarea"
value={value}
onChange={(event) => onChange(event.target.value)}
placeholder={"/home/vlad/dev/project-one\n/home/vlad/dev/project-two"}
rows={4}
wrap="off"
/>
<div className="mobile-remote-workspace-modal-hint">
One path per line. Comma and semicolon separators also work. You can use `~/...`.
</div>
{recentPaths.length > 0 && (
<div className="mobile-remote-workspace-modal-recent">
<div className="mobile-remote-workspace-modal-recent-title">Recently added</div>
<div className="mobile-remote-workspace-modal-recent-list">
{recentPaths.map((path) => (
<button
key={path}
type="button"
className="mobile-remote-workspace-modal-recent-item"
onClick={() => {
onRecentPathSelect(path);
requestAnimationFrame(() => {
focusTextareaAtEnd();
});
}}
>
{path}
</button>
))}
</div>
</div>
)}
{error && <div className="ds-modal-error">{error}</div>}
<div className="ds-modal-actions">
<button className="ghost ds-modal-button" onClick={onCancel} type="button">
Cancel
</button>
<button className="primary ds-modal-button" onClick={onConfirm} type="button">
Add
</button>
</div>
</div>
</ModalShell>
);
}