follows/followers pagination ready for review
This commit is contained in:
parent
8ce513ed09
commit
dbb16d56e2
9 changed files with 229 additions and 76 deletions
|
@ -1,5 +1,5 @@
|
|||
import backendInteractorService from '../services/backend_interactor_service/backend_interactor_service.js'
|
||||
import { compact, map, each, merge, concat } from 'lodash'
|
||||
import { compact, map, each, merge, find } from 'lodash'
|
||||
import { set } from 'vue'
|
||||
import { registerPushNotifications, unregisterPushNotifications } from '../services/push/push.js'
|
||||
import oauthApi from '../services/new_api/oauth'
|
||||
|
@ -52,14 +52,35 @@ export const mutations = {
|
|||
state.loggingIn = false
|
||||
},
|
||||
// TODO Clean after ourselves?
|
||||
addFriends (state, { id, friends }) {
|
||||
addFriends (state, { id, friends, page }) {
|
||||
const user = state.usersObject[id]
|
||||
console.log(user.friends)
|
||||
user.friends = concat(user.friends, friends)
|
||||
each(friends, friend => {
|
||||
if (!find(user.friends, { id: friend.id })) {
|
||||
user.friends.push(friend)
|
||||
}
|
||||
})
|
||||
user.friendsPage = page + 1
|
||||
},
|
||||
addFollowers (state, { id, followers }) {
|
||||
addFollowers (state, { id, followers, page }) {
|
||||
const user = state.usersObject[id]
|
||||
user.followers = followers
|
||||
each(followers, follower => {
|
||||
if (!find(user.followers, { id: follower.id })) {
|
||||
user.followers.push(follower)
|
||||
}
|
||||
})
|
||||
user.followersPage = page + 1
|
||||
},
|
||||
// Because frontend doesn't have a reason to keep these stuff in memory
|
||||
// outside of viewing someones user profile.
|
||||
clearFriendsAndFollowers (state, userKey) {
|
||||
const user = state.usersObject[userKey]
|
||||
if (!user) {
|
||||
return
|
||||
}
|
||||
user.friends = []
|
||||
user.followers = []
|
||||
user.friendsPage = 0
|
||||
user.followersPage = 0
|
||||
},
|
||||
addNewUsers (state, users) {
|
||||
each(users, (user) => mergeOrAdd(state.users, state.usersObject, user))
|
||||
|
@ -116,13 +137,34 @@ const users = {
|
|||
store.rootState.api.backendInteractor.fetchUser({ id })
|
||||
.then((user) => store.commit('addNewUsers', [user]))
|
||||
},
|
||||
addFriends ({ rootState, commit }, { id, page }) {
|
||||
rootState.api.backendInteractor.fetchFriends({ id, page })
|
||||
.then((friends) => commit('addFriends', { id, friends }))
|
||||
addFriends ({ rootState, commit }, fetchBy) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const user = rootState.users.usersObject[fetchBy]
|
||||
const page = user.friendsPage || 1
|
||||
rootState.api.backendInteractor.fetchFriends({ id: user.id, page })
|
||||
.then((friends) => {
|
||||
commit('addFriends', { id: user.id, friends, page })
|
||||
resolve(friends)
|
||||
}).catch(() => {
|
||||
reject()
|
||||
})
|
||||
})
|
||||
},
|
||||
addFollowers ({ rootState, commit }, { id, page }) {
|
||||
rootState.api.backendInteractor.fetchFollowers({ id, page })
|
||||
.then((followers) => commit('addFollowers', { id, followers }))
|
||||
addFollowers ({ rootState, commit }, fetchBy) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const user = rootState.users.usersObject[fetchBy]
|
||||
const page = user.followersPage || 1
|
||||
rootState.api.backendInteractor.fetchFollowers({ id: user.id, page })
|
||||
.then((followers) => {
|
||||
commit('addFollowers', { id: user.id, followers, page })
|
||||
resolve(followers)
|
||||
}).catch(() => {
|
||||
reject()
|
||||
})
|
||||
})
|
||||
},
|
||||
clearFriendsAndFollowers ({ commit }, userKey) {
|
||||
commit('clearFriendsAndFollowers', userKey)
|
||||
},
|
||||
registerPushNotifications (store) {
|
||||
const token = store.state.currentUser.credentials
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue