diff --git a/src/component/diary/diaryActionIcon.js b/src/component/diary/diaryActionIcon.js index 7e3cff3..47c9a88 100644 --- a/src/component/diary/diaryActionIcon.js +++ b/src/component/diary/diaryActionIcon.js @@ -1,7 +1,6 @@ import React, {Component} from 'react'; -import {StyleSheet, Text, View, TouchableOpacity, Alert} from 'react-native'; +import {StyleSheet, Text, View, TouchableOpacity} from 'react-native'; import Ionicons from 'react-native-vector-icons/Ionicons'; -import ActionSheet from 'react-native-actionsheet-api'; import Color from '../../style/color' @@ -9,27 +8,14 @@ import Color from '../../style/color' export default class DiaryActionIcon extends Component { _defaultOnPress() { - ActionSheet.showActionSheetWithOptions({ - options:['修改','删除', '取消'], - cancelButtonIndex: 2, - destructiveButtonIndex: 1 - - }, (index) => { - if(index === 0) { - - - } else if (index === 1) { - Alert.alert('提示', '确认删除日记?',[ - {text: '删除', style: 'destructive', onPress: () => {}}, - {text: '取消', onPress: () => {}}, - ]); - } - }); + } render() { return ( - + { this.editable - ? + ? : null } diff --git a/src/component/diary/diaryList.js b/src/component/diary/diaryList.js index 4e5f4f5..ce426b9 100644 --- a/src/component/diary/diaryList.js +++ b/src/component/diary/diaryList.js @@ -4,10 +4,13 @@ import { ActivityIndicator, StyleSheet, FlatList, - Text, View + Text, + View, + Alert } from 'react-native'; import {Navigation} from 'react-native-navigation'; import {Divider} from "react-native-elements"; +import ActionSheet from 'react-native-actionsheet-api'; import Color from '../../style/color'; import Msg from '../../util/msg'; @@ -23,7 +26,9 @@ export default class DiaryList extends Component { constructor(props) { super(props); + this.editable = props.editable || false; this.dataSource = props.dataSource; + this.state = { diaries: [], @@ -82,6 +87,38 @@ export default class DiaryList extends Component { }); } + _onDeleteDiary(diary) { + ActionSheet.showActionSheetWithOptions({ + options:['修改','删除', '取消'], + cancelButtonIndex: 2, + destructiveButtonIndex: 1 + + }, (index) => { + if(index === 0) { + + + } else if (index === 1) { + Alert.alert('提示', '确认删除日记?', [ + {text: '删除', style: 'destructive', onPress: () => { + Api.deleteDiary(diary.id) + .then(() => { + let filterDiaries = this.state.diaries.filter((it) => it.id !== diary.id); + this.setState({ + diaries: filterDiaries + }); + + Msg.showMsg('日记已删除'); + }) + .catch(e => { + Msg.showMsg('日记删除失败'); + }); + }}, + {text: '取消', onPress: () => {}}, + ]); + } + }); + } + async refresh() { if (this.state.refreshing) { return; @@ -173,7 +210,12 @@ export default class DiaryList extends Component { this._onDiaryPress(item)}> this._onUserIconPress(item)}> + editable={this.editable} + + onUserIconPress={() => this._onUserIconPress(item)} + onDeleteDiary={() => this._onDeleteDiary(item)} + > + ) @@ -204,6 +246,7 @@ export default class DiaryList extends Component { onEndReached={this.state.hasMore ? this.loadMore.bind(this) : null} > + ); } diff --git a/src/page/UserPage.js b/src/page/UserPage.js index 39206f5..70be938 100644 --- a/src/page/UserPage.js +++ b/src/page/UserPage.js @@ -71,6 +71,7 @@ export default class UserPage extends Component { />, diary: () => , notebook: () =>