diff --git a/src/component/dateInput.js b/src/component/dateInput.js index e556885..35f0c80 100644 --- a/src/component/dateInput.js +++ b/src/component/dateInput.js @@ -22,7 +22,7 @@ export default class DateInput extends Component { this.updateDate(); this.state = { - date: this.formatDate(this.nowDate) + date: this.minDate }; } @@ -36,11 +36,11 @@ export default class DateInput extends Component { this.nowDate = now(); let nowMSec = this.nowDate.getTime(); - let minExpiredMSec = 7 * 24 * 3600000; // at least 7 days to expire + let minExpiredMSec = 8 * 24 * 3600000; // at least 7 days to expire let minExpiredDate = new Date(nowMSec + minExpiredMSec); this.minDate = this.formatDate(minExpiredDate); - let maxExpiredMSec = 3650 * 24 * 3600000; // at most 10 years to expire + let maxExpiredMSec = 364 * 24 * 3600000; // at most 1 years to expire let maxExpireDate = new Date(nowMSec + maxExpiredMSec); this.maxDate = this.formatDate(maxExpireDate); } diff --git a/src/component/diary/diaryIconComment.js b/src/component/diary/diaryIconComment.js index eb8ddd1..5ad8b65 100644 --- a/src/component/diary/diaryIconComment.js +++ b/src/component/diary/diaryIconComment.js @@ -16,13 +16,15 @@ export default class DiaryIconComment extends Component { } render() { - return this.state.count > 0 ? ( + return ( <View style={localStyle.wrap}> <Ionicons name="ios-text-outline" size={18} style={localStyle.icon} /> - <Text style={localStyle.text}>{this.state.count}</Text> + <Text style={localStyle.text}> + {this.state.count > 0 ? this.state.count : ''} + </Text> </View> - ) : null; + ); } } diff --git a/src/component/diary/diaryIconOkB.js b/src/component/diary/diaryIconOkB.js index 5c96ba2..6a042ba 100644 --- a/src/component/diary/diaryIconOkB.js +++ b/src/component/diary/diaryIconOkB.js @@ -80,12 +80,16 @@ export default class DiaryIconOkB extends Component { style={localStyle.icon} /> - <Text style={[localStyle.text, { - color: !this.state.active - ? Color.inactiveText - : Color.primary - }]} - >{this.state.count > 0 ? this.state.count : ''}</Text> + { + this.state.count > 0 ? + <Text style={[localStyle.text, { + color: !this.state.active + ? Color.inactiveText + : Color.primary + }]} + >{this.state.count}</Text> + : null + } </View> </TouchableOpacity> ); @@ -101,8 +105,7 @@ const localStyle = StyleSheet.create({ icon: { width: 18, height: 18, - marginLeft: 4, - marginRight: 1 + marginLeft: 4 }, text: { fontSize: 15, diff --git a/src/page/WritePage.js b/src/page/WritePage.js index a2b9783..bb88d35 100644 --- a/src/page/WritePage.js +++ b/src/page/WritePage.js @@ -13,6 +13,7 @@ import { DeviceEventEmitter, Alert, Image, + InteractionManager, SafeAreaView } from 'react-native'; import {Navigation} from 'react-native-navigation'; @@ -105,8 +106,25 @@ export default class WritePage extends Component { } componentDidMount() { - this.loadNotebook(); - this.contentInput.focus(); + this.loadNotebook().then(notebookCount => { + if(notebookCount > 0) { + setTimeout(() => { + this.contentInput.focus(); + }, 500); + + } else { + Alert.alert('提示', '没有可用日记本,无法写日记',[ + {text: '取消', onPress: () => {}}, + {text: '创建一个', onPress: () => { + Navigation.push(this.props.componentId, { + component: { + name: 'NotebookEdit' + } + }); + }} + ]); + } + }); this.notebookListener = DeviceEventEmitter.addListener(Event.updateNotebooks, (param) => { this.loadNotebook(true); @@ -120,12 +138,6 @@ export default class WritePage extends Component { openModal() { this.contentInput.blur(); this.setState({modalVisible: true}); - - if(this.state.notebooks.length == 0) { - Alert.alert('提示', '没有可用日记本,无法写日记', [ - {text: '确定', onPress: () => {}} - ]); - } } closeModal(showKeyboard = true, callback) { @@ -185,29 +197,27 @@ export default class WritePage extends Component { }); } - loadNotebook(resetTargetbook = false) { - Api.getSelfNotebooks() - .then(notebooks => { - if (!notebooks || !notebooks.filter) { - notebooks = []; - } + async loadNotebook(resetTargetbook = false) { + let notebooks = await Api.getSelfNotebooks(); + if(!notebooks || !notebooks.filter) { + notebooks = []; + } - let unExpiredBooks = notebooks.filter(it => !it.isExpired); - if (unExpiredBooks.length > 0) { - let st = { - notebooks: unExpiredBooks - } + let unExpiredBooks = notebooks.filter(it => !it.isExpired);unExpiredBooks=[]; + if(unExpiredBooks && unExpiredBooks.length > 0) { + let st = { + notebooks: unExpiredBooks + } - if (resetTargetbook || this.state.targetbookId == 0) { - st.targetbookId = unExpiredBooks[0].id; - st.targetbookSubject = unExpiredBooks[0].subject; - } + if(resetTargetbook || this.state.targetbookId == 0) { + st.targetbookId = unExpiredBooks[0].id; + st.targetbookSubject = unExpiredBooks[0].subject; + } - this.setState(st); - } + this.setState(st); + } - }) - .catch((err) => { console.error(err) }) + return unExpiredBooks && unExpiredBooks.length > 0 ? unExpiredBooks.length : 0; } _onPickPhoto() { @@ -262,6 +272,29 @@ export default class WritePage extends Component { return; } + if(this.state.targetbookId == 0) { + if(this.state.notebooks.length == 0) { + this.contentInput.blur(); + Alert.alert('提示', '没有可用日记本,无法写日记',[ + {text: '取消', onPress: () => {}}, + {text: '创建一个', onPress: () => { + Navigation.push(this.props.componentId, { + component: { + name: 'NotebookEdit' + } + }); + }} + ]); + + } else { + Alert.alert('提示', '选择一个日记本先',[ + {text: '确定', onPress: () => this.openModal()} + ]); + } + + return; + } + let photoUri = this.state.photoUri; let topic = this.props.topic ? 1 : 0; @@ -431,9 +464,13 @@ export default class WritePage extends Component { <Animated.View style={{height: this.state.fadeAnimHeight, backgroundColor: '#fff'}}> <View style={localStyle.modalBanner}> - <TouchableOpacity onPress={this._onCreateNotebook.bind(this)} style={localStyle.modalButton}> - <Text style={localStyle.modalButtonText}>新添</Text> - </TouchableOpacity> + { + !this.diary ? + <TouchableOpacity onPress={this._onCreateNotebook.bind(this)} style={localStyle.modalButton}> + <Text style={localStyle.modalButtonText}>新添</Text> + </TouchableOpacity> : <Text/> + } + <Text style={{padding: 10, color: Color.text}}>选择日记本</Text> <TouchableOpacity onPress={this.closeModal.bind(this)} style={localStyle.modalButton}> <Text style={localStyle.modalButtonText}>取消</Text>