fix login and favorites tab...

This commit is contained in:
Henry Jameson 2019-01-17 22:11:51 +03:00
parent cab87744c8
commit 93cbb58212
5 changed files with 64 additions and 32 deletions

View File

@ -5,13 +5,16 @@ import Timeline from '../timeline/timeline.vue'
const UserProfile = {
created () {
this.$store.commit('clearTimeline', { timeline: 'user' })
this.$store.commit('clearTimeline', { timeline: 'favorites' })
this.$store.dispatch('startFetching', ['user', this.fetchBy])
this.$store.dispatch('startFetching', ['favorites', this.fetchBy])
if (!this.user.id) {
this.$store.dispatch('fetchUser', this.fetchBy)
}
},
destroyed () {
this.$store.dispatch('stopFetching', 'user')
this.$store.dispatch('stopFetching', 'favorites')
},
computed: {
timeline () {
@ -26,6 +29,9 @@ const UserProfile = {
userName () {
return this.$route.params.name || this.user.screen_name
},
isUs () {
return this.userId === this.$store.state.users.currentUser.id
},
friends () {
return this.user.friends
},
@ -65,21 +71,28 @@ const UserProfile = {
}
},
watch: {
// TODO get rid of this copypasta
userName () {
if (this.isExternal) {
return
}
this.$store.dispatch('stopFetching', 'user')
this.$store.dispatch('stopFetching', 'favorites')
this.$store.commit('clearTimeline', { timeline: 'user' })
this.$store.commit('clearTimeline', { timeline: 'favorites' })
this.$store.dispatch('startFetching', ['user', this.fetchBy])
this.$store.dispatch('startFetching', ['favorites', this.fetchBy])
},
userId () {
if (!this.isExternal) {
return
}
this.$store.dispatch('stopFetching', 'user')
this.$store.dispatch('stopFetching', 'favorites')
this.$store.commit('clearTimeline', { timeline: 'user' })
this.$store.commit('clearTimeline', { timeline: 'favorites' })
this.$store.dispatch('startFetching', ['user', this.fetchBy])
this.$store.dispatch('startFetching', ['favorites', this.fetchBy])
},
user () {
if (this.user.id && !this.user.followers) {

View File

@ -20,7 +20,7 @@
<i class="icon-spin3 animate-spin"></i>
</div>
</div>
<Timeline :label="$t('user_card.favorites')" :embedded="true" :title="$t('user_profile.favorites_title')" :timeline="favorites"/>
<Timeline v-if="isUs" :label="$t('user_card.favorites')" :embedded="true" :title="$t('user_profile.favorites_title')" :timeline="favorites"/>
</tab-switcher>
</div>
<div v-else class="panel user-profile-placeholder">

View File

@ -207,10 +207,9 @@ const users = {
const commit = store.commit
commit('beginLogin')
store.rootState.api.backendInteractor.verifyCredentials(accessToken)
.then((response) => {
if (response.ok) {
response.json()
.then((user) => {
.then((data) => {
if (!data.error) {
const { user } = data
// user.credentials = userCredentials
user.credentials = accessToken
commit('setCurrentUser', user)
@ -238,8 +237,8 @@ const users = {
// Fetch our friends
store.rootState.api.backendInteractor.fetchFriends({ id: user.id })
.then((friends) => commit('addNewUsers', friends))
})
} else {
const response = data.error
// Authentication failed
commit('endLogin')
if (response.status === 401) {

View File

@ -366,6 +366,18 @@ const verifyCredentials = (user) => {
method: 'POST',
headers: authHeaders(user)
})
.then((response) => {
if (response.ok) {
return response.json()
} else {
return {
error: response
}
}
})
.then((data) => ({
user: parseUser(data)
}))
}
const favorite = ({ id, credentials }) => {

View File

@ -80,6 +80,14 @@ export const parseUser = (data) => {
output.statusnet_profile_url = data.statusnet_profile_url
output.is_local = data.is_local
// QVITTER ONLY FOR NOW
// Really only applies to logged in user, really.. I THINK
output.rights = data.rights
output.no_rich_text = data.no_rich_text
output.default_scope = data.default_scope
output.hide_network = data.hide_network
output.background_image = data.background_image
}
output.created_at = new Date(data.created_at)