Use state object for user view instead of timeline.
Also fetch user if not in the state already.
This commit is contained in:
parent
55c4818084
commit
07057043d9
|
@ -5,6 +5,9 @@ const UserProfile = {
|
||||||
created () {
|
created () {
|
||||||
this.$store.commit('clearTimeline', { timeline: 'user' })
|
this.$store.commit('clearTimeline', { timeline: 'user' })
|
||||||
this.$store.dispatch('startFetching', ['user', this.userId])
|
this.$store.dispatch('startFetching', ['user', this.userId])
|
||||||
|
if (!this.$store.state.users.usersObject[this.userId]) {
|
||||||
|
this.$store.dispatch('fetchUser', this.userId)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
destroyed () {
|
destroyed () {
|
||||||
this.$store.dispatch('stopFetching', 'user')
|
this.$store.dispatch('stopFetching', 'user')
|
||||||
|
@ -18,7 +21,7 @@ const UserProfile = {
|
||||||
if (this.timeline.statuses[0]) {
|
if (this.timeline.statuses[0]) {
|
||||||
return this.timeline.statuses[0].user
|
return this.timeline.statuses[0].user
|
||||||
} else {
|
} else {
|
||||||
return false
|
return this.$store.state.users.usersObject[this.userId] || false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -57,6 +57,10 @@ const users = {
|
||||||
state: defaultState,
|
state: defaultState,
|
||||||
mutations,
|
mutations,
|
||||||
actions: {
|
actions: {
|
||||||
|
fetchUser (store, id) {
|
||||||
|
store.rootState.api.backendInteractor.fetchUser({id})
|
||||||
|
.then((user) => store.commit('addNewUsers', user))
|
||||||
|
},
|
||||||
addNewStatuses (store, { statuses }) {
|
addNewStatuses (store, { statuses }) {
|
||||||
const users = map(statuses, 'user')
|
const users = map(statuses, 'user')
|
||||||
const retweetedUsers = compact(map(statuses, 'retweeted_status.user'))
|
const retweetedUsers = compact(map(statuses, 'retweeted_status.user'))
|
||||||
|
|
|
@ -28,7 +28,7 @@ const EXTERNAL_PROFILE_URL = '/api/externalprofile/show.json'
|
||||||
const QVITTER_USER_TIMELINE_URL = '/api/qvitter/statuses/user_timeline.json'
|
const QVITTER_USER_TIMELINE_URL = '/api/qvitter/statuses/user_timeline.json'
|
||||||
const BLOCKING_URL = '/api/blocks/create.json'
|
const BLOCKING_URL = '/api/blocks/create.json'
|
||||||
const UNBLOCKING_URL = '/api/blocks/destroy.json'
|
const UNBLOCKING_URL = '/api/blocks/destroy.json'
|
||||||
// const USER_URL = '/api/users/show.json'
|
const USER_URL = '/api/users/show.json'
|
||||||
|
|
||||||
import { each, map } from 'lodash'
|
import { each, map } from 'lodash'
|
||||||
import 'whatwg-fetch'
|
import 'whatwg-fetch'
|
||||||
|
@ -202,6 +202,12 @@ const unblockUser = ({id, credentials}) => {
|
||||||
}).then((data) => data.json())
|
}).then((data) => data.json())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fetchUser = ({id, credentials}) => {
|
||||||
|
let url = `${USER_URL}?user_id=${id}`
|
||||||
|
return fetch(url, { headers: authHeaders(credentials) })
|
||||||
|
.then((data) => data.json())
|
||||||
|
}
|
||||||
|
|
||||||
const fetchFriends = ({id, credentials}) => {
|
const fetchFriends = ({id, credentials}) => {
|
||||||
let url = `${FRIENDS_URL}?user_id=${id}`
|
let url = `${FRIENDS_URL}?user_id=${id}`
|
||||||
return fetch(url, { headers: authHeaders(credentials) })
|
return fetch(url, { headers: authHeaders(credentials) })
|
||||||
|
@ -363,6 +369,7 @@ const apiService = {
|
||||||
unfollowUser,
|
unfollowUser,
|
||||||
blockUser,
|
blockUser,
|
||||||
unblockUser,
|
unblockUser,
|
||||||
|
fetchUser,
|
||||||
favorite,
|
favorite,
|
||||||
unfavorite,
|
unfavorite,
|
||||||
retweet,
|
retweet,
|
||||||
|
|
|
@ -22,6 +22,10 @@ const backendInteractorService = (credentials) => {
|
||||||
return apiService.fetchAllFollowing({username, credentials})
|
return apiService.fetchAllFollowing({username, credentials})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fetchUser = ({id}) => {
|
||||||
|
return apiService.fetchUser({id, credentials})
|
||||||
|
}
|
||||||
|
|
||||||
const followUser = (id) => {
|
const followUser = (id) => {
|
||||||
return apiService.followUser({credentials, id})
|
return apiService.followUser({credentials, id})
|
||||||
}
|
}
|
||||||
|
@ -65,6 +69,7 @@ const backendInteractorService = (credentials) => {
|
||||||
unfollowUser,
|
unfollowUser,
|
||||||
blockUser,
|
blockUser,
|
||||||
unblockUser,
|
unblockUser,
|
||||||
|
fetchUser,
|
||||||
fetchAllFollowing,
|
fetchAllFollowing,
|
||||||
verifyCredentials: apiService.verifyCredentials,
|
verifyCredentials: apiService.verifyCredentials,
|
||||||
startFetching,
|
startFetching,
|
||||||
|
|
Loading…
Reference in New Issue