Authored by 王钱钧

完善个人中心功能。 code review by 于良

... ... @@ -41,8 +41,10 @@ import HomeContainer from './containers/HomeContainer';
import SectionContainer from './containers/SectionContainer';
import UserContainer from './containers/UserContainer';
import UserThatNotMeContainer from './containers/UserThatNotMeContainer';
import MessageCenterContainer from './containers/MessageCenterContainer';
import SubjectPostContainer from './containers/SubjectPostContainer';
import PostingContainer from './containers/PostingContainer';
import SettingContainer from './containers/UserSettingContainer';
import NavBar from './components/NavBar';
... ... @@ -201,6 +203,22 @@ export default function community(platform) {
/>
<Scene
key="MessageCenter"
title="消息"
hideNavBar={false}
component={MessageCenterContainer}
initial={false}
/>
<Scene
key="Setting"
title="社区资料"
hideNavBar={false}
component={SettingContainer}
initial={false}
/>
<Scene
key="UserThatNotMe"
title="用户中心"
hideNavBar={true}
... ...
... ... @@ -45,6 +45,7 @@ export default class CommunityList extends React.Component {
likeCount: React.PropTypes.number,
}),
),
onPressPost: React.PropTypes.func,
};
constructor(props) {
... ... @@ -63,20 +64,20 @@ export default class CommunityList extends React.Component {
<ListCell
key={sectionID + rowID}
data={rowData}
onPressPost={(url) => {
this.props.onPressPost && this.props.onPressPost(url);
onPressPost={() => {
this.props.onPressPost && this.props.onPressPost(rowData.get('id'));
}}
onPressAvatar={(url) => {
this.props.onPressAvatar && this.props.onPressAvatar(url);
}}
onPressSectionTag={(url) => {
this.props.onPressSectionTag && this.props.onPressSectionTag(url);
onPressSectionTag={() => {
this.props.onPressSectionTag && this.props.onPressSectionTag(rowData.get('section').toJS());
}}
onPressComment={(url) => {
this.props.onPressComment && this.props.onPressComment(url);
onPressComment={() => {
this.props.onPressComment && this.props.onPressComment(rowData.get('id'));
}}
onPressLike={(url) => {
this.props.onPressLike && this.props.onPressLike(url);
onPressLike={() => {
this.props.onPressLike && this.props.onPressLike(rowData);
}}
/>
);
... ...
... ... @@ -87,22 +87,26 @@ export default class MessageCenter extends React.Component {
}
}
/*
<ListView
dataSource={this.dataSource.cloneWithRowsAndSections(dataSource)}
renderRow={this._renderRow}
renderSeparator={this._renderSeparator}
/>
*/
render() {
let {system, like, message,} = this.props;
let dataSource = {
system: this.props.system.toArray(),
like: this.props.like.toArray(),
message: this.props.message.toArray(),
};
// let dataSource = {
// system: this.props.system.toArray(),
// like: this.props.like.toArray(),
// message: this.props.message.toArray(),
// };
return (
<View style={styles.container}>
<ListView
dataSource={this.dataSource.cloneWithRowsAndSections(dataSource)}
renderRow={this._renderRow}
renderSeparator={this._renderSeparator}
/>
</View>
);
... ...
'use strict';
import React from 'react';
import ReactNative from 'react-native';
import ImmutablePropTypes from 'react-immutable-proptypes';
// import SlicedImage from '../../../common/components/SlicedImage';
const {
View,
Text,
Image,
TouchableOpacity,
StyleSheet,
Dimensions,
} = ReactNative;
export default class MessageIcon extends React.Component {
static propTypes = {
msgCount: React.PropTypes.string,
iconTap: React.PropTypes.func,
}
constructor(props) {
super (props);
}
renderMsgCount() {
if (parseInt(this.props.msgCount) !== 0) {
return (
<View style={styles.textContainer}>
<Text style={styles.text}>{this.props.msgCount}</Text>
</View>
);
} else {
return null;
}
}
render() {
return (
<View style={[styles.container, this.props.extraStyle]}>
<TouchableOpacity activeOpacity={0.8} onPress={() => {
this.props.iconTap && this.props.iconTap();
}}>
<Image
style={styles.icon}
source={require('../../images/user/message.png')}
/>
{this.renderMsgCount()}
</TouchableOpacity>
</View>
);
}
}
let styles = StyleSheet.create ({
container: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
backgroundColor: 'transparent',
width: 32,
height: 23,
},
icon: {
},
textContainer: {
position: 'absolute',
top: -10,
right: -8,
height: 18,
borderRadius: 9,
borderColor: 'red',
borderWidth: 1,
justifyContent: 'center',
alignItems: 'center',
opacity: 0.9,
backgroundColor: 'white',
flexDirection:'row',
},
text: {
fontSize: 12,
color: 'red',
textAlign: 'center',
marginHorizontal: 6,
marginVertical: 6,
backgroundColor: 'transparent',
},
});
... ...
... ... @@ -17,78 +17,103 @@ const {
export default class ReplyCell extends React.Component {
static propTypes = {
data: ImmutablePropTypes.contains({
id: React.PropTypes.number,
postId: React.PropTypes.number,
createTime: React.PropTypes.number.isRequired,
authorUid: React.PropTypes.number,
// 帖子
postInfo: ImmutablePropTypes.contains({
title: React.PropTypes.string,
type: React.PropTypes.string.isRequired,
}),
// 回复的内容
blocks: ImmutablePropTypes.listOf(
ImmutablePropTypes.contains({
commentId: React.PropTypes.number,
orderBy: React.PropTypes.number,
content: React.PropTypes.string,
templateKey: React.PropTypes.string.isRequired,
})
),
// 我的信息
reply: ImmutablePropTypes.contains({
headIcon: React.PropTypes.string,
data: ImmutablePropTypes.contains({
self: ImmutablePropTypes.contains({
avatar: React.PropTypes.string,
uid: React.PropTypes.number,
name: React.PropTypes.string,
backgroundImage: React.PropTypes.string,
}),
// 被回复者信息
replyTo: ImmutablePropTypes.contains({
headIcon: React.PropTypes.string,
createTime: React.PropTypes.string.isRequired,
replyToUser: ImmutablePropTypes.contains({
avatar: React.PropTypes.string,
uid: React.PropTypes.number,
name: React.PropTypes.string,
backgroundImage: React.PropTypes.string,
}),
replyContent: ImmutablePropTypes.contains({
thumbs: ImmutablePropTypes.listOf(
ImmutablePropTypes.contains({
src: React.PropTypes.string,
})
),
desc: React.PropTypes.string,
}),
postInfo: ImmutablePropTypes.contains({
type:React.PropTypes.string.isRequired,
title:React.PropTypes.string,
postId:React.PropTypes.string,
}),
}),
onPressAvatar: React.PropTypes.func,
onPressReply: React.PropTypes.func,
onPressPosts: React.PropTypes.func,
}),
// TODO 添加点击事件
};
constructor(props) {
super(props);
this._renderReplyContent = this._renderReplyContent.bind(this);
this._renderPostInfo = this._renderPostInfo.bind(this);
}
_renderReplyContent(replyContent) {
if (replyContent.desc === '') {
return (
<Image
source = {require('../../images/user/default-pic.png')}
/>
);
} else {
return (
<Text>
{replyContent.desc}
</Text>
);
}
}
_renderPostInfo(postInfo) {
if (postInfo.type === 'image') {
return (
<Image
source = {require('../../images/user/default-pic.png')}
/>
);
} else {
return (
<Text>
{postInfo.title}
</Text>
);
}
}
render() {
let data = this.props.data.toJS();
let {
id,
postId,
self,
replyToUser,
replyContent,
createTime,
authorUid,
postInfo,
blocks,
reply,
replyTo,
} = data;
return (
<View style={styles.container}>
<View style={styles.topContainer}>
<UserBrief
avatar={reply.headIcon}
name={reply.name}
avatar={self.avatar}
name={self.name}
timeago={createTime.toString()}
// isOwner={isOwner}
onPressAvatar={() => {
this.props.onPressAvatar && this.props.onPressAvatar();
}}
... ... @@ -105,12 +130,12 @@ export default class ReplyCell extends React.Component {
this.props.onPressReply && this.props.onPressReply();
}}
>
小草莓
{replyToUser.name}
</Text>
:如果你无法表单房间诶哦我就佛大发了瓦解偶发的拉萨减肥劳动局撒了附件二范德萨范德萨
:{this._renderReplyContent(replyContent)}
</Text>
</View>
... ... @@ -124,7 +149,7 @@ export default class ReplyCell extends React.Component {
this.props.onPressPosts && this.props.onPressPosts();
}}
>
帖子:港南爱上米彩妆,看叫啥呢我发的是fdsafdsafdsafdasfd剪短发搜富哦为福建省的
帖子:{this._renderPostInfo(postInfo)}
</Text>
</View>
... ...
... ... @@ -35,15 +35,15 @@ export default class ReplyList extends React.Component {
// onPressPost={(url) => {
// this.props.onPressPost && this.props.onPressPost(url);
// }}
onPressAvatar={(url) => {
this.props.onPressAvatar && this.props.onPressAvatar(url);
onPressAvatar={() => {
this.props.onPressAvatar && this.props.onPressAvatar();
}}
onPressReply={(url) => {
this.props.onPressReply && this.props.onPressReply(url);
onPressReply={() => {
this.props.onPressReply && this.props.onPressReply(rowData.get('replyToUser').get('uid'));
}}
onPressPosts={(url) => {
this.props.onPressPosts && this.props.onPressPosts(url);
onPressPosts={() => {
this.props.onPressPosts && this.props.onPressPosts(rowData.get('postInfo').get('postId'));
}}
// onPressLike={(url) => {
// this.props.onPressLike && this.props.onPressLike(url);
... ...
... ... @@ -26,6 +26,10 @@ const {
Animated,
} = ReactNative;
let {width, height} = Dimensions.get('window');
let navbarHeight = (Platform.OS === 'android') ? 50 : 64;
let userBgHieght = Math.ceil((490 / 750) * width);
export default class User extends React.Component {
static propTypes = {
... ... @@ -35,6 +39,7 @@ export default class User extends React.Component {
backgroundImage:React.PropTypes.string,
nickName:React.PropTypes.string.isRequired,
sign: React.PropTypes.string,
msgCount:React.PropTypes.number,
}),
list: ImmutablePropTypes.listOf(
... ... @@ -94,23 +99,38 @@ export default class User extends React.Component {
reply: ImmutablePropTypes.listOf(
ImmutablePropTypes.contains({
reply: ImmutablePropTypes.contains({
headIcon: React.PropTypes.string,
self: ImmutablePropTypes.contains({
avatar: React.PropTypes.string,
uid: React.PropTypes.number,
name: React.PropTypes.string,
backgroundImage: React.PropTypes.string,
}),
replyTo: ImmutablePropTypes.contains({
headIcon: React.PropTypes.string,
createTime: React.PropTypes.string.isRequired,
replyToUser: ImmutablePropTypes.contains({
avatar: React.PropTypes.string,
uid: React.PropTypes.number,
name: React.PropTypes.string,
backgroundImage: React.PropTypes.string,
}),
id: React.PropTypes.number,
postId: React.PropTypes.number,
createTime: React.PropTypes.number.isRequired,
authorUid: React.PropTypes.number,
})
replyContent: ImmutablePropTypes.contains({
thumbs: ImmutablePropTypes.listOf(
ImmutablePropTypes.contains({
src: React.PropTypes.string,
})
),
desc: React.PropTypes.string,
}),
postInfo: ImmutablePropTypes.contains({
type:React.PropTypes.string.isRequired,
title:React.PropTypes.string,
postId:React.PropTypes.string,
}),
}),
),
... ... @@ -122,7 +142,7 @@ export default class User extends React.Component {
onPressAvatar: React.PropTypes.func,
onPressComment: React.PropTypes.func,
onPressLike: React.PropTypes.func,
onPressPosts: React.PropTypes.func,
onPressPost: React.PropTypes.func,
onEndReached: React.PropTypes.func,
onRefresh: React.PropTypes.func,
};
... ... @@ -199,6 +219,7 @@ export default class User extends React.Component {
}
_renderRow(rowData, sectionID, rowID, highlightRow) {
switch (sectionID) {
case 'userInfo':
return (
... ... @@ -248,8 +269,8 @@ export default class User extends React.Component {
onPressReply={(url) => {
this.props.onPressReply && this.props.onPressReply(url);
}}
onPressPosts={(url) => {
this.props.onPressPosts && this.props.onPressPosts(url);
onPressPost={() => {
this.props.onPressPosts && this.props.onPressPosts();
}}
/>
... ... @@ -296,14 +317,23 @@ export default class User extends React.Component {
_updateVerticalScrollValue(offsetY) {
this.state.scrollValueV.setValue(offsetY/150);
this.state.listViewMarginTop.setValue(offsetY/150);
let delta = userBgHieght-navbarHeight;
this.state.scrollValueV.setValue(offsetY/delta);
// this.state.listViewMarginTop =
if (offsetY >= delta) {
this.state.listViewMarginTop.setValue(navbarHeight);
} else {
this.state.listViewMarginTop.setValue(offsetY);
}
// this.state.scrollValueV.setValue(offsetY/150);
// this.state.listViewMarginTop.setValue(offsetY/150);
}
render() {
let {userInfo, list, user, endReached, isRefreshing, isLoadingMore, isFetching} = this.props;
let dataSource = {
userInfo: userInfo.toArray(),
list: list.toArray(),
... ... @@ -315,6 +345,7 @@ export default class User extends React.Component {
this.animView = c;
}}
style={{flex:1, backgroundColor: 'transparent', top: this.state.listViewTop}}
>
<ListView
ref={(c) => {
... ... @@ -353,15 +384,21 @@ export default class User extends React.Component {
/>
</Animated.View>
<UserNavBar scrollValue={this.state.scrollValueV} channel={this.props.channel}/>
<UserNavBar
scrollValue={this.state.scrollValueV}
channel={this.props.channel}
hasRightButton={true}
msgCount={this.props.profile.msgCount}
rightButtonClick={this.props.rightButtonClick}
/>
</View>
);
}
}
let {width, height} = Dimensions.get('window');
let navbarHeight = (Platform.OS === 'android') ? 50 : 64;
let styles = StyleSheet.create({
container: {
... ...
... ... @@ -15,6 +15,7 @@ const {
TouchableHighlight,
} = ReactNative;
export default class UserCenterTop extends React.Component {
static propTypes = {
... ... @@ -80,11 +81,11 @@ export default class UserCenterTop extends React.Component {
let {width, height} = Dimensions.get('window');
let navbarHeight = (Platform.OS === 'android') ? 50 : 64;
let containerHieght = Math.ceil((490 / 750) * width);
let styles = StyleSheet.create({
container: {
height: 244,
height: containerHieght,
backgroundColor: 'transparent',
},
... ...
... ... @@ -16,6 +16,7 @@ import {
} from 'react-native';
import {Actions} from 'react-native-router-flux';
import _backButtonImage from '../../images/home/menu_back1.png';
import MessageIcon from './MessageIcon'
const styles = StyleSheet.create({
header: {
... ... @@ -35,6 +36,7 @@ const styles = StyleSheet.create({
// borderBottomWidth: 0.5,
// borderBottomColor: '#828287',
position: 'absolute',
},
backButton: {
width: 60,
... ... @@ -61,6 +63,20 @@ const styles = StyleSheet.create({
width: Dimensions.get('window').width,
height: (Platform.OS === 'android') ? 50 : 64,
},
rightButton: {
position: 'absolute',
...Platform.select({
ios: {
top: 22+8,
},
android: {
top: 10+8,
},
}),
right: 15,
}
});
const propTypes = {
... ... @@ -81,6 +97,7 @@ class UserNavBar extends React.Component {
super(props);
this.renderBackButton = this.renderBackButton.bind(this);
this.renderRightButton = this.renderRightButton.bind(this);
this.setAnimationValue = this.setAnimationValue.bind(this);
this.headerColor = this.headerColor.bind(this);
}
... ... @@ -137,6 +154,19 @@ class UserNavBar extends React.Component {
);
}
renderRightButton() {
if(this.props.hasRightButton) {
return (
<MessageIcon
extraStyle={styles.rightButton}
msgCount={this.props.msgCount}
iconTap={this.props.rightButtonClick}
/>);
} else {
return null;
}
}
getNavBarBackgroundImage(channel) {
let img = require('../../images/nav/boy/navbar_bg.png');
switch (parseInt(channel)) {
... ... @@ -176,6 +206,7 @@ class UserNavBar extends React.Component {
</Image>
{this.renderBackButton()}
{this.renderRightButton()}
</Animated.View>
);
}
... ...
... ... @@ -21,6 +21,7 @@ export default keyMirror({
GO_TO_LIKE_MESSAGE: null,
GO_TO_POST: null,
HOME_BNS_REQUEST: null,
HOME_BNS_SUCCESS: null,
HOME_BNS_FAILURE: null,
... ... @@ -67,6 +68,9 @@ export default keyMirror({
USER_REPLY_SUCCESS: null,
USER_REPLY_FAILURE: null,
USER_UNREAD_REQUEST: null,
USER_UNREAD_SUCCESS: null,
USER_UNREAD_FAILURE: null,
USER_INFO_REQUEST: null,
USER_INFO_SUCCESS: null,
... ...
... ... @@ -12,6 +12,8 @@ import User from '../components/user/User';
import {Actions} from 'react-native-router-flux';
import * as userActions from '../reducers/user/userActions';
import * as homeActions from '../reducers/home/homeActions';
import {shouldShowTabBar, shouldHideTabBar} from '../utils/tabBar';
const {
... ... @@ -59,6 +61,7 @@ let SourceType = {
const actions = [
userActions,
homeActions,
];
function mapStateToProps(state) {
... ... @@ -89,7 +92,10 @@ class UserContainer extends React.Component {
this._onPressComment = this._onPressComment.bind(this);
this._onPressLike = this._onPressLike.bind(this);
this._onRefresh = this._onRefresh.bind(this);
this._onPressPost = this._onPressPost.bind(this);
this._onEndReached = this._onEndReached.bind(this);
this._rightButtonClick = this._rightButtonClick.bind(this);
this._onPressSectionTag = this._onPressSectionTag.bind(this);
}
componentDidMount() {
... ... @@ -126,20 +132,27 @@ class UserContainer extends React.Component {
console.log('avatar');
}
_onPressComment(url) {
_onPressComment(id) {
console.log('comment');
this.props.actions.goToPost(id);
}
_onPressLike(url) {
_onPressLike(post) {
console.log('like');
this.props.actions.likeOperation(post);
}
_onPressReply() {
_onPressReply(id) {
console.log('reply');
}
_onPressPosts() {
console.log('posts');
_onPressPost(id) {
console.log('posts id =' + id);
this.props.actions.goToPost(id);
}
_onPressSectionTag(section) {
this.props.actions.goToSection(section, this.props.navigationState.name);
}
_onPressUserAvatar() {
... ... @@ -152,9 +165,6 @@ class UserContainer extends React.Component {
(buttonIndex) => {
this._onPressGotoSettingState(buttonIndex);
// this.setState({ clicked: BUTTONS[buttonIndex] });
// this.props.actions.goToStatsPage(USER_GO_TO_SETTING_STATS);
});
... ... @@ -178,7 +188,7 @@ class UserContainer extends React.Component {
case 2:
{
console.log('编辑个人资料');
console.log('actions = ' + this.actions);
// console.log('actions = ' + this.actions);
this.props.actions.goToStatsPage(GO_TO_SETTING);
}
... ... @@ -219,6 +229,7 @@ class UserContainer extends React.Component {
this.props.actions.posts(true);
this.props.actions.like(true);
this.props.actions.reply(true);
this.props.actions.unread();
});
}
... ... @@ -238,6 +249,10 @@ class UserContainer extends React.Component {
});
}
_rightButtonClick() {
console.log('message clicked-----------');
this.props.actions.goToStatsPage(GO_TO_MESSAGE);
}
render() {
let {profile, activeTab, isFetching, ptr, posts: postsData, like: likeData, reply: replyData} = this.props.user;
... ... @@ -269,12 +284,14 @@ class UserContainer extends React.Component {
<User
channel={this.props.app.channel}
userInfo={userInfo}
profile={profile}
list={listData}
onPressAvatar={this._onPressAvatar}
onPressComment={this._onPressComment}
onPressLike={this._onPressLike}
onPressReply={this._onPressReply}
onPressPosts={this._onPressPosts}
onPressPost={this._onPressPost}
onPressSectionTag={this._onPressSectionTag}
onPressUserAvatar={this._onPressUserAvatar}
onPressBackgroundImg={this._onPressBackgroundImg}
onRefresh={this._onRefresh}
... ... @@ -284,6 +301,7 @@ class UserContainer extends React.Component {
isRefreshing={isRefreshing}
isLoadingMore={isLoadingMore}
onEndReached={this._onEndReached}
rightButtonClick={this._rightButtonClick}
/>
</View>
);
... ...
... ... @@ -19,6 +19,7 @@ import user from './user/userReducer';
import userThatNotMe from './userThatNotMe/userThatNotMeReducer';
import setting from './setting/settingReducer';
import subject from './subject/subjectPostReducer';
import message from './message/messageReducer';
import { combineReducers } from 'redux';
... ... @@ -37,6 +38,7 @@ const rootReducer = combineReducers({
userThatNotMe,
setting,
subject,
message,
});
export default rootReducer;
... ...
... ... @@ -11,7 +11,7 @@ const {
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
export default function settingReducer(state = initialState, action) {
export default function message(state = initialState, action) {
if (!(state instanceof InitialState)) return initialState.merge(state);
// switch (action.type) {
... ...
... ... @@ -6,7 +6,7 @@ import UserService from '../../services/UserService';
import timeago from '../../utils/timeago';
import {number10KFormater} from '../../utils/numberFormater';
import PostingService from '../../services/PostingService';
import moment from 'moment';
const LIMIT = 10;
const {
... ... @@ -36,6 +36,10 @@ const {
USER_INFO_SUCCESS,
USER_INFO_FAILURE,
USER_UNREAD_REQUEST,
USER_UNREAD_SUCCESS,
USER_UNREAD_FAILURE,
SET_UID,
USER_CLEAN,
USER_SET_ACTIVE_TAB,
... ... @@ -112,17 +116,48 @@ export function replyFailure(error) {
};
}
export function userInfo() {
// return dispatch => {
// dispatch(postRequest());
// return new UserService().posts()
// .then(json => {
// dispatch(postSuccess(json))
// })
// .catch(error => {
// dispatch(postFailure(error));
// });
// };
export function unreadRequest() {
return {
type: USER_UNREAD_REQUEST
};
}
export function unreadSuccess(json) {
return {
type: USER_UNREAD_SUCCESS,
payload: json
};
}
export function unreadFailure(error) {
return {
type: USER_UNREAD_FAILURE,
payload: error
};
}
export function unread() {
return (dispatch, getState) => {
let {user} = getState();
dispatch(unreadRequest());
let uid = user.profile.uid;
return new UserService().unread(uid)
.then(json => {
let msgCount = json.total ? json.total : 0;
if (msgCount > 99) {
msgCount = '99+';
} else {
msgCount = msgCount + '';
}
dispatch(unreadSuccess(msgCount))
})
.catch(error => {
dispatch(unreadFailure(error));
});
};
}
// 获取【我的帖子】数据
... ... @@ -223,7 +258,7 @@ export function reply(ptr = false) {
return new UserService().reply(uid, lastedTime, limit)
.then(json => {
let payload = parseJson(json);
let payload = parseReply(json);
if (!ptr) {
let oldList = user.reply.list.toJS();
let list = [...oldList, ...payload.list];
... ... @@ -243,7 +278,7 @@ export function goToStatsPage(type) {
switch (type) {
case GO_TO_SETTING:
{
Actions.SettingStats();
Actions.Setting();
return {
type: GO_TO_SETTING,
}
... ... @@ -486,6 +521,67 @@ function parseJson(json) {
export function parseReply(json) {
console.log('========>', json);
let {lastedTime, list} = json;
let replies = [];
list && list.map((item, i) => {
let {reply, replyTo, blocks, postInfo} = item;
let desc = '';
let thumbs = [];
blocks && blocks.map((item, i) => {
let contentData = item.contentData ? item.contentData : '';
if (desc === '' && item.templateKey === 'text') {
desc = decodeURI(contentData);
}
if (item.templateKey === 'image') {
let thumb = {
src: contentData,
};
thumbs.push(thumb);
}
});
let self = {
avatar: reply && reply.headIcon ? reply.headIcon : '',
backgroundImage: reply && reply.bgPic ? reply.bgPic : '',
uid: reply && reply.uid ? reply.uid : '',
name: reply && reply.nickName ? reply.nickName : '',
signature: reply && reply.signaure ? reply.signature : '',
};
let replyToUser = {
avatar: replyTo && replyTo.headIcon ? replyTo.headIcon : '',
backgroundImage: replyTo && replyTo.bgPic ? replyTo.bgPic : '',
uid: replyTo && replyTo.uid ? replyTo.uid : '',
name: replyTo && replyTo.nickName ? replyTo.nickName : '',
signature: replyTo && replyTo.signaure ? replyTo.signature : '',
};
let replyContent = {
thumbs,
desc,
}
let createTime = moment(item.createTime, 'x').format('MM.DD.YYYY');
let data = {
self,
replyToUser,
replyContent,
createTime,
postInfo,
}
replies.push(data);
});
let endReached = replies.length == 0;
return {
lastedTime,
list: replies,
endReached,
}
}
export function uploadAvatar(assetURL) {
... ...
... ... @@ -19,6 +19,10 @@ const {
USER_REPLY_SUCCESS,
USER_REPLY_FAILURE,
USER_UNREAD_REQUEST,
USER_UNREAD_SUCCESS,
USER_UNREAD_FAILURE,
USER_GO_TO_SETTING_STATS,
SYNC_USER_REQUEST,
... ... @@ -39,6 +43,9 @@ const {
USER_BG_UPLOAD_SUCCESS,
USER_BG_UPLOAD_FAILURE,
POST_LIKE_REQUEST,
POST_UNLIKE_REQUEST,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
... ... @@ -197,8 +204,18 @@ export default function user(state = initialState, action) {
break;
case USER_CLEAN:
{
let nextState = initialState.set('profile', state.profile);
return nextState;
}
break;
case USER_UNREAD_SUCCESS:
return state.setIn(['profile', 'msgCount'], action.payload);
break;
case USER_UNREAD_FAILURE:
return state.setIn(['profile','error'], action.payload);
break;
case USER_AVATAR_UPLOADING:{
... ... @@ -236,7 +253,60 @@ export default function user(state = initialState, action) {
}
break;
case POST_LIKE_REQUEST: {
return userCenterNewLikeState(state, action.payload, true);
}
case POST_UNLIKE_REQUEST: {
return userCenterNewLikeState(state, action.payload, false);
}
}
return state;
}
function userCenterNewLikeState(state, postId, like) {
let likeState = (list, postId, like) => {
let index = list.findIndex((item) => {
return item.get('id') == postId;
})
if (index == -1) {
return list;
}
let likeCount = 0;
if (like) {
likeCount = list.get(index).get('likeCount') + 1;
} else {
likeCount = list.get(index).get('likeCount') - 1;
likeCount = likeCount < 0 ? 0 : likeCount;
}
let nextList = list.setIn([index, 'isLike'], like)
.setIn([index, 'likeCount'], likeCount);
return nextList;
};
// let nextState = state;
let postsList = likeState(state.posts.list, postId, like);
let likeList = likeState(state.posts.list, postId, like);
let nextState = state.setIn(['posts', 'list'], postsList)
.setIn(['like', 'list'], likeList);
return nextState;
// state.items.map((item, i) => {
// let hotList = likeState(item.hot.list, postId, like);
// let newList = likeState(item.new.list, postId, like);
//
// item = item.setIn(['hot', 'list'], hotList)
// .setIn(['new', 'list'], newList);
// nextState = nextState.setIn(['items', i], item);
// });
//
// return nextState;
}
... ...
... ... @@ -108,4 +108,21 @@ export default class UserService {
throw(error);
});
}
// 获取未读消息数
async unread(uid) {
return await this.api.get({
url: '',
body: {
method: 'app.social.getTotal',
uid
}
})
.then((json) => {
return json;
})
.catch((error) => {
throw(error);
});
}
}
... ...