added show directory picker and added its state · javascriptdata/dnotebook@9606e18 · GitHub
Skip to content

Commit 9606e18

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

6 files changed

Lines changed: 62 additions & 24 deletions

File tree

‎src/frontend/components/IconMenu/file.tsx‎

Lines changed: 14 additions & 5 deletions

‎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

0 commit comments

Comments
 (0)