修复写日记问题

This commit is contained in:
mx1700 2019-08-04 21:17:11 +08:00
parent 9c6346f9eb
commit 9dd231c41a

View file

@ -274,26 +274,31 @@ export default class WritePage extends Component {
} }
saveDiary() { saveDiary() {
if(!this.state.content) { if (!this.state.content) {
return; return;
} }
if(this.state.targetbookId == 0) { if (this.state.targetbookId == 0) {
if(this.state.notebooks.length == 0) { if (this.state.notebooks.length == 0) {
this.contentInput.blur(); this.contentInput.blur();
Alert.alert('提示', '没有可用日记本,无法写日记',[ Alert.alert('提示', '没有可用日记本,无法写日记', [
{text: '取消', onPress: () => {}}, {
{text: '创建一个', onPress: () => { text: '取消', onPress: () => {
Navigation.push(this.props.componentId, { }
component: { },
name: 'NotebookEdit' {
} text: '创建一个', onPress: () => {
}); Navigation.push(this.props.componentId, {
}} component: {
name: 'NotebookEdit'
}
});
}
}
]); ]);
} else { } else {
Alert.alert('提示', '选择一个日记本先',[ Alert.alert('提示', '选择一个日记本先', [
{text: '确定', onPress: () => this.openModal()} {text: '确定', onPress: () => this.openModal()}
]); ]);
} }
@ -312,36 +317,17 @@ export default class WritePage extends Component {
}); });
(this.diary (this.diary
? Api.updateDiary(this.diary.id, this.state.targetbookId, this.state.content) ? Api.updateDiary(this.diary.id, this.state.targetbookId, this.state.content)
: Api.addDiary(this.state.targetbookId, this.state.content, photoUri, topic) : Api.addDiary(this.state.targetbookId, this.state.content, photoUri, topic)
).then(result => { ).then(result => {
Msg.hideMsg(waitingToast); Msg.hideMsg(waitingToast);
Msg.showMsg('日记保存完成'); Msg.showMsg('日记保存完成');
DeviceEventEmitter.emit(Event.updateDiarys); DeviceEventEmitter.emit(Event.updateDiarys);
this.closePage();
if(this.diary || this.topic) { }).catch(e => {
Navigation.pop(this.props.componentId); Msg.hideMsg(waitingToast);
Msg.showMsg('保存失败');
} else { });
Navigation.setStackRoot(this.props.componentId, {
component: {
name: 'Empty',
options: {
bottomTabs: {
visible: true
}
},
passProps: {
from: 'write'
}
}
});
}
})
.catch(e => {
Msg.hideMsg(waitingToast);
Msg.showMsg('保存失败');
})
} }
render() { render() {