Skip to content

Commit 9bd173f

Browse files
committed
refactor: 💄 Added note title on note upload
1 parent dc85e23 commit 9bd173f

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

src/components/header/header.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from "react";
1+
import React, { useState } from "react";
22
// eslint-disable-next-line import/no-extraneous-dependencies
33
import PropTypes from "prop-types";
44
import { CgSoftwareDownload, CgMathPlus } from "react-icons/cg";
@@ -12,11 +12,19 @@ import {
1212
} from "./header.style";
1313

1414
export default function Header({ download, load }) {
15+
const [noteName, setNoteName] = useState("untitled.ipynb");
16+
const onNoteTitleChange = (e) => {
17+
setNoteName(e);
18+
};
1519
return (
1620
<HeaderContainer>
1721
<div></div>
1822
<NoteEditContainer>
19-
<NoteTitle type="text" value="untitled.ipynb" />
23+
<NoteTitle
24+
onChange={(e) => onNoteTitleChange(e.target.value)}
25+
type="text"
26+
value={noteName}
27+
/>
2028
<div>
2129
<AddNoteLabel htmlFor="import-notebook-file">
2230
{" "}
@@ -29,7 +37,11 @@ export default function Header({ download, load }) {
2937
<AddNoteInput
3038
type="file"
3139
id="import-notebook-file"
32-
onChange={() => load()}
40+
onChange={() => {
41+
const fileName = load();
42+
const name = `${fileName.split(".")[0]}.ipynb`;
43+
onNoteTitleChange(name);
44+
}}
3345
/>
3446
</div>
3547
</NoteEditContainer>

src/index.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,7 @@ a{
3030
color: #36c5ce;
3131
text-decoration: none;
3232
}
33+
34+
input:focus{
35+
outline: none !important;
36+
}

src/reducer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// eslint-disable-next-line consistent-return
33
export const reducer = (state, action) => {
44
if (action.type === "CHANGE_CELL") {
5-
console.log(state);
65
const stateCells = state.cells.map((cell) => {
76
if (cell.id === action.payload.id) {
87
return action.payload;
@@ -36,6 +35,7 @@ export const reducer = (state, action) => {
3635
}
3736

3837
if (action.type === "LOAD_NOTE") {
38+
// console.log(action.payload);
3939
return { ...state, cells: action.payload };
4040
}
4141
};

src/utils.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ const load_package = async (array, callback) => {
196196
};
197197

198198
export const load_notebook = (dispatch) => {
199+
let fileName = null;
199200
const { files } = document.getElementById("import-notebook-file");
200201
let json_content = null;
201202
if (files.length > 0) {
@@ -207,7 +208,9 @@ export const load_notebook = (dispatch) => {
207208
dispatch({ type: "LOAD_NOTE", payload: json });
208209
};
209210
reader.readAsText(content);
211+
fileName = content.name;
210212
}
213+
return fileName;
211214
};
212215
/**
213216
* Returns the id of the current cell's output div

0 commit comments

Comments
 (0)