Skip to content

Commit 636cb86

Browse files
committed
Add download notebook feature
1 parent 59510b9 commit 636cb86

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

src/frontend/components/IconMenu/file.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,18 @@ import ListItemText from "@mui/material/ListItemText";
1111
import ListItemIcon from "@mui/material/ListItemIcon";
1212
import Typography from "@mui/material/Typography";
1313
import Paper from '@mui/material/Paper';
14-
import { openFile, openNewFile, saveNotebookToFileSystem } from "../../lib/FileSystem/fileSystem";
15-
import { addNotebook, setActiveNotebookTabNumber, updateActiveNotebookName, setNotebookIsSaving } from "../../lib/state/reducer"
14+
import {
15+
openFile,
16+
openNewFile,
17+
saveNotebookToFileSystem,
18+
downloadAsNewNotebook,
19+
} from "../../lib/FileSystem/fileSystem";
20+
import {
21+
addNotebook,
22+
setActiveNotebookTabNumber,
23+
updateActiveNotebookName,
24+
setNotebookIsSaving
25+
} from "../../lib/state/reducer"
1626
import { useDispatch, useSelector } from 'react-redux';
1727
import { AppState } from '../../lib/typings/types';
1828

@@ -45,6 +55,12 @@ export default function FileMenu() {
4555
dispatch(setNotebookIsSaving(false))
4656
}
4757

58+
const downloadActiveNotebook = async () => {
59+
const currentNotebook = {...notebooks[activeNotebookName]}
60+
await downloadAsNewNotebook(currentNotebook)
61+
}
62+
63+
4864
return (
4965
<Paper sx={{ width: 320, maxWidth: '100%' }}>
5066
<MenuList>
@@ -84,7 +100,7 @@ export default function FileMenu() {
84100
⌘S
85101
</Typography>
86102
</MenuItem>
87-
<MenuItem>
103+
<MenuItem onClick={() => downloadActiveNotebook()}>
88104
<ListItemIcon>
89105
<SaveAltIcon fontSize="small" />
90106
</ListItemIcon>

src/frontend/lib/FileSystem/fileSystem.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,22 @@ export const saveNotebookToFileSystem = async (fileHandle, contents) => {
174174
await writable.close();
175175

176176
}
177+
178+
export const downloadAsNewNotebook = async (notebook) => {
179+
const fileHandle = await window.showSaveFilePicker({
180+
types: [
181+
{
182+
description: 'notebooks',
183+
accept: {
184+
'text/plain': ['.dnb'],
185+
}
186+
},
187+
],
188+
excludeAcceptAllOption: true,
189+
multiple: false
190+
});
191+
const fileMetaData = await fileHandle.getFile();
192+
notebook.name = fileMetaData.name;
193+
await saveNotebookToFileSystem(fileHandle, JSON.stringify(notebook));
194+
}
195+

0 commit comments

Comments
 (0)