diff --git a/src/component/block/blockUserList.js b/src/component/block/blockUserList.js new file mode 100644 index 0000000..99b9088 --- /dev/null +++ b/src/component/block/blockUserList.js @@ -0,0 +1,131 @@ +import React, {Component} from 'react'; +import {StyleSheet, Text, View, InteractionManager, FlatList, Alert} from 'react-native'; +import {Navigation} from 'react-native-navigation'; +import Ionicons from 'react-native-vector-icons/Ionicons'; + +import Touchable from '../touchable'; +import Color from '../../style/color'; +import Api from '../../util/api'; + +import UserIcon from '../userIcon'; +import Loading from '../loading'; +import {ListFooterEnd} from '../listFooter'; + + +export default class BlockUserList extends Component { + + constructor(props) { + super(props); + this.state = { + users: [], + isLoading: true + }; + } + + componentDidMount() { + InteractionManager.runAfterInteractions(() => { + this.refresh(); + }); + } + + _onDeletePress(user) { + Alert.alert('提示', '确定解除屏蔽?', [ + {text: '确定', style: 'destructive', onPress: () => { + Api.deleteUserBlock(user.id) + .then(() => { + let filterUsers = this.state.users.filter((it) => it.id !== user.id); + this.setState({ + users: filterUsers + }); + }) + .catch(e => { + Alert.alert('解除屏蔽失败'); + }); + }}, + {text: '取消', onPress: () => {}} + ]); + } + + refresh() { + Api.getBlockUsers() + .then(data => { + if (data) { + this.setState({ + users: data.users || [], + }); + } + }) + .catch(e => { + console.log('block user error:', e); + }) + .finally(() => { + this.setState({ + isLoading: false + }); + }); + } + + render() { + if (this.state.isLoading) { + return ; + } + + return ( + + { + return item.id ? item.id.toString() : index; + }} + + renderItem={({item}) => { + return ( + {}}> + + {}}> + {item.name} + this._onDeletePress(item)}> + + + + + ); + }} + + ListFooterComponent={() => } + /> + + ); + } +} + + +const localStyle = StyleSheet.create({ + container: { + flex: 1 + }, + list: { + height: '100%' + }, + box: { + flexDirection: 'row', + borderBottomWidth: 1, + borderColor: Color.line, + alignItems: 'center', + backgroundColor: 'white', + paddingLeft: 25 + }, + userName: { + flex: 1, + color: Color.text, + fontSize: 16 + }, + removeIcon: { + padding: 20 + } +}); diff --git a/src/component/diary/diaryList.js b/src/component/diary/diaryList.js index 15cb7ca..78e8ef4 100644 --- a/src/component/diary/diaryList.js +++ b/src/component/diary/diaryList.js @@ -122,6 +122,14 @@ export default class DiaryList extends Component { }); } + filter(blockUserId) { + let diaries = this.state.diaries; + let filtered = diaries.filter(d => d.user.id != blockUserId); + this.setState({ + diaries: filtered + }); + } + refreshOne(index, diary) { if(diary) { let list = this.state.diaries; diff --git a/src/component/userIntro.js b/src/component/userIntro.js index 6d4e000..5a9b157 100644 --- a/src/component/userIntro.js +++ b/src/component/userIntro.js @@ -1,14 +1,14 @@ import React, {Component} from 'react'; -import {StyleSheet, Text, View, ScrollView, InteractionManager} from 'react-native'; -import {Avatar} from "react-native-elements"; +import {StyleSheet, Text, View, ScrollView, InteractionManager, Alert} from 'react-native'; +import {Avatar, Button} from "react-native-elements"; import moment from 'moment'; import Color from '../style/color'; import Api from '../util/api'; import Msg from '../util/msg'; -import UserIcon from './userIcon' -import Loading from './loading' +import UserIcon from './userIcon'; +import Loading from './loading'; export default class UserIntro extends Component { @@ -18,37 +18,76 @@ export default class UserIntro extends Component { this.state = { user: props.user, + followed: 0, + isLoading: true }; } componentDidMount() { - Api.getSelfInfoByStore() - .then(user => { - this.selfInfo = user; - - InteractionManager.runAfterInteractions(() => { - this.refresh(); - }); - }); + InteractionManager.runAfterInteractions(() => { + this.refresh(); + }); } - refresh() { - let userId = this.state.user ? this.state.user.id : this.selfInfo.id; - Api.getUserInfo(userId) - .then(user => { + _onAddFollow() { + Api.addFollow(this.state.user.id) + .then(() => { this.setState({ - user: user + followed: 1 }); + + Alert.alert('已关注'); }) .catch(e => { - Msg.showMsg('用户信息加载失败'); + Alert.alert('关注失败'); }) - .finally(() => { + } + + _onDeleteFollow() { + Api.deleteFollow(this.state.user.id) + .then(() => { this.setState({ - isLoading: false + followed: -1, + }); + + Alert.alert('已取消关注'); + }) + .catch(e => { + Alert.alert('取消关注失败'); + }) + } + + refresh(userId) { + let targetId = userId; + if(!targetId) { + targetId = this.state.user ? this.state.user.id : null; + } + + if(targetId) { + Api.getUserInfo(targetId) + .then(user => { + this.setState({ + user: user + }); }) + .catch(e => { + Msg.showMsg('用户信息加载失败'); + }) + .finally(() => { + this.setState({ + isLoading: false + }) + }); + } + } + + refreshFollowed(followed = 0) { + if(followed) { + this.setState({ + followed: followed }); + } } render() { @@ -57,10 +96,34 @@ export default class UserIntro extends Component { } const user = this.state.user; + const followed = this.state.followed; + return user ? ( + + { + followed < 0 + ?