forked from AkkomaGang/akkoma-fe
fix login and favorites tab...
This commit is contained in:
parent
cab87744c8
commit
93cbb58212
5 changed files with 64 additions and 32 deletions
|
@ -5,13 +5,16 @@ import Timeline from '../timeline/timeline.vue'
|
||||||
const UserProfile = {
|
const UserProfile = {
|
||||||
created () {
|
created () {
|
||||||
this.$store.commit('clearTimeline', { timeline: 'user' })
|
this.$store.commit('clearTimeline', { timeline: 'user' })
|
||||||
|
this.$store.commit('clearTimeline', { timeline: 'favorites' })
|
||||||
this.$store.dispatch('startFetching', ['user', this.fetchBy])
|
this.$store.dispatch('startFetching', ['user', this.fetchBy])
|
||||||
|
this.$store.dispatch('startFetching', ['favorites', this.fetchBy])
|
||||||
if (!this.user.id) {
|
if (!this.user.id) {
|
||||||
this.$store.dispatch('fetchUser', this.fetchBy)
|
this.$store.dispatch('fetchUser', this.fetchBy)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
destroyed () {
|
destroyed () {
|
||||||
this.$store.dispatch('stopFetching', 'user')
|
this.$store.dispatch('stopFetching', 'user')
|
||||||
|
this.$store.dispatch('stopFetching', 'favorites')
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
timeline () {
|
timeline () {
|
||||||
|
@ -26,6 +29,9 @@ const UserProfile = {
|
||||||
userName () {
|
userName () {
|
||||||
return this.$route.params.name || this.user.screen_name
|
return this.$route.params.name || this.user.screen_name
|
||||||
},
|
},
|
||||||
|
isUs () {
|
||||||
|
return this.userId === this.$store.state.users.currentUser.id
|
||||||
|
},
|
||||||
friends () {
|
friends () {
|
||||||
return this.user.friends
|
return this.user.friends
|
||||||
},
|
},
|
||||||
|
@ -65,21 +71,28 @@ const UserProfile = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
|
// TODO get rid of this copypasta
|
||||||
userName () {
|
userName () {
|
||||||
if (this.isExternal) {
|
if (this.isExternal) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.$store.dispatch('stopFetching', 'user')
|
this.$store.dispatch('stopFetching', 'user')
|
||||||
|
this.$store.dispatch('stopFetching', 'favorites')
|
||||||
this.$store.commit('clearTimeline', { timeline: 'user' })
|
this.$store.commit('clearTimeline', { timeline: 'user' })
|
||||||
|
this.$store.commit('clearTimeline', { timeline: 'favorites' })
|
||||||
this.$store.dispatch('startFetching', ['user', this.fetchBy])
|
this.$store.dispatch('startFetching', ['user', this.fetchBy])
|
||||||
|
this.$store.dispatch('startFetching', ['favorites', this.fetchBy])
|
||||||
},
|
},
|
||||||
userId () {
|
userId () {
|
||||||
if (!this.isExternal) {
|
if (!this.isExternal) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.$store.dispatch('stopFetching', 'user')
|
this.$store.dispatch('stopFetching', 'user')
|
||||||
|
this.$store.dispatch('stopFetching', 'favorites')
|
||||||
this.$store.commit('clearTimeline', { timeline: 'user' })
|
this.$store.commit('clearTimeline', { timeline: 'user' })
|
||||||
|
this.$store.commit('clearTimeline', { timeline: 'favorites' })
|
||||||
this.$store.dispatch('startFetching', ['user', this.fetchBy])
|
this.$store.dispatch('startFetching', ['user', this.fetchBy])
|
||||||
|
this.$store.dispatch('startFetching', ['favorites', this.fetchBy])
|
||||||
},
|
},
|
||||||
user () {
|
user () {
|
||||||
if (this.user.id && !this.user.followers) {
|
if (this.user.id && !this.user.followers) {
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
<i class="icon-spin3 animate-spin"></i>
|
<i class="icon-spin3 animate-spin"></i>
|
||||||
</div>
|
</div>
|
||||||
</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>
|
</tab-switcher>
|
||||||
</div>
|
</div>
|
||||||
<div v-else class="panel user-profile-placeholder">
|
<div v-else class="panel user-profile-placeholder">
|
||||||
|
|
|
@ -207,39 +207,38 @@ const users = {
|
||||||
const commit = store.commit
|
const commit = store.commit
|
||||||
commit('beginLogin')
|
commit('beginLogin')
|
||||||
store.rootState.api.backendInteractor.verifyCredentials(accessToken)
|
store.rootState.api.backendInteractor.verifyCredentials(accessToken)
|
||||||
.then((response) => {
|
.then((data) => {
|
||||||
if (response.ok) {
|
if (!data.error) {
|
||||||
response.json()
|
const { user } = data
|
||||||
.then((user) => {
|
// user.credentials = userCredentials
|
||||||
// user.credentials = userCredentials
|
user.credentials = accessToken
|
||||||
user.credentials = accessToken
|
commit('setCurrentUser', user)
|
||||||
commit('setCurrentUser', user)
|
commit('addNewUsers', [user])
|
||||||
commit('addNewUsers', [user])
|
|
||||||
|
|
||||||
getNotificationPermission()
|
getNotificationPermission()
|
||||||
.then(permission => commit('setNotificationPermission', permission))
|
.then(permission => commit('setNotificationPermission', permission))
|
||||||
|
|
||||||
// Set our new backend interactor
|
// Set our new backend interactor
|
||||||
commit('setBackendInteractor', backendInteractorService(accessToken))
|
commit('setBackendInteractor', backendInteractorService(accessToken))
|
||||||
|
|
||||||
if (user.token) {
|
if (user.token) {
|
||||||
store.dispatch('initializeSocket', user.token)
|
store.dispatch('initializeSocket', user.token)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start getting fresh tweets.
|
// Start getting fresh tweets.
|
||||||
store.dispatch('startFetching', 'friends')
|
store.dispatch('startFetching', 'friends')
|
||||||
|
|
||||||
// Get user mutes and follower info
|
// Get user mutes and follower info
|
||||||
store.rootState.api.backendInteractor.fetchMutes().then((mutedUsers) => {
|
store.rootState.api.backendInteractor.fetchMutes().then((mutedUsers) => {
|
||||||
each(mutedUsers, (user) => { user.muted = true })
|
each(mutedUsers, (user) => { user.muted = true })
|
||||||
store.commit('addNewUsers', mutedUsers)
|
store.commit('addNewUsers', mutedUsers)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Fetch our friends
|
// Fetch our friends
|
||||||
store.rootState.api.backendInteractor.fetchFriends({ id: user.id })
|
store.rootState.api.backendInteractor.fetchFriends({ id: user.id })
|
||||||
.then((friends) => commit('addNewUsers', friends))
|
.then((friends) => commit('addNewUsers', friends))
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
|
const response = data.error
|
||||||
// Authentication failed
|
// Authentication failed
|
||||||
commit('endLogin')
|
commit('endLogin')
|
||||||
if (response.status === 401) {
|
if (response.status === 401) {
|
||||||
|
@ -251,11 +250,11 @@ const users = {
|
||||||
commit('endLogin')
|
commit('endLogin')
|
||||||
resolve()
|
resolve()
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log(error)
|
console.log(error)
|
||||||
commit('endLogin')
|
commit('endLogin')
|
||||||
reject('Failed to connect to server, try again')
|
reject('Failed to connect to server, try again')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -366,6 +366,18 @@ const verifyCredentials = (user) => {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: authHeaders(user)
|
headers: authHeaders(user)
|
||||||
})
|
})
|
||||||
|
.then((response) => {
|
||||||
|
if (response.ok) {
|
||||||
|
return response.json()
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
error: response
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then((data) => ({
|
||||||
|
user: parseUser(data)
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
const favorite = ({ id, credentials }) => {
|
const favorite = ({ id, credentials }) => {
|
||||||
|
|
|
@ -80,6 +80,14 @@ export const parseUser = (data) => {
|
||||||
|
|
||||||
output.statusnet_profile_url = data.statusnet_profile_url
|
output.statusnet_profile_url = data.statusnet_profile_url
|
||||||
output.is_local = data.is_local
|
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)
|
output.created_at = new Date(data.created_at)
|
||||||
|
|
Loading…
Reference in a new issue