paginate-follow-requests (#277)
Co-authored-by: FloatingGhost <hannah@coffee-and-dreams.uk> Reviewed-on: https://akkoma.dev/AkkomaGang/akkoma-fe/pulls/277
This commit is contained in:
parent
b4b13d777f
commit
88d5149db5
12 changed files with 92 additions and 72 deletions
|
@ -1,5 +1,6 @@
|
|||
import backendInteractorService from '../services/backend_interactor_service/backend_interactor_service.js'
|
||||
import { WSConnectionStatus } from '../services/api/api.service.js'
|
||||
import { map } from 'lodash'
|
||||
|
||||
const retryTimeout = (multiplier) => 1000 * multiplier
|
||||
|
||||
|
@ -40,9 +41,6 @@ const api = {
|
|||
setSocket (state, socket) {
|
||||
state.socket = socket
|
||||
},
|
||||
setFollowRequests (state, value) {
|
||||
state.followRequests = value
|
||||
},
|
||||
setMastoUserSocketStatus (state, value) {
|
||||
state.mastoUserSocketStatus = value
|
||||
},
|
||||
|
@ -51,6 +49,15 @@ const api = {
|
|||
},
|
||||
resetRetryMultiplier (state) {
|
||||
state.retryMultiplier = 1
|
||||
},
|
||||
setFollowRequests (state, value) {
|
||||
state.followRequests = [...value]
|
||||
},
|
||||
saveFollowRequests (state, requests) {
|
||||
state.followRequests = [...state.followRequests, ...requests]
|
||||
},
|
||||
saveFollowRequestPagination (state, pagination) {
|
||||
state.followRequestsPagination = pagination
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
|
@ -240,24 +247,22 @@ const api = {
|
|||
...rest
|
||||
})
|
||||
},
|
||||
|
||||
// Follow requests
|
||||
startFetchingFollowRequests (store) {
|
||||
if (store.state.fetchers['followRequests']) return
|
||||
const fetcher = store.state.backendInteractor.startFetchingFollowRequests({ store })
|
||||
|
||||
store.commit('addFetcher', { fetcherName: 'followRequests', fetcher })
|
||||
},
|
||||
stopFetchingFollowRequests (store) {
|
||||
const fetcher = store.state.fetchers.followRequests
|
||||
if (!fetcher) return
|
||||
store.commit('removeFetcher', { fetcherName: 'followRequests', fetcher })
|
||||
},
|
||||
removeFollowRequest (store, request) {
|
||||
let requests = store.state.followRequests.filter((it) => it !== request)
|
||||
let requests = [...store.state.followRequests].filter((it) => it.id !== request.id)
|
||||
store.commit('setFollowRequests', requests)
|
||||
},
|
||||
|
||||
fetchFollowRequests ({ rootState, commit }) {
|
||||
const pagination = rootState.api.followRequestsPagination
|
||||
return rootState.api.backendInteractor.getFollowRequests({ pagination })
|
||||
.then((requests) => {
|
||||
if (requests.data.length > 0) {
|
||||
commit('addNewUsers', requests.data)
|
||||
commit('saveFollowRequests', requests.data)
|
||||
commit('saveFollowRequestPagination', requests.pagination)
|
||||
}
|
||||
return requests
|
||||
})
|
||||
},
|
||||
// Lists
|
||||
startFetchingLists (store) {
|
||||
if (store.state.fetchers['lists']) return
|
||||
|
|
|
@ -265,6 +265,12 @@ export const mutations = {
|
|||
signUpFailure (state, errors) {
|
||||
state.signUpPending = false
|
||||
state.signUpErrors = errors
|
||||
},
|
||||
decrementFollowRequestsCount (store) {
|
||||
store.currentUser.follow_requests_count--
|
||||
},
|
||||
incrementFollowRequestsCount (store) {
|
||||
store.currentUser.follow_requests_count++
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -504,6 +510,12 @@ const users = {
|
|||
store.commit('setUserForNotification', notification)
|
||||
})
|
||||
},
|
||||
decrementFollowRequestsCount (store) {
|
||||
store.commit('decrementFollowRequestsCount')
|
||||
},
|
||||
incrementFollowRequestsCount (store) {
|
||||
store.commit('incrementFollowRequestsCount')
|
||||
},
|
||||
searchUsers ({ rootState, commit }, { query }) {
|
||||
return rootState.api.backendInteractor.searchUsers({ query })
|
||||
.then((users) => {
|
||||
|
@ -567,7 +579,6 @@ const users = {
|
|||
store.dispatch('stopFetchingTimeline', 'friends')
|
||||
store.commit('setBackendInteractor', backendInteractorService(store.getters.getToken()))
|
||||
store.dispatch('stopFetchingNotifications')
|
||||
store.dispatch('stopFetchingFollowRequests')
|
||||
store.dispatch('stopFetchingConfig')
|
||||
store.commit('clearNotifications')
|
||||
store.commit('resetStatuses')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue