Authored by 盖剑秋

Change user avatar and background image.

... ... @@ -85,6 +85,13 @@ export default keyMirror({
USER_TNM_CLEAN: null,
USER_AVATAR_UPLOADING: null,
USER_AVATAR_UPLOAD_SUCCESS: null,
USER_AVATAR_UPLOAD_FAILURE: null,
USER_BG_UPLOADING: null,
USER_BG_UPLOAD_SUCCESS: null,
USER_BG_UPLOAD_FAILURE: null,
SETTING_SAVE_REQUEST: null,
SETTING_SAVE_SUCCESS: null,
SETTING_SAVE_FAILURE: null,
... ...
... ... @@ -43,7 +43,19 @@ const {
ActionSheetIOS,
NativeModules,
InteractionManager,
NativeAppEventEmitter,
} = ReactNative;
let YH_CommunityAssetsPicker = NativeModules.YH_CommunityAssetsPicker;
let PickerType = {
Avatar: 0,
Bg: 1,
}
let SourceType = {
UIImagePickerControllerSourceTypePhotoLibrary: 0,
UIImagePickerControllerSourceTypeCamera: 1,
}
const actions = [
userActions,
... ... @@ -84,6 +96,19 @@ class UserContainer extends React.Component {
if (shouldHideTabBar(this.props.navigationState)) {
NativeModules.YH_CommunityHelper.hideTabBar();
}
this.observer = NativeAppEventEmitter.addListener('UserImagePickerEvent',(event)=>{
console.log(event);
switch (event.pickerType) {
case PickerType.Avatar:
this.props.actions.uploadAvatar(event.assetURL);
break;
case PickerType.Bg:
this.props.actions.uploadBg(event.assetURL);
break;
default:
}
})
}
componentWillUnmount() {
... ... @@ -92,6 +117,7 @@ class UserContainer extends React.Component {
}
this.props.actions.userClean();
this.observer.remove();
}
... ... @@ -140,13 +166,13 @@ class UserContainer extends React.Component {
case 0:
{
console.log('拍照');
this.props.actions.goToStatsPage(GO_TO_MESSAGE);
YH_CommunityAssetsPicker.userImagePicker(PickerType.Avatar,SourceType.UIImagePickerControllerSourceTypeCamera);
}
break;
case 1:
{
console.log('从相册中选择');
YH_CommunityAssetsPicker.userImagePicker(PickerType.Avatar,SourceType.UIImagePickerControllerSourceTypePhotoLibrary);
}
break;
case 2:
... ... @@ -172,11 +198,13 @@ class UserContainer extends React.Component {
case 0:
{
console.log('拍照');
YH_CommunityAssetsPicker.userImagePicker(PickerType.Bg,SourceType.UIImagePickerControllerSourceTypeCamera);
}
break;
case 1:
{
console.log('从相册中选择');
YH_CommunityAssetsPicker.userImagePicker(PickerType.Bg,SourceType.UIImagePickerControllerSourceTypePhotoLibrary);
}
break;
default:
... ...
... ... @@ -5,6 +5,7 @@ import {Actions} from 'react-native-router-flux';
import UserService from '../../services/UserService';
import timeago from '../../utils/timeago';
import {number10KFormater} from '../../utils/numberFormater';
import PostingService from '../../services/PostingService';
const LIMIT = 10;
... ... @@ -39,6 +40,13 @@ const {
USER_CLEAN,
USER_SET_ACTIVE_TAB,
USER_AVATAR_UPLOADING,
USER_AVATAR_UPLOAD_SUCCESS,
USER_AVATAR_UPLOAD_FAILURE,
USER_BG_UPLOADING,
USER_BG_UPLOAD_SUCCESS,
USER_BG_UPLOAD_FAILURE,
} = require('../../constants/actionTypes').default;
export function postRequest(ptr) {
... ... @@ -476,6 +484,108 @@ function parseJson(json) {
}
}
function parseReply(json) {
export function parseReply(json) {
console.log('========>', json);
}
export function uploadAvatar(assetURL) {
return (dispatch, getState) => {
dispatch(startUploadAvatar());
let {user} = getState();
let asset = {
name: 'avatar.jpg',
url: assetURL,
uri: assetURL,
}
new PostingService().uploadImageAsset(asset)
.then(response => {
console.log('aaaaaaaaaaaaaaaaaaaaa');
console.log(response);
let params = {
headIco: response,
uid: user.profile.uid,
}
return new UserService().updateUserInfo(params)
.then(json => {
console.log(json);
dispatch(avatarUploadSuccess(json));
dispatch(syncUserWithSSOUid(user.profile.uid));
}).catch(error => {
dispatch(avatarUploadFailure(error));
})
}).catch(error => {
dispatch(avatarUploadFailure(error));
});
}
}
export function startUploadAvatar() {
return {
type: USER_AVATAR_UPLOADING,
}
}
export function avatarUploadSuccess(json) {
return {
type: USER_AVATAR_UPLOAD_SUCCESS,
payload: json,
}
}
export function avatarUploadFailure(error) {
return {
type: USER_AVATAR_UPLOAD_FAILURE,
payload: error,
}
}
export function uploadBg(assetURL) {
return (dispatch, getState) => {
dispatch(startUploadBg());
let {user} = getState();
let asset = {
name: 'avatar.jpg',
url: assetURL,
uri: assetURL,
}
new PostingService().uploadImageAsset(asset)
.then(response => {
console.log('aaaaaaaaaaaaaaaaaaaaa');
console.log(response);
let params = {
bgPic: response,
uid: user.profile.uid,
}
return new UserService().updateUserInfo(params)
.then(json => {
console.log(json);
dispatch(bgUploadSuccess(json));
dispatch(syncUserWithSSOUid(user.profile.uid));
}).catch(error => {
dispatch(bgUploadFailure(error));
})
}).catch(error => {
dispatch(bgUploadFailure(error));
});
}
}
export function startUploadBg() {
return {
type: USER_BG_UPLOADING,
}
}
export function bgUploadSuccess(json) {
return {
type: USER_BG_UPLOAD_SUCCESS,
payload: json,
}
}
export function bgUploadFailure(error) {
return {
type: USER_BG_UPLOAD_FAILURE,
payload: error,
}
}
... ...
... ... @@ -44,6 +44,10 @@ let InitialState = Record({
list: List(),
endReached: false,
})), //我的回复
avatarUploading: false,
avatarUploadError: null,
bgUploading: false,
bgUploadError: null,
});
export default InitialState;
... ...
... ... @@ -32,6 +32,13 @@ const {
USER_CLEAN,
USER_SET_ACTIVE_TAB,
USER_AVATAR_UPLOADING,
USER_AVATAR_UPLOAD_SUCCESS,
USER_AVATAR_UPLOAD_FAILURE,
USER_BG_UPLOADING,
USER_BG_UPLOAD_SUCCESS,
USER_BG_UPLOAD_FAILURE,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
... ... @@ -193,6 +200,42 @@ export default function user(state = initialState, action) {
let nextState = initialState.set('profile', state.profile);
return nextState;
break;
case USER_AVATAR_UPLOADING:{
let nextState = state.set('avatarUploading',true).set('avatarUploadError',null);
return nextState;
}
break;
case USER_AVATAR_UPLOAD_SUCCESS:{
let nextState = state.set('avatarUploading',false).set('avatarUploadError',null);
return nextState;
}
break;
case USER_AVATAR_UPLOAD_FAILURE: {
let nextState = state.set('avatarUploading',false).set('avatarUploadError',action.payload);
return nextState;
}
break;
case USER_BG_UPLOADING: {
let nextState = state.set('bgUploading',true).set('bgUploadError',null);
return nextState;
}
break;
case USER_BG_UPLOAD_SUCCESS: {
let nextState = state.set('bgUploading',false).set('bgUploadError',null);
return nextState;
}
break;
case USER_BG_UPLOAD_FAILURE: {
let nextState = state.set('bgUploading',false).set('bgUploadError',action.payload);
return nextState;
}
break;
}
return state;
... ...
... ... @@ -8,6 +8,19 @@ export default class UserService {
this.api = new Request();
}
async updateUserInfo(params) {
return await this.api.get({
url: '',
body: {
method:'app.social.updateUserInfo',
...params,
}
}).then((json)=> {
return json;
}).catch((error) => {
throw error;
});
}
async syncUser(uid, appChannel) {
return await this.api.get({
... ...