forked from AkkomaGang/akkoma-fe
Add load more to blocks/mutes
This commit is contained in:
parent
35d10ab9ff
commit
29cfdcbbcd
4 changed files with 61 additions and 15 deletions
|
@ -1,9 +1,13 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="list">
|
<div
|
||||||
|
class="list"
|
||||||
|
role="list"
|
||||||
|
>
|
||||||
<div
|
<div
|
||||||
v-for="item in items"
|
v-for="item in items"
|
||||||
:key="getKey(item)"
|
:key="getKey(item)"
|
||||||
class="list-item"
|
class="list-item"
|
||||||
|
role="listitem"
|
||||||
>
|
>
|
||||||
<slot
|
<slot
|
||||||
name="item"
|
name="item"
|
||||||
|
|
|
@ -10,17 +10,20 @@ import SelectableList from 'src/components/selectable_list/selectable_list.vue'
|
||||||
import ProgressButton from 'src/components/progress_button/progress_button.vue'
|
import ProgressButton from 'src/components/progress_button/progress_button.vue'
|
||||||
import withSubscription from 'src/components/../hocs/with_subscription/with_subscription'
|
import withSubscription from 'src/components/../hocs/with_subscription/with_subscription'
|
||||||
import Checkbox from 'src/components/checkbox/checkbox.vue'
|
import Checkbox from 'src/components/checkbox/checkbox.vue'
|
||||||
|
import withLoadMore from 'src/components/../hocs/with_load_more/with_load_more'
|
||||||
|
|
||||||
const BlockList = withSubscription({
|
const BlockList = withLoadMore({
|
||||||
fetch: (props, $store) => $store.dispatch('fetchBlocks'),
|
fetch: (props, $store) => $store.dispatch('fetchBlocks'),
|
||||||
select: (props, $store) => get($store.state.users.currentUser, 'blockIds', []),
|
select: (props, $store) => get($store.state.users.currentUser, 'blockIds', []),
|
||||||
childPropName: 'items'
|
childPropName: 'items',
|
||||||
|
destroy: () => {}
|
||||||
})(SelectableList)
|
})(SelectableList)
|
||||||
|
|
||||||
const MuteList = withSubscription({
|
const MuteList = withLoadMore({
|
||||||
fetch: (props, $store) => $store.dispatch('fetchMutes'),
|
fetch: (props, $store) => $store.dispatch('fetchMutes'),
|
||||||
select: (props, $store) => get($store.state.users.currentUser, 'muteIds', []),
|
select: (props, $store) => get($store.state.users.currentUser, 'muteIds', []),
|
||||||
childPropName: 'items'
|
childPropName: 'items',
|
||||||
|
destroy: () => {}
|
||||||
})(SelectableList)
|
})(SelectableList)
|
||||||
|
|
||||||
const DomainMuteList = withSubscription({
|
const DomainMuteList = withSubscription({
|
||||||
|
|
|
@ -199,21 +199,28 @@ export const mutations = {
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
saveBlockIds (state, blockIds) {
|
saveBlockIds (state, blockIds) {
|
||||||
state.currentUser.blockIds = blockIds
|
console.log("ADDING BLOCK IDS", blockIds);
|
||||||
|
state.currentUser.blockIds = uniq(concat(state.currentUser.blockIds || [], blockIds))
|
||||||
},
|
},
|
||||||
addBlockId (state, blockId) {
|
addBlockId (state, blockId) {
|
||||||
if (state.currentUser.blockIds.indexOf(blockId) === -1) {
|
if (state.currentUser.blockIds.indexOf(blockId) === -1) {
|
||||||
state.currentUser.blockIds.push(blockId)
|
state.currentUser.blockIds.push(blockId)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
setBlockIdsMaxId (state, blockIdsMaxId) {
|
||||||
|
state.currentUser.blockIdsMaxId = blockIdsMaxId
|
||||||
|
},
|
||||||
saveMuteIds (state, muteIds) {
|
saveMuteIds (state, muteIds) {
|
||||||
state.currentUser.muteIds = muteIds
|
state.currentUser.muteIds = uniq(concat(state.currentUser.muteIds || [], muteIds))
|
||||||
},
|
},
|
||||||
addMuteId (state, muteId) {
|
addMuteId (state, muteId) {
|
||||||
if (state.currentUser.muteIds.indexOf(muteId) === -1) {
|
if (state.currentUser.muteIds.indexOf(muteId) === -1) {
|
||||||
state.currentUser.muteIds.push(muteId)
|
state.currentUser.muteIds.push(muteId)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
setMuteIdsMaxId (state, muteIdsMaxId) {
|
||||||
|
state.currentUser.muteIdsMaxId = muteIdsMaxId
|
||||||
|
},
|
||||||
updateMascot (state, mascotUrl) {
|
updateMascot (state, mascotUrl) {
|
||||||
state.currentUser.mascot = mascotUrl
|
state.currentUser.mascot = mascotUrl
|
||||||
},
|
},
|
||||||
|
@ -330,10 +337,21 @@ const users = {
|
||||||
.then((relationships) => store.commit('updateUserRelationship', relationships))
|
.then((relationships) => store.commit('updateUserRelationship', relationships))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
fetchBlocks (store) {
|
fetchBlocks (store, args) {
|
||||||
return store.rootState.api.backendInteractor.fetchBlocks()
|
const { reset } = args || {}
|
||||||
|
|
||||||
|
const maxId = store.state.currentUser.blockIdsMaxId
|
||||||
|
return store.rootState.api.backendInteractor.fetchBlocks({ maxId })
|
||||||
.then((blocks) => {
|
.then((blocks) => {
|
||||||
store.commit('saveBlockIds', map(blocks, 'id'))
|
store.commit('saveBlockIds', map(blocks, 'id'))
|
||||||
|
if (reset) {
|
||||||
|
store.commit('saveBlockIds', map(blocks, 'id'))
|
||||||
|
} else {
|
||||||
|
map(blocks, 'id').map(id => store.commit('addBlockId', id))
|
||||||
|
}
|
||||||
|
if (blocks.length) {
|
||||||
|
store.commit('setBlockIdsMaxId', last(blocks).id)
|
||||||
|
}
|
||||||
store.commit('addNewUsers', blocks)
|
store.commit('addNewUsers', blocks)
|
||||||
return blocks
|
return blocks
|
||||||
})
|
})
|
||||||
|
@ -353,10 +371,22 @@ const users = {
|
||||||
unblockUsers (store, ids = []) {
|
unblockUsers (store, ids = []) {
|
||||||
return Promise.all(ids.map(id => unblockUser(store, id)))
|
return Promise.all(ids.map(id => unblockUser(store, id)))
|
||||||
},
|
},
|
||||||
fetchMutes (store) {
|
fetchMutes (store, args) {
|
||||||
return store.rootState.api.backendInteractor.fetchMutes()
|
const { reset } = args || {}
|
||||||
|
|
||||||
|
const maxId = store.state.currentUser.muteIdsMaxId
|
||||||
|
return store.rootState.api.backendInteractor.fetchMutes({ maxId })
|
||||||
.then((mutes) => {
|
.then((mutes) => {
|
||||||
store.commit('saveMuteIds', map(mutes, 'id'))
|
store.commit('saveMuteIds', map(mutes, 'id'))
|
||||||
|
if (reset) {
|
||||||
|
store.commit('saveMuteIds', map(mutes, 'id'))
|
||||||
|
} else {
|
||||||
|
map(mutes, 'id').map(id => store.commit('addMuteId', id))
|
||||||
|
}
|
||||||
|
if (mutes.length) {
|
||||||
|
store.commit('setMuteIdsMaxId', last(mutes).id)
|
||||||
|
}
|
||||||
|
|
||||||
store.commit('addNewUsers', mutes)
|
store.commit('addNewUsers', mutes)
|
||||||
return mutes
|
return mutes
|
||||||
})
|
})
|
||||||
|
|
|
@ -1166,8 +1166,13 @@ const generateMfaBackupCodes = ({ credentials }) => {
|
||||||
}).then((data) => data.json())
|
}).then((data) => data.json())
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchMutes = ({ credentials }) => {
|
const fetchMutes = ({ maxId, credentials }) => {
|
||||||
return promisedRequest({ url: MASTODON_USER_MUTES_URL, credentials })
|
const query = new URLSearchParams({ with_relationships: true })
|
||||||
|
if (maxId) {
|
||||||
|
query.append('max_id', maxId)
|
||||||
|
}
|
||||||
|
|
||||||
|
return promisedRequest({ url: `${MASTODON_USER_MUTES_URL}?${query.toString()}`, credentials })
|
||||||
.then((users) => users.map(parseUser))
|
.then((users) => users.map(parseUser))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1213,8 +1218,12 @@ const unsubscribeUser = ({ id, credentials }) => {
|
||||||
return promisedRequest({ url: MASTODON_UNSUBSCRIBE_USER(id), credentials, method: 'POST' })
|
return promisedRequest({ url: MASTODON_UNSUBSCRIBE_USER(id), credentials, method: 'POST' })
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchBlocks = ({ credentials }) => {
|
const fetchBlocks = ({ maxId, credentials }) => {
|
||||||
return promisedRequest({ url: MASTODON_USER_BLOCKS_URL, credentials })
|
const query = new URLSearchParams({ with_relationships: true })
|
||||||
|
if (maxId) {
|
||||||
|
query.append('max_id', maxId)
|
||||||
|
}
|
||||||
|
return promisedRequest({ url: `${MASTODON_USER_BLOCKS_URL}?${query.toString()}`, credentials })
|
||||||
.then((users) => users.map(parseUser))
|
.then((users) => users.map(parseUser))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue