mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 15:09:33 +01:00
fix topic and notebook editing
This commit is contained in:
@@ -114,12 +114,17 @@ export class AddNotebookDialog extends React.Component {
|
|||||||
let id = toEdit && toEdit.id ? toEdit.id : null;
|
let id = toEdit && toEdit.id ? toEdit.id : null;
|
||||||
|
|
||||||
let t = [...topics];
|
let t = [...topics];
|
||||||
|
console.log(this.prevIndex, this.prevItem);
|
||||||
if (
|
if (
|
||||||
this.currentInputValue &&
|
this.currentInputValue &&
|
||||||
this.currentInputValue.trim().length !== 0
|
this.currentInputValue.trim().length !== 0
|
||||||
) {
|
) {
|
||||||
t.push(this.currentInputValue);
|
if (this.prevItem != null) {
|
||||||
this.currentInputValue = null;
|
t[this.prevIndex] = this.currentInputValue;
|
||||||
|
} else {
|
||||||
|
t.push(this.currentInputValue);
|
||||||
|
this.currentInputValue = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (id) {
|
if (id) {
|
||||||
await db.notebooks.add({
|
await db.notebooks.add({
|
||||||
@@ -127,9 +132,16 @@ export class AddNotebookDialog extends React.Component {
|
|||||||
description: this.description,
|
description: this.description,
|
||||||
id: id,
|
id: id,
|
||||||
});
|
});
|
||||||
console.log(t);
|
let allTopics = toEdit.topics;
|
||||||
await db.notebooks.notebook(id).topics.add(...t);
|
t.forEach((title, index) => {
|
||||||
|
if (allTopics[index]) {
|
||||||
|
allTopics[index].title = title;
|
||||||
|
} else {
|
||||||
|
allTopics.push(title);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
console.log(allTopics);
|
||||||
|
await db.notebooks.notebook(id).topics.add(...allTopics);
|
||||||
} else {
|
} else {
|
||||||
await db.notebooks.add({
|
await db.notebooks.add({
|
||||||
title: this.title,
|
title: this.title,
|
||||||
@@ -146,7 +158,7 @@ export class AddNotebookDialog extends React.Component {
|
|||||||
}, 100);
|
}, 100);
|
||||||
};
|
};
|
||||||
|
|
||||||
onSubmit = () => {
|
onSubmit = (forward = true) => {
|
||||||
let {topics} = this.state;
|
let {topics} = this.state;
|
||||||
if (!this.currentInputValue || this.currentInputValue.trim().length === 0)
|
if (!this.currentInputValue || this.currentInputValue.trim().length === 0)
|
||||||
return;
|
return;
|
||||||
@@ -171,7 +183,7 @@ export class AddNotebookDialog extends React.Component {
|
|||||||
topics: prevTopics,
|
topics: prevTopics,
|
||||||
});
|
});
|
||||||
this.currentInputValue = null;
|
this.currentInputValue = null;
|
||||||
if (prevTopics[this.prevIndex + 1]) {
|
if (prevTopics[this.prevIndex + 1] && forward) {
|
||||||
this.prevIndex = this.prevIndex + 1;
|
this.prevIndex = this.prevIndex + 1;
|
||||||
this.prevItem = prevTopics[this.prevIndex];
|
this.prevItem = prevTopics[this.prevIndex];
|
||||||
this.currentInputValue = this.prevItem;
|
this.currentInputValue = this.prevItem;
|
||||||
@@ -188,9 +200,11 @@ export class AddNotebookDialog extends React.Component {
|
|||||||
this.topicInputRef.setNativeProps({
|
this.topicInputRef.setNativeProps({
|
||||||
text: null,
|
text: null,
|
||||||
});
|
});
|
||||||
setTimeout(() => {
|
if (forward) {
|
||||||
this.listRef.scrollToEnd({animated: true});
|
setTimeout(() => {
|
||||||
}, 30);
|
this.listRef.scrollToEnd({animated: true});
|
||||||
|
}, 30);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -301,7 +315,7 @@ export class AddNotebookDialog extends React.Component {
|
|||||||
<TextInput
|
<TextInput
|
||||||
ref={ref => (this.descriptionRef = ref)}
|
ref={ref => (this.descriptionRef = ref)}
|
||||||
style={{
|
style={{
|
||||||
padding: pv -2 ,
|
padding: pv - 2,
|
||||||
borderWidth: 1.5,
|
borderWidth: 1.5,
|
||||||
borderColor: descFocused ? colors.accent : colors.nav,
|
borderColor: descFocused ? colors.accent : colors.nav,
|
||||||
paddingHorizontal: ph,
|
paddingHorizontal: ph,
|
||||||
@@ -364,7 +378,7 @@ export class AddNotebookDialog extends React.Component {
|
|||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
onBlur={() => {
|
onBlur={() => {
|
||||||
this.onSubmit();
|
this.onSubmit(false);
|
||||||
this.setState({
|
this.setState({
|
||||||
topicInputFoused: false,
|
topicInputFoused: false,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -27,6 +27,9 @@ export class AddTopicDialog extends React.Component {
|
|||||||
if (!this.props.toEdit) {
|
if (!this.props.toEdit) {
|
||||||
await db.notebooks.notebook(this.props.notebookID).topics.add(this.title);
|
await db.notebooks.notebook(this.props.notebookID).topics.add(this.title);
|
||||||
} else {
|
} else {
|
||||||
|
let topic = this.props.toEdit;
|
||||||
|
topic.title = this.title;
|
||||||
|
await db.notebooks.notebook(this.props.notebookID).topics.add(topic);
|
||||||
}
|
}
|
||||||
this.close();
|
this.close();
|
||||||
ToastEvent.show('New topic added', 'success');
|
ToastEvent.show('New topic added', 'success');
|
||||||
|
|||||||
Reference in New Issue
Block a user