forked from AkkomaGang/akkoma-fe
Wire up ui to real blocks api data
This commit is contained in:
parent
a56d2dfeb1
commit
a817cc7cb4
6 changed files with 40 additions and 3 deletions
|
@ -10,8 +10,8 @@ import withLoadMore from '../../hocs/with_load_more/with_load_more'
|
||||||
|
|
||||||
const BlockListWithLoadMore = withLoadMore(
|
const BlockListWithLoadMore = withLoadMore(
|
||||||
UserList,
|
UserList,
|
||||||
(props, $store) => $store.dispatch('addFriends', $store.state.users.currentUser.id),
|
(props, $store) => $store.dispatch('fetchBlocks'),
|
||||||
(props, $store) => get($store.getters.userById($store.state.users.currentUser.id), 'friends', [])
|
(props, $store) => get($store.state.users.currentUser, 'blocks', [])
|
||||||
)
|
)
|
||||||
|
|
||||||
const UserSettings = {
|
const UserSettings = {
|
||||||
|
|
|
@ -48,7 +48,7 @@ const withLoadMore = (Component, fetchEntries, getEntries) => {
|
||||||
fetchEntries(this.$props, this.$store).then((newEntries) => {
|
fetchEntries(this.$props, this.$store).then((newEntries) => {
|
||||||
this.error = false
|
this.error = false
|
||||||
this.loading = false
|
this.loading = false
|
||||||
this.bottomedOut = newEntries.length === 0
|
this.bottomedOut = !newEntries || newEntries.length === 0
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
this.error = true
|
this.error = true
|
||||||
this.loading = false
|
this.loading = false
|
||||||
|
|
|
@ -85,6 +85,15 @@ export const mutations = {
|
||||||
addNewUsers (state, users) {
|
addNewUsers (state, users) {
|
||||||
each(users, (user) => mergeOrAdd(state.users, state.usersObject, user))
|
each(users, (user) => mergeOrAdd(state.users, state.usersObject, user))
|
||||||
},
|
},
|
||||||
|
addBlocks (state, { blocks, page }) {
|
||||||
|
const user = state.currentUser
|
||||||
|
each(blocks, block => {
|
||||||
|
if (!find(user.blocks, { id: block.id })) {
|
||||||
|
user.blocks.push(block)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
user.blocksPage = page + 1
|
||||||
|
},
|
||||||
setUserForStatus (state, status) {
|
setUserForStatus (state, status) {
|
||||||
status.user = state.usersObject[status.user.id]
|
status.user = state.usersObject[status.user.id]
|
||||||
},
|
},
|
||||||
|
@ -137,6 +146,14 @@ const users = {
|
||||||
store.rootState.api.backendInteractor.fetchUser({ id })
|
store.rootState.api.backendInteractor.fetchUser({ id })
|
||||||
.then((user) => store.commit('addNewUsers', [user]))
|
.then((user) => store.commit('addNewUsers', [user]))
|
||||||
},
|
},
|
||||||
|
fetchBlocks (store) {
|
||||||
|
const page = store.state.currentUser.blocksPage || 1
|
||||||
|
return store.rootState.api.backendInteractor.fetchBlocks({ page })
|
||||||
|
.then((blocks) => {
|
||||||
|
store.commit('addBlocks', { blocks, page })
|
||||||
|
return blocks
|
||||||
|
})
|
||||||
|
},
|
||||||
addFriends ({ rootState, commit }, fetchBy) {
|
addFriends ({ rootState, commit }, fetchBy) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const user = rootState.users.usersObject[fetchBy]
|
const user = rootState.users.usersObject[fetchBy]
|
||||||
|
|
|
@ -18,6 +18,7 @@ const MENTIONS_URL = '/api/statuses/mentions.json'
|
||||||
const DM_TIMELINE_URL = '/api/statuses/dm_timeline.json'
|
const DM_TIMELINE_URL = '/api/statuses/dm_timeline.json'
|
||||||
const FOLLOWERS_URL = '/api/statuses/followers.json'
|
const FOLLOWERS_URL = '/api/statuses/followers.json'
|
||||||
const FRIENDS_URL = '/api/statuses/friends.json'
|
const FRIENDS_URL = '/api/statuses/friends.json'
|
||||||
|
const BLOCKS_URL = '/api/statuses/blocks.json'
|
||||||
const FOLLOWING_URL = '/api/friendships/create.json'
|
const FOLLOWING_URL = '/api/friendships/create.json'
|
||||||
const UNFOLLOWING_URL = '/api/friendships/destroy.json'
|
const UNFOLLOWING_URL = '/api/friendships/destroy.json'
|
||||||
const QVITTER_USER_PREF_URL = '/api/qvitter/set_profile_pref.json'
|
const QVITTER_USER_PREF_URL = '/api/qvitter/set_profile_pref.json'
|
||||||
|
@ -519,6 +520,21 @@ const fetchMutes = ({credentials}) => {
|
||||||
}).then((data) => data.json())
|
}).then((data) => data.json())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fetchBlocks = ({page, credentials}) => {
|
||||||
|
let url = BLOCKS_URL
|
||||||
|
if (page) {
|
||||||
|
url = url + `?page=${page}`
|
||||||
|
}
|
||||||
|
return fetch(url, {
|
||||||
|
headers: authHeaders(credentials)
|
||||||
|
}).then((data) => {
|
||||||
|
if (data.ok) {
|
||||||
|
return data.json()
|
||||||
|
}
|
||||||
|
throw new Error('Error fetching blocks', data)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const suggestions = ({credentials}) => {
|
const suggestions = ({credentials}) => {
|
||||||
return fetch(SUGGESTIONS_URL, {
|
return fetch(SUGGESTIONS_URL, {
|
||||||
headers: authHeaders(credentials)
|
headers: authHeaders(credentials)
|
||||||
|
@ -560,6 +576,7 @@ const apiService = {
|
||||||
fetchAllFollowing,
|
fetchAllFollowing,
|
||||||
setUserMute,
|
setUserMute,
|
||||||
fetchMutes,
|
fetchMutes,
|
||||||
|
fetchBlocks,
|
||||||
register,
|
register,
|
||||||
getCaptcha,
|
getCaptcha,
|
||||||
updateAvatar,
|
updateAvatar,
|
||||||
|
|
|
@ -63,6 +63,7 @@ const backendInteractorService = (credentials) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchMutes = () => apiService.fetchMutes({credentials})
|
const fetchMutes = () => apiService.fetchMutes({credentials})
|
||||||
|
const fetchBlocks = (params) => apiService.fetchBlocks({credentials, ...params})
|
||||||
const fetchFollowRequests = () => apiService.fetchFollowRequests({credentials})
|
const fetchFollowRequests = () => apiService.fetchFollowRequests({credentials})
|
||||||
|
|
||||||
const getCaptcha = () => apiService.getCaptcha()
|
const getCaptcha = () => apiService.getCaptcha()
|
||||||
|
@ -94,6 +95,7 @@ const backendInteractorService = (credentials) => {
|
||||||
startFetching,
|
startFetching,
|
||||||
setUserMute,
|
setUserMute,
|
||||||
fetchMutes,
|
fetchMutes,
|
||||||
|
fetchBlocks,
|
||||||
register,
|
register,
|
||||||
getCaptcha,
|
getCaptcha,
|
||||||
updateAvatar,
|
updateAvatar,
|
||||||
|
|
|
@ -120,6 +120,7 @@ export const parseUser = (data) => {
|
||||||
if (data.pleroma) {
|
if (data.pleroma) {
|
||||||
output.follow_request_count = data.pleroma.follow_request_count
|
output.follow_request_count = data.pleroma.follow_request_count
|
||||||
}
|
}
|
||||||
|
output.blocks = []
|
||||||
|
|
||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue