import graphql from '../utils/graphql' ; function setUser ( userinfo ) { return { type : 'SET_USER' , userinfo } ; } export function addAccessToken ( { accessToken } ) { return ( dispatch , getState ) => { dispatch ( { type : 'ADD_ACCESS_TOKEN' , access_token : accessToken } ) ; } ; } export function removeAccessToken ( ) { return ( dispatch , getState ) => { dispatch ( { type : 'REMOVE_ACCESS_TOKEN' } ) ; } ; } param { String } accessToken export const loadUserInfo = ( { accessToken } ) => { return ( dispatch , getState ) => { return new Promise ( async ( resolve , reject ) => { let [ err , res ] = await graphql ( { apis : [ { api : 'selfInfo' , args : { } , fields : `
          _id
          nickname_reset_at
          create_at
          last_sign_at
          blocked
          role
          avatar
          brief
          source
          posts_count
          comment_count
          fans_count
          like_count
          follow_people_count
          follow_topic_count
          follow_posts_count
          block_people_count
          block_posts_count
          block_comment_count
          gender
          nickname
          banned_to_post
          avatar_url
          email
          weibo
          qq
          github
          phone
          area_code
          find_notification_at
          last_find_feed_at
          last_find_favorite_at
          has_password
          theme
          user_cover
          ` } ] , headers : { accessToken : accessToken || getState ( ) . user . accessToken } } ) ; if ( err ) { resolve ( [ err ] ) ; } else { if ( dispatch ) { dispatch ( { type : 'SET_USER' , userinfo : res } ) ; if ( accessToken ) { dispatch ( { type : 'ADD_ACCESS_TOKEN' , access_token : accessToken } ) ; } } resolve ( [ null , res ] ) ; } } ) ; } ; } ; param { Object } args return { Array } export function updateUser ( args ) { return async ( dispatch , getState ) => { return new Promise ( async ( resolve ) => { args . _id = getState ( ) . user . userInfo . _id ; let [ err , res ] = await graphql ( { type : 'mutation' , apis : [ { api : 'updateUser' , args , fields : `success` } ] , headers : { accessToken : getState ( ) . user . accessToken } } ) ; resolve ( [ err , res ] ) ; } ) ; } ; } param { Object } args return { Array } export function updatePassword ( args ) { return async ( dispatch , getState ) => { return new Promise ( async ( resolve ) => { args . user_id = getState ( ) . user . userInfo . _id ; let [ err , res ] = await graphql ( { type : 'mutation' , apis : [ { api : 'updatePassword' , args , fields : `success` } ] , headers : { accessToken : getState ( ) . user . accessToken } } ) ; resolve ( [ err , res ] ) ; } ) ; } ; }