aboutsummaryrefslogtreecommitdiff
path: root/src/components/user_profile/user_profile.js
diff options
context:
space:
mode:
authorHenry Jameson <me@hjkos.com>2019-03-08 22:40:57 +0200
committerHenry Jameson <me@hjkos.com>2019-03-08 22:40:57 +0200
commit4f3a220487c3c8b3596e5a8de7b65cc7c4f0c981 (patch)
tree585b89655e5156a464a9889ed44cc9c9ed693722 /src/components/user_profile/user_profile.js
parent853e0bc26fc49c9f402fd482fb03082f32353485 (diff)
Since BE doesn't support fetching user by screen name over MastoAPI we'll gonna
just fetching it over QvitterAPI real quick :DDDDDDDDD
Diffstat (limited to 'src/components/user_profile/user_profile.js')
-rw-r--r--src/components/user_profile/user_profile.js63
1 files changed, 26 insertions, 37 deletions
diff --git a/src/components/user_profile/user_profile.js b/src/components/user_profile/user_profile.js
index 345e7035..4f920ae2 100644
--- a/src/components/user_profile/user_profile.js
+++ b/src/components/user_profile/user_profile.js
@@ -9,7 +9,7 @@ import withList from '../../hocs/with_list/with_list'
const FollowerList = compose(
withLoadMore({
fetch: (props, $store) => $store.dispatch('addFollowers', props.userId),
- select: (props, $store) => get($store.getters.userById(props.userId), 'followers', []),
+ select: (props, $store) => get($store.getters.findUser(props.userId), 'followers', []),
destory: (props, $store) => $store.dispatch('clearFollowers', props.userId),
childPropName: 'entries',
additionalPropNames: ['userId']
@@ -20,7 +20,7 @@ const FollowerList = compose(
const FriendList = compose(
withLoadMore({
fetch: (props, $store) => $store.dispatch('addFriends', props.userId),
- select: (props, $store) => get($store.getters.userById(props.userId), 'friends', []),
+ select: (props, $store) => get($store.getters.findUser(props.userId), 'friends', []),
destory: (props, $store) => $store.dispatch('clearFriends', props.userId),
childPropName: 'entries',
additionalPropNames: ['userId']
@@ -31,19 +31,22 @@ const FriendList = compose(
const UserProfile = {
data () {
return {
- error: false
+ error: false,
+ fetchedUserId: null
}
},
created () {
- this.$store.commit('clearTimeline', { timeline: 'user' })
- this.$store.commit('clearTimeline', { timeline: 'favorites' })
- this.$store.commit('clearTimeline', { timeline: 'media' })
- this.$store.dispatch('startFetching', { timeline: 'user', userId: this.fetchBy })
- this.$store.dispatch('startFetching', { timeline: 'media', userId: this.fetchBy })
- this.startFetchFavorites()
if (!this.user.id) {
- this.$store.dispatch('fetchUser', this.fetchBy)
- .then(() => this.$store.dispatch('fetchUserRelationship', this.fetchBy))
+ let fetchPromise
+ if (this.userId) {
+ fetchPromise = this.$store.dispatch('fetchUser', this.userId)
+ } else {
+ fetchPromise = this.$store.dispatch('fetchUserByScreenName', this.userName)
+ .then(userId => {
+ this.fetchedUserId = userId
+ })
+ }
+ fetchPromise
.catch((reason) => {
const errorMessage = get(reason, 'error.error')
if (errorMessage === 'No user with such user_id') { // Known error
@@ -54,8 +57,7 @@ const UserProfile = {
this.error = this.$t('user_profile.profile_loading_error')
}
})
- } else if (typeof this.user.following === 'undefined' || this.user.following === null) {
- this.$store.dispatch('fetchUserRelationship', this.fetchBy)
+ .then(() => this.startUp())
}
},
destroyed () {
@@ -72,7 +74,7 @@ const UserProfile = {
return this.$store.state.statuses.timelines.media
},
userId () {
- return this.$route.params.id || this.user.id
+ return this.$route.params.id || this.user.id || this.fetchedUserId
},
userName () {
return this.$route.params.name || this.user.screen_name
@@ -82,10 +84,8 @@ const UserProfile = {
this.userId === this.$store.state.users.currentUser.id
},
userInStore () {
- if (this.isExternal) {
- return this.$store.getters.userById(this.userId)
- }
- return this.$store.getters.userByName(this.userName)
+ const routeParams = this.$route.params
+ return this.$store.getters.findUser(routeParams.name || routeParams.iid)
},
user () {
if (this.timeline.statuses[0]) {
@@ -96,9 +96,6 @@ const UserProfile = {
}
return {}
},
- fetchBy () {
- return this.isExternal ? this.userId : this.userName
- },
isExternal () {
return this.$route.name === 'external-user-profile'
},
@@ -112,13 +109,13 @@ const UserProfile = {
methods: {
startFetchFavorites () {
if (this.isUs) {
- this.$store.dispatch('startFetching', { timeline: 'favorites', userId: this.fetchBy })
+ this.$store.dispatch('startFetching', { timeline: 'favorites', userId: this.userId })
}
},
startUp () {
- this.$store.dispatch('startFetching', { timeline: 'user', userId: this.fetchBy })
- this.$store.dispatch('startFetching', { timeline: 'media', userId: this.fetchBy })
-
+ this.$store.dispatch('fetchUserRelationship', this.userId)
+ this.$store.dispatch('startFetching', { timeline: 'user', userId: this.userId })
+ this.$store.dispatch('startFetching', { timeline: 'media', userId: this.userId })
this.startFetchFavorites()
},
cleanUp () {
@@ -131,19 +128,11 @@ const UserProfile = {
}
},
watch: {
- userName () {
- if (this.isExternal) {
- return
- }
- this.cleanUp()
- this.startUp()
- },
- userId () {
- if (!this.isExternal) {
- return
+ userId (newVal, oldVal) {
+ if (newVal) {
+ this.cleanUp()
+ this.startUp()
}
- this.cleanUp()
- this.startUp()
},
$route () {
this.$refs.tabSwitcher.activateTab(0)()