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
+ ?
+ : (
+ followed > 0
+ ?
+ : null
+ )
+ }
+
{user.name}
@@ -89,6 +152,14 @@ const localStyle = StyleSheet.create({
alignItems: 'center',
justifyContent: 'center'
},
+ followButton: {
+ width: 100,
+ height: 30,
+ marginTop: 20,
+ marginRight: 3,
+ paddingTop: 5,
+ paddingBottom: 5,
+ },
userTitle: {
fontSize: 22,
marginTop: 30,
diff --git a/src/page/BlockUserPage.js b/src/page/BlockUserPage.js
new file mode 100644
index 0000000..74605a9
--- /dev/null
+++ b/src/page/BlockUserPage.js
@@ -0,0 +1,49 @@
+import React, {Component} from 'react';
+import {StyleSheet, Text, View} from 'react-native';
+
+import BlockUserList from '../component/block/blockUserList';
+
+
+export default class BlockUserPage extends Component {
+
+ constructor(props) {
+ super(props);
+ this.state = {
+
+ };
+ }
+
+ static options(passProps) {
+ return {
+ topBar: {
+ title: {
+ text: '屏蔽'
+ }
+ },
+ statusBar: {
+ backgroundColor: 'white',
+ style: 'dark'
+ }
+ };
+ }
+
+ render() {
+ return (
+
+ this.list = r}
+ {...this.props}
+ >
+
+ );
+ }
+}
+
+
+const localStyle = StyleSheet.create({
+ wrap: {
+ flex: 1,
+ backgroundColor: '#fff',
+ paddingTop: 1
+ }
+});
+
diff --git a/src/page/FollowPage.js b/src/page/FollowPage.js
index 55ef5e5..b7bf76c 100644
--- a/src/page/FollowPage.js
+++ b/src/page/FollowPage.js
@@ -1,8 +1,9 @@
import React, {Component} from 'react';
-import {StyleSheet, Text, View} from 'react-native';
+import {StyleSheet, Text, View, DeviceEventEmitter} from 'react-native';
import {Navigation} from 'react-native-navigation';
import Api from '../util/api';
+import Event from "../util/event";
import {Icon} from '../style/icon';
import Color from '../style/color';
@@ -64,6 +65,15 @@ export default class FollowPage extends Component {
}
}
);
+
+ this.blockUserListener = DeviceEventEmitter.addListener(Event.userBlocked, (param) => {
+ this.diaryList.filter(param.blockUserId);
+ });
+ }
+
+ componentWillUnmount() {
+ this.bottomTabEventListener.remove();
+ this.blockUserListener.remove();
}
render() {
diff --git a/src/page/FollowUserPage.js b/src/page/FollowUserPage.js
index cd31998..692a6ca 100644
--- a/src/page/FollowUserPage.js
+++ b/src/page/FollowUserPage.js
@@ -1,5 +1,5 @@
import React, {Component} from 'react';
-import {StyleSheet, Text, View, Animated} from 'react-native';
+import {StyleSheet, Text, View, Animated, DeviceEventEmitter} from 'react-native';
import {
PagerScroll,
TabView,
@@ -8,7 +8,9 @@ import {
} from 'react-native-tab-view';
import Api from '../util/api';
+import Event from "../util/event";
import Color from '../style/color';
+
import FollowUserList from '../component/follow/followUserList'
import FollowingUserData from '../dataLoader/followingUserData'
import FollowedByUserData from '../dataLoader/followedByUserData'
@@ -44,6 +46,21 @@ export default class FollowUserPage extends Component {
};
}
+ componentDidMount() {
+ this.blockUserListener = DeviceEventEmitter.addListener(Event.userBlocked, (param) => {
+ if (this.followingList) {
+ this.followingList.refresh();
+ }
+ if (this.folloedByList) {
+ this.folloedByList.refresh();
+ }
+ });
+ }
+
+ componentWillUnmount() {
+ this.blockUserListener.remove();
+ }
+
_renderLabel = props => ({route}) => {
let routes = props.navigationState.routes;
let index = props.navigationState.index;
@@ -72,14 +89,14 @@ export default class FollowUserPage extends Component {
};
_renderScene = SceneMap({
- following: () => this.followingList = r}
listType={'followingUser'} dataSource={new FollowingUserData()}
onDeletePress={async (id) => {
return Api.deleteFollow(id);
}}
{...this.props}
/>,
- followedBy: () => this.followedByList = r}
listType={'followedByUser'} dataSource={new FollowedByUserData()}
onDeletePress={async (id) => {
return Api.deleteFollowBy(id);
diff --git a/src/page/HomePage.js b/src/page/HomePage.js
index 94ac2eb..af5a2f6 100644
--- a/src/page/HomePage.js
+++ b/src/page/HomePage.js
@@ -9,7 +9,8 @@ import {
Modal,
TouchableWithoutFeedback,
InteractionManager,
- StatusBar
+ StatusBar,
+ DeviceEventEmitter,
} from 'react-native';
import {Navigation} from 'react-native-navigation';
import {Button} from 'react-native-elements';
@@ -18,6 +19,7 @@ import ActionSheet from 'react-native-actionsheet-api';
import Color from '../style/color'
import Api from '../util/api';
import Update from '../util/update';
+import Event from '../util/event'
import DiaryList from '../component/diary/diaryList'
import HomeDiaryData from '../dataLoader/homeDiaryData';
@@ -76,10 +78,15 @@ export default class HomePage extends Component {
Update.updateAndroid();
}, 2000);
}
+
+ this.blockUserListener = DeviceEventEmitter.addListener(Event.userBlocked, (param) => {
+ this.diaryList.filter(param.blockUserId);
+ });
}
componentWillUnmount() {
this.bottomTabEventListener.remove();
+ this.blockUserListener.remove();
}
startTimer() {
diff --git a/src/page/SettingPage.js b/src/page/SettingPage.js
index 9e5b8ac..2d8d6d0 100644
--- a/src/page/SettingPage.js
+++ b/src/page/SettingPage.js
@@ -179,6 +179,13 @@ export default class SettingPage extends Component {
{/**/}
+
+ this.jumpTo('BlockUser')}>
+ 屏蔽
+
+
+
+
{
Api.IS_IOS ? (
diff --git a/src/page/TopicPage.js b/src/page/TopicPage.js
index 173161a..15d623b 100644
--- a/src/page/TopicPage.js
+++ b/src/page/TopicPage.js
@@ -61,10 +61,14 @@ export default class TopicPage extends Component {
this.diaryListener = DeviceEventEmitter.addListener(Event.updateDiarys, (param) => {
this.diaryList.refresh();
});
+ this.blockUserListener = DeviceEventEmitter.addListener(Event.userBlocked, (param) => {
+ this.diaryList.filter(param.blockUserId);
+ });
}
componentWillUnmount() {
this.diaryListener.remove();
+ this.blockUserListener.remove();
}
render() {
diff --git a/src/page/UserPage.js b/src/page/UserPage.js
index 2456fc2..5d36fe0 100644
--- a/src/page/UserPage.js
+++ b/src/page/UserPage.js
@@ -8,6 +8,7 @@ import {
} from 'react-native-tab-view';
import {Navigation} from 'react-native-navigation';
+import Msg from '../util/msg';
import Api from '../util/api';
import {Icon} from '../style/icon';
import Event from "../util/event";
@@ -48,8 +49,8 @@ export default class UserPage extends Component {
text: passProps.user.name
},
rightButtons: [{
- id: 'followIcon',
- icon: Icon.navButtonFollow
+ id: 'navButtonMore',
+ icon: Icon.navButtonMore
}]
},
statusBar: {
@@ -76,41 +77,26 @@ export default class UserPage extends Component {
}
navigationButtonPressed({buttonId}) {
- if(buttonId == 'followIcon') {
- Api.addFollow(this.userId)
- .then(() => {
- Navigation.mergeOptions(this.props.componentId, {
- topBar: {
- rightButtons: [{
- id: 'navButtonFollowSelected',
- icon: Icon.navButtonFollowSelected
- }]
- }
- });
+ if(buttonId == 'navButtonMore') {
+ ActionSheet.showActionSheetWithOptions({
+ options: ['屏蔽', '取消'],
+ cancelButtonIndex: 1,
+ destructiveButtonIndex: 0
- Alert.alert('已关注');
- })
- .catch(e => {
- Alert.alert('关注失败');
- })
-
- } else if(buttonId == 'navButtonFollowSelected') {
- Api.deleteFollow(this.userId)
- .then(() => {
- Navigation.mergeOptions(this.props.componentId, {
- topBar: {
- rightButtons: [{
- id: 'followIcon',
- icon: Icon.navButtonFollow
- }]
- }
- });
-
- Alert.alert('已取消关注');
- })
- .catch(e => {
- Alert.alert('取消关注失败');
- })
+ }, (index) => {
+ if(index == 0) {
+ Api.addUserBlock(this.userId)
+ .then(() => {
+ DeviceEventEmitter.emit(Event.userBlocked, {blockUserId: this.userId});
+ Navigation.popToRoot(this.props.componentId);
+ Msg.showMsg('该用户已被屏蔽');
+ })
+ .catch(e => {
+ console.log('block error:', e);
+ Alert.alert('屏蔽失败');
+ });
+ }
+ });
} else if(buttonId == 'setting') {
Navigation.push(this.props.componentId, {
@@ -131,36 +117,27 @@ export default class UserPage extends Component {
}
componentDidMount() {
- if(this.userId) {
- Api.getSelfInfoByStore()
- .then(user => {
- if(user && user.id == this.userId) {
- Navigation.mergeOptions(this.props.componentId, {
- topBar: {
- rightButtons: [{
- id: 'setting',
- icon: Icon.navButtonSetting
- }]
- }
+ Api.getSelfInfoByStore()
+ .then(user => {
+ if(!this.userId || (user && user.id == this.userId)) {
+ this.userIntro.refresh(user.id);
+ Navigation.mergeOptions(this.props.componentId, {
+ topBar: {
+ rightButtons: [{
+ id: 'setting',
+ icon: Icon.navButtonSetting
+ }]
+ }
+ });
+
+ } else {
+ Api.getRelation(this.userId)
+ .then(re => {
+ this.followed = re ? 1 : -1;
+ this.userIntro.refreshFollowed(this.followed);
});
- } else {
- Api.getRelation(this.userId)
- .then(re => {
- this.followed = re;
- if(this.followed) {
- Navigation.mergeOptions(this.props.componentId, {
- topBar: {
- rightButtons: [{
- id: 'navButtonFollowSelected',
- icon: Icon.navButtonFollowSelected
- }]
- }
- });
- }
- });
- }
- });
- }
+ }
+ });
this.notebookListener = DeviceEventEmitter.addListener(Event.updateNotebooks, (param) => {
this.notebookList.refresh();
diff --git a/src/page/_list.js b/src/page/_list.js
index 8f0bda3..9b10544 100644
--- a/src/page/_list.js
+++ b/src/page/_list.js
@@ -1,24 +1,25 @@
export default {
- About: require("./AboutPage.js").default,
- DiaryDetail: require("./DiaryDetailPage.js").default,
- Empty: require("./EmptyPage.js").default,
- Feedback: require("./FeedbackPage.js").default,
- Follow: require("./FollowPage.js").default,
- FollowUser: require("./FollowUserPage.js").default,
- Home: require("./HomePage.js").default,
- NotebookDetail: require("./NotebookDetailPage.js").default,
- NotebookEdit: require("./NotebookEditPage.js").default,
- NotebookMerge: require("./NotebookMergePage.js").default,
- NotificationHistory: require("./NotificationHistoryPage.js").default,
- Notification: require("./NotificationPage.js").default,
- Password: require("./PasswordPage.js").default,
- Photo: require("./PhotoPage.js").default,
- Setting: require("./SettingPage.js").default,
- Topic: require("./TopicPage.js").default,
- UserInfoEdit: require("./UserInfoEditPage.js").default,
- UserIntroEdit: require("./UserIntroEditPage.js").default,
- UserNameEdit: require("./UserNameEditPage.js").default,
- User: require("./UserPage.js").default,
- WebView: require("./WebViewPage.js").default,
- Write: require("./WritePage.js").default
+About: require("./AboutPage.js").default,
+BlockUser: require("./BlockUserPage.js").default,
+DiaryDetail: require("./DiaryDetailPage.js").default,
+Empty: require("./EmptyPage.js").default,
+Feedback: require("./FeedbackPage.js").default,
+Follow: require("./FollowPage.js").default,
+FollowUser: require("./FollowUserPage.js").default,
+Home: require("./HomePage.js").default,
+NotebookDetail: require("./NotebookDetailPage.js").default,
+NotebookEdit: require("./NotebookEditPage.js").default,
+NotebookMerge: require("./NotebookMergePage.js").default,
+NotificationHistory: require("./NotificationHistoryPage.js").default,
+Notification: require("./NotificationPage.js").default,
+Password: require("./PasswordPage.js").default,
+Photo: require("./PhotoPage.js").default,
+Setting: require("./SettingPage.js").default,
+Topic: require("./TopicPage.js").default,
+UserInfoEdit: require("./UserInfoEditPage.js").default,
+UserIntroEdit: require("./UserIntroEditPage.js").default,
+UserNameEdit: require("./UserNameEditPage.js").default,
+User: require("./UserPage.js").default,
+WebView: require("./WebViewPage.js").default,
+Write: require("./WritePage.js").default
}
\ No newline at end of file
diff --git a/src/util/api.js b/src/util/api.js
index 22422e8..76d8d22 100644
--- a/src/util/api.js
+++ b/src/util/api.js
@@ -369,16 +369,16 @@ async function getUpdateInfo() {
}
async function addUserBlock(user_id) {
- return call('POST', `blocks/${user_id}`);
+ return call('POST', `/blocks/${user_id}`);
}
async function deleteUserBlock(user_id) {
- return call('DELETE', `blocks/${user_id}`);
+ return call('DELETE', `/blocks/${user_id}`);
}
async function getBlockUsers() {
- return call('GET', `blocks`);
+ return call('GET', `/blocks`);
}
export async function updatePushInfo() {
diff --git a/src/util/event.js b/src/util/event.js
index d9641d3..531b7a0 100644
--- a/src/util/event.js
+++ b/src/util/event.js
@@ -7,5 +7,7 @@ export default {
commentPressed: 'commentPressed',
passwordUpdated: 'passwordUpdated',
updateNewsRead: 'updateNewsRead',
- userInfoUpdated: 'userInfoUpdated'
+ userInfoUpdated: 'userInfoUpdated',
+
+ userBlocked: 'userBlocked',
}
\ No newline at end of file