-
Notifications
You must be signed in to change notification settings - Fork 311
/
Copy pathTextPadDrawer.tsx
87 lines (75 loc) · 2.23 KB
/
TextPadDrawer.tsx
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
// TextPadDrawer.tsx
import React, { useState } from "react";
import {
Drawer,
IconButton,
TextField,
Box,
Typography,
Button,
} from "@mui/material";
import { Close as CloseIcon, Save as SaveIcon } from "@mui/icons-material";
import { useUploadEnqueue } from "./app/transferQueue";
type TextPadDrawerProps = {
open: boolean;
setOpen: (open: boolean) => void;
cwd: string;
onUpload: () => void;
};
const TextPadDrawer = ({ open, setOpen, cwd, onUpload }: TextPadDrawerProps) => {
const [noteTitle, setNoteTitle] = useState("");
const [noteContent, setNoteContent] = useState("");
const uploadEnqueue = useUploadEnqueue();
const handleSaveAndUpload = async () => {
if (!noteTitle.trim() || !noteContent.trim()) return;
const file = new File([noteContent], `${noteTitle}.txt`, {
type: "text/plain",
});
uploadEnqueue({ file, basedir: cwd });
// Reset fields and close drawer
setNoteTitle("");
setNoteContent("");
setOpen(false);
onUpload(); // Refresh file list
};
return (
<Drawer anchor="right" open={open} onClose={() => setOpen(false)}>
<Box sx={{ width: 400, padding: 3 }}>
<Box display="flex" justifyContent="space-between" alignItems="center">
<Typography variant="h6">TextPad</Typography>
<IconButton onClick={() => setOpen(false)}>
<CloseIcon />
</IconButton>
</Box>
<TextField
label="Note Title"
fullWidth
variant="outlined"
margin="normal"
value={noteTitle}
onChange={(e) => setNoteTitle(e.target.value)}
/>
<TextField
label="Write your note"
fullWidth
multiline
rows={12}
variant="outlined"
margin="normal"
value={noteContent}
onChange={(e) => setNoteContent(e.target.value)}
/>
<Button
variant="contained"
startIcon={<SaveIcon />}
fullWidth
sx={{ mt: 2 }}
onClick={handleSaveAndUpload}
>
Save & Upload
</Button>
</Box>
</Drawer>
);
};
export default TextPadDrawer;