mirror of
https://github.com/timepill/timepill-app.git
synced 2025-04-30 09:59:31 +08:00
1. 删除今天日记
This commit is contained in:
parent
d862735d6f
commit
912cf0cabb
5 changed files with 59 additions and 23 deletions
|
@ -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 (
|
||||
<TouchableOpacity onPress={this.props.onPress ? this.props.onPress : this._defaultOnPress.bind(this)}>
|
||||
<TouchableOpacity onPress={
|
||||
this.props.onPress ? this.props.onPress : this._defaultOnPress.bind(this)
|
||||
}>
|
||||
<Ionicons name="ios-more"
|
||||
size={24}
|
||||
color={Color.inactiveText}
|
||||
|
|
|
@ -76,7 +76,8 @@ export default class DiaryBrief extends Component {
|
|||
<View style={{flex: 1}} />
|
||||
{
|
||||
this.editable
|
||||
? <DiaryActionIcon></DiaryActionIcon>
|
||||
? <DiaryActionIcon diaryId={diary.id}
|
||||
onPress={this.props.onDeleteDiary}></DiaryActionIcon>
|
||||
: null
|
||||
}
|
||||
</View>
|
||||
|
|
|
@ -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 {
|
|||
<Touchable onPress={() => this._onDiaryPress(item)}>
|
||||
<DiaryBrief diary={item}
|
||||
showField={this.props.showField}
|
||||
onUserIconPress={() => this._onUserIconPress(item)}>
|
||||
editable={this.editable}
|
||||
|
||||
onUserIconPress={() => this._onUserIconPress(item)}
|
||||
onDeleteDiary={() => this._onDeleteDiary(item)}
|
||||
>
|
||||
|
||||
</DiaryBrief>
|
||||
</Touchable>
|
||||
)
|
||||
|
@ -204,6 +246,7 @@ export default class DiaryList extends Component {
|
|||
onEndReached={this.state.hasMore ? this.loadMore.bind(this) : null}
|
||||
>
|
||||
</FlatList>
|
||||
<ActionSheet/>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -71,6 +71,7 @@ export default class UserPage extends Component {
|
|||
/>,
|
||||
diary: () => <DiaryList
|
||||
dataSource={this.dataSource}
|
||||
editable={!this.user}
|
||||
{...this.props}
|
||||
/>,
|
||||
notebook: () => <NotebookList
|
||||
|
|
|
@ -120,6 +120,9 @@ async function getMessagesHistory() {
|
|||
return call('GET', '/tip/history');
|
||||
}
|
||||
|
||||
async function deleteDiary(id) {
|
||||
return call('DELETE', '/diaries/' + id);
|
||||
}
|
||||
|
||||
|
||||
async function call(method, api, body, _timeout = 10000) {
|
||||
|
@ -227,5 +230,7 @@ export default {
|
|||
deleteFollow,
|
||||
deleteFollowBy,
|
||||
|
||||
getMessagesHistory
|
||||
getMessagesHistory,
|
||||
|
||||
deleteDiary
|
||||
}
|
Loading…
Reference in a new issue