2026-08-31 19:05:26 +03:00
|
|
|
import { defineStore } from 'pinia'
|
|
|
|
|
|
|
|
|
|
import followRequestFetcher from 'src/stores/fetchers/follow_requests.js'
|
|
|
|
|
import { useOAuthStore } from 'src/stores/oauth.js'
|
|
|
|
|
|
|
|
|
|
export const useFollowRequestsStore = defineStore('followRequests', {
|
|
|
|
|
state: () => ({
|
|
|
|
|
fetcher: null,
|
|
|
|
|
requests: new Map(),
|
|
|
|
|
}),
|
|
|
|
|
getters: {
|
|
|
|
|
followRequestsCount(state) {
|
|
|
|
|
return state.requests.size
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
actions: {
|
|
|
|
|
startFetching() {
|
2026-09-03 16:55:41 +03:00
|
|
|
if (this.fetcher) throw new Error('Fetcher already exists!')
|
2026-08-31 19:05:26 +03:00
|
|
|
|
|
|
|
|
this.fetcher = followRequestFetcher({
|
|
|
|
|
credentials: useOAuthStore().token,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
this.fetcher.startFetching()
|
|
|
|
|
},
|
|
|
|
|
stopFetching() {
|
2026-09-03 16:55:41 +03:00
|
|
|
if (!this.fetcher) throw new Error("Fetcher doesn't exists!")
|
|
|
|
|
this.fetcher.stopFetching()
|
|
|
|
|
this.fetcher = null
|
2026-08-31 19:05:26 +03:00
|
|
|
},
|
|
|
|
|
setFollowRequests(requests) {
|
|
|
|
|
this.requests = new Map(requests.map((user) => [user.id, user]))
|
|
|
|
|
},
|
|
|
|
|
remove(id) {
|
|
|
|
|
this.requests.delete(id)
|
2026-09-01 18:02:38 +03:00
|
|
|
},
|
2026-08-31 19:05:26 +03:00
|
|
|
},
|
|
|
|
|
})
|