Skip to content

Commit 9606e18

Browse files
committed
added show directory picker and added its state
1 parent 18e98e7 commit 9606e18

File tree

6 files changed

+62
-24
lines changed

6 files changed

+62
-24
lines changed

src/frontend/components/IconMenu/file.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import * as React from 'react';
2+
import { useDispatch } from "react-redux";
3+
import { setDirectories } from "../../lib/state/reducer";
24
import Divider from '@mui/material/Divider';
35
import Paper from '@mui/material/Paper';
46
import MenuList from '@mui/material/MenuList';
@@ -10,25 +12,32 @@ import ContentCut from '@mui/icons-material/ContentCut';
1012
import ContentCopy from '@mui/icons-material/ContentCopy';
1113
import ContentPaste from '@mui/icons-material/ContentPaste';
1214
import Cloud from '@mui/icons-material/Cloud';
15+
import { openFile, openFolder } from "../../lib/utils/fileSystem";
1316

1417
export default function FileMenu() {
18+
const dispatch = useDispatch();
19+
async function onFolderSelect() {
20+
const folders = await openFolder();
21+
console.log(folders);
22+
dispatch(setDirectories(folders))
23+
}
1524
return (
16-
<Paper sx={{ width: 320, maxWidth: '100%' }}>
25+
<Paper sx={{ width: 320, maxWidth: "100%" }}>
1726
<MenuList>
18-
<MenuItem>
27+
<MenuItem onClick={() => openFile()}>
1928
<ListItemIcon>
2029
<ContentCut fontSize="small" />
2130
</ListItemIcon>
22-
<ListItemText>Cut</ListItemText>
31+
<ListItemText>Open File</ListItemText>
2332
<Typography variant="body2" color="text.secondary">
2433
⌘X
2534
</Typography>
2635
</MenuItem>
27-
<MenuItem>
36+
<MenuItem onClick={() => onFolderSelect()}>
2837
<ListItemIcon>
2938
<ContentCopy fontSize="small" />
3039
</ListItemIcon>
31-
<ListItemText>Copy</ListItemText>
40+
<ListItemText>Open Folder</ListItemText>
3241
<Typography variant="body2" color="text.secondary">
3342
⌘C
3443
</Typography>

src/frontend/lib/state/reducer.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ const initialState: AppState = {
2424
cellShowLineNumbers: false,
2525
cellTabSize: 2,
2626
width: "100%",
27-
}
27+
},
28+
directories: [],
2829
}
2930

3031
const appReducer = createSlice({
@@ -43,6 +44,9 @@ const appReducer = createSlice({
4344
updateConfig: (state, action) => {
4445
state.config = action.payload;
4546
},
47+
setDirectories: (state, action) => {
48+
state.directories = action.payload;
49+
}
4650
}
4751
});
4852

@@ -51,6 +55,7 @@ export const {
5155
updateCellIds,
5256
updateCells,
5357
updateConfig,
58+
setDirectories,
5459
} = appReducer.actions;
5560

5661
export default appReducer.reducer;

src/frontend/lib/state/store.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
import { configureStore } from "@reduxjs/toolkit";
1+
import { configureStore, getDefaultMiddleware } from "@reduxjs/toolkit";
22
import appReducer from "./reducer";
33

44
const store = configureStore({
5-
reducer: {
6-
app: appReducer
7-
}
5+
devTools: true,
6+
reducer: {
7+
app: appReducer,
8+
},
9+
middleware: (getDefaultMiddleware) =>
10+
getDefaultMiddleware({
11+
serializableCheck: false,
12+
}),
813
});
914

1015
export default store;

src/frontend/lib/typings/types.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ export type NbCell = {
1818
outputError?: any;
1919
}
2020

21+
export type DirectoryObj = {
22+
key: string,
23+
value: Object,
24+
}
25+
2126
export type Notebook = {
2227
cellIds: string[];
2328
cells: {
@@ -53,6 +58,7 @@ export type AppState = {
5358
cellIds: string[];
5459
cells: {
5560
[key: string]: NbCell
56-
}
61+
},
62+
directories: DirectoryObj[],
5763
config: Partial<NotebookConfig>;
5864
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export async function openFile() {
2+
let [fileHandle] = await window.showOpenFilePicker();
3+
console.log(fileHandle.kind);
4+
}
5+
6+
export async function openFolder() {
7+
const directoryHandle = await window.showDirectoryPicker();
8+
let dirs = [];
9+
for await (const [key, value] of directoryHandle.entries()) {
10+
dirs.push({ key, value });
11+
}
12+
return dirs;
13+
}

src/frontend/pages/index.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,31 @@ const Home: NextPage = () => {
1717
<link rel="icon" href="/favicon.ico" />
1818
</Head>
1919

20-
<div className='flex-row'>
20+
<div className="flex-row">
2121
<section>
2222
<NavBar />
2323
</section>
2424
<section>
2525
<MenuBar />
2626
</section>
27-
28-
<section style={{ height: "650px" }} className='grid grid-cols-12 p-2 overflow-y-scroll'>
29-
<div className='fixed'>
27+
<section className="flex p-2 border-r-2 overflow-y-scroll">
28+
<div className="fixed flex-none">
3029
<SideBar />
3130
</div>
32-
<div className='col-span-12 border-l-2 ml-60'>
33-
{
34-
cellIds.map((cellId: string, i: number) => {
35-
const cell: NbCell = cells[cellId]
36-
return <div key={cellId}><NoteBookCell cell={cell} /></div>
37-
})
38-
}
31+
<div className=" flex-1 w-64 col-span-12 ml-60">
32+
{cellIds.map((cellId: string, i: number) => {
33+
const cell: NbCell = cells[cellId];
34+
return (
35+
<div key={cellId}>
36+
<NoteBookCell cell={cell} />
37+
</div>
38+
);
39+
})}
3940
</div>
40-
4141
</section>
4242
</div>
4343
</div>
44-
)
44+
);
4545
}
4646

4747
export default Home

0 commit comments

Comments
 (0)