fix adding notebook

This commit is contained in:
ammarahm-ed
2020-09-14 22:59:19 +05:00
parent 1cfe909323
commit e9f515aa30

View File

@@ -114,7 +114,6 @@ export class AddNotebookDialog extends React.Component {
};
addNewNotebook = async () => {
let {topics} = this.state;
let edit = this.props.toEdit;
@@ -130,10 +129,7 @@ export class AddNotebookDialog extends React.Component {
let prevTopics = [...topics];
if (
this.currentInputValue &&
this.currentInputValue.trim().length !== 0
) {
if (this.currentInputValue && this.currentInputValue.trim().length !== 0) {
if (this.prevItem != null) {
prevTopics[this.prevIndex] = this.currentInputValue;
} else {
@@ -142,7 +138,7 @@ export class AddNotebookDialog extends React.Component {
}
}
if (id) {
if (this.topicsToDelete.length > 0) {
if (this.topicsToDelete?.length > 0) {
await db.notebooks
.notebook(toEdit.id)
.topics.delete(...this.topicsToDelete);
@@ -155,7 +151,6 @@ export class AddNotebookDialog extends React.Component {
id: id,
});
let nextTopics = toEdit.topics.map((topic, index) => {
if (index === 0) return topic;
let copy = {...topic};
@@ -169,7 +164,7 @@ export class AddNotebookDialog extends React.Component {
nextTopics.push(title);
}
});
console.log(nextTopics,prevTopics,toEdit.topics,"HERE");
console.log(nextTopics, prevTopics, toEdit.topics, 'HERE');
await db.notebooks.notebook(id).topics.add(...nextTopics);
} else {
await db.notebooks.add({
@@ -179,17 +174,16 @@ export class AddNotebookDialog extends React.Component {
id: id,
});
}
//this.close();
this.close();
updateEvent({type: ACTIONS.NOTEBOOKS});
updateEvent({type: ACTIONS.PINNED});
ToastEvent.show('New notebook added', 'success', 'local');
//ToastEvent.show('New notebook added', 'success', 'local');
};
onSubmit = (forward = true) => {
let {topics} = this.state;
if (!this.currentInputValue || this.currentInputValue.trim().length === 0)
if (!this.currentInputValue || this.currentInputValue?.trim().length === 0)
return;
let prevTopics = [...topics];
@@ -385,7 +379,7 @@ export class AddNotebookDialog extends React.Component {
color: colors.pri,
width: '85%',
maxWidth: '85%',
marginTop:5
marginTop: 5,
},
]}
placeholder="Add a new topic"