forked from AkkomaGang/admin-fe
Add pagination to local emoji packs
This commit is contained in:
parent
8d23e36a54
commit
918bd18b88
4 changed files with 55 additions and 20 deletions
|
@ -86,11 +86,12 @@ export async function importFromFS(host, token) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function listPacks(host) {
|
export async function listPacks(page, pageSize, host, token) {
|
||||||
return await request({
|
return await request({
|
||||||
baseURL: baseName(host),
|
baseURL: baseName(host),
|
||||||
url: `/api/pleroma/emoji/packs/`,
|
url: `/api/pleroma/emoji/packs?page=${page}&page_size=${pageSize}`,
|
||||||
method: 'get'
|
method: 'get',
|
||||||
|
headers: authHeaders(token)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,10 @@ import Vue from 'vue'
|
||||||
const emojiPacks = {
|
const emojiPacks = {
|
||||||
state: {
|
state: {
|
||||||
activeCollapseItems: [],
|
activeCollapseItems: [],
|
||||||
|
currentPage: 1,
|
||||||
localPacks: {},
|
localPacks: {},
|
||||||
|
localPacksCount: 0,
|
||||||
|
pageSize: 20,
|
||||||
remoteInstance: '',
|
remoteInstance: '',
|
||||||
remotePacks: {}
|
remotePacks: {}
|
||||||
},
|
},
|
||||||
|
@ -31,6 +34,9 @@ const emojiPacks = {
|
||||||
SET_LOCAL_PACKS: (state, packs) => {
|
SET_LOCAL_PACKS: (state, packs) => {
|
||||||
state.localPacks = packs
|
state.localPacks = packs
|
||||||
},
|
},
|
||||||
|
SET_LOCAL_PACKS_COUNT: (state, count) => {
|
||||||
|
state.localPacksCount = count
|
||||||
|
},
|
||||||
SET_PACK_FILES: (state, { name, files }) => {
|
SET_PACK_FILES: (state, { name, files }) => {
|
||||||
state.localPacks = { ...state.localPacks, [name]: { ...state.localPacks[name], files }}
|
state.localPacks = { ...state.localPacks, [name]: { ...state.localPacks[name], files }}
|
||||||
},
|
},
|
||||||
|
@ -103,7 +109,18 @@ const emojiPacks = {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async FetchPack({ getters, commit }, name) {
|
async FetchLocalEmojiPacks({ commit, getters, state }, page) {
|
||||||
|
const { data } = await listPacks(page, state.pageSize, getters.authHost, getters.token)
|
||||||
|
const { packs, count } = data
|
||||||
|
const updatedPacks = Object.keys(packs).reduce((acc, packName) => {
|
||||||
|
const { files, ...pack } = packs[packName]
|
||||||
|
acc[packName] = pack
|
||||||
|
return acc
|
||||||
|
}, {})
|
||||||
|
commit('SET_LOCAL_PACKS', updatedPacks)
|
||||||
|
commit('SET_LOCAL_PACKS_COUNT', count)
|
||||||
|
},
|
||||||
|
async FetchSinglePack({ getters, commit }, name) {
|
||||||
const { data } = await fetchPack(name, getters.authHost, getters.token)
|
const { data } = await fetchPack(name, getters.authHost, getters.token)
|
||||||
commit('SET_PACK_FILES', { name, files: data.files })
|
commit('SET_PACK_FILES', { name, files: data.files })
|
||||||
},
|
},
|
||||||
|
@ -147,15 +164,6 @@ const emojiPacks = {
|
||||||
SetActiveCollapseItems({ commit }, activeItems) {
|
SetActiveCollapseItems({ commit }, activeItems) {
|
||||||
commit('SET_ACTIVE_COLLAPSE_ITEMS', activeItems)
|
commit('SET_ACTIVE_COLLAPSE_ITEMS', activeItems)
|
||||||
},
|
},
|
||||||
async SetLocalEmojiPacks({ commit, getters }) {
|
|
||||||
const { data } = await listPacks(getters.authHost)
|
|
||||||
const packs = Object.keys(data).reduce((acc, packName) => {
|
|
||||||
const { files, ...pack } = data[packName]
|
|
||||||
acc[packName] = pack
|
|
||||||
return acc
|
|
||||||
}, {})
|
|
||||||
commit('SET_LOCAL_PACKS', packs)
|
|
||||||
},
|
|
||||||
async SetRemoteEmojiPacks({ commit, getters }, { remoteInstance }) {
|
async SetRemoteEmojiPacks({ commit, getters }, { remoteInstance }) {
|
||||||
const { data } = await listRemotePacks(getters.authHost, getters.token, remoteInstance)
|
const { data } = await listRemotePacks(getters.authHost, getters.token, remoteInstance)
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
<el-tab-pane :label="$t('emoji.localPacks')" name="local">
|
<el-tab-pane :label="$t('emoji.localPacks')" name="local">
|
||||||
<el-form :label-width="labelWidth" class="emoji-packs-form">
|
<el-form :label-width="labelWidth" class="emoji-packs-form">
|
||||||
<el-form-item :label="$t('emoji.localPacks')">
|
<el-form-item :label="$t('emoji.localPacks')">
|
||||||
<el-button type="primary" @click="refreshLocalPacks">{{ $t('emoji.refreshLocalPacks') }}</el-button>
|
<el-button @click="refreshLocalPacks">{{ $t('emoji.refreshLocalPacks') }}</el-button>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item :label="$t('emoji.createLocalPack')">
|
<el-form-item :label="$t('emoji.createLocalPack')">
|
||||||
<div class="create-pack">
|
<div class="create-pack">
|
||||||
|
@ -37,6 +37,16 @@
|
||||||
</el-collapse>
|
</el-collapse>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
|
<div class="pagination">
|
||||||
|
<el-pagination
|
||||||
|
:total="localPacksCount"
|
||||||
|
:current-page="currentPage"
|
||||||
|
:page-size="pageSize"
|
||||||
|
hide-on-single-page
|
||||||
|
layout="prev, pager, next"
|
||||||
|
@current-change="handlePageChange"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</el-tab-pane>
|
</el-tab-pane>
|
||||||
<el-tab-pane :label="$t('emoji.remotePacks')" name="remote">
|
<el-tab-pane :label="$t('emoji.remotePacks')" name="remote">
|
||||||
<el-form :label-width="labelWidth" class="emoji-packs-form">
|
<el-form :label-width="labelWidth" class="emoji-packs-form">
|
||||||
|
@ -83,6 +93,9 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
currentPage() {
|
||||||
|
return this.$store.state.emojiPacks.currentPage
|
||||||
|
},
|
||||||
isMobile() {
|
isMobile() {
|
||||||
return this.$store.state.app.device === 'mobile'
|
return this.$store.state.app.device === 'mobile'
|
||||||
},
|
},
|
||||||
|
@ -95,12 +108,18 @@ export default {
|
||||||
} else if (this.isTablet) {
|
} else if (this.isTablet) {
|
||||||
return '180px'
|
return '180px'
|
||||||
} else {
|
} else {
|
||||||
return '240px'
|
return '200px'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
localPacks() {
|
localPacks() {
|
||||||
return this.$store.state.emojiPacks.localPacks
|
return this.$store.state.emojiPacks.localPacks
|
||||||
},
|
},
|
||||||
|
localPacksCount() {
|
||||||
|
return this.$store.state.emojiPacks.localPacksCount
|
||||||
|
},
|
||||||
|
pageSize() {
|
||||||
|
return this.$store.state.emojiPacks.pageSize
|
||||||
|
},
|
||||||
remoteInstanceAddress: {
|
remoteInstanceAddress: {
|
||||||
get() {
|
get() {
|
||||||
return this.$store.state.emojiPacks.remoteInstance
|
return this.$store.state.emojiPacks.remoteInstance
|
||||||
|
@ -124,20 +143,23 @@ export default {
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.newPackName = ''
|
this.newPackName = ''
|
||||||
|
|
||||||
this.$store.dispatch('SetLocalEmojiPacks')
|
this.$store.dispatch('FetchLocalEmojiPacks')
|
||||||
this.$store.dispatch('ReloadEmoji')
|
this.$store.dispatch('ReloadEmoji')
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
handlePageChange(page) {
|
||||||
|
this.$store.dispatch('FetchLocalEmojiPacks', page)
|
||||||
|
},
|
||||||
importFromFS() {
|
importFromFS() {
|
||||||
this.$store.dispatch('ImportFromFS')
|
this.$store.dispatch('ImportFromFS')
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.$store.dispatch('SetLocalEmojiPacks')
|
this.$store.dispatch('FetchLocalEmojiPacks')
|
||||||
this.$store.dispatch('ReloadEmoji')
|
this.$store.dispatch('ReloadEmoji')
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
refreshLocalPacks() {
|
refreshLocalPacks() {
|
||||||
try {
|
try {
|
||||||
this.$store.dispatch('SetLocalEmojiPacks')
|
this.$store.dispatch('FetchLocalEmojiPacks', 1)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -188,7 +210,7 @@ export default {
|
||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
.emoji-packs-form {
|
.emoji-packs-form {
|
||||||
margin: 0 30px;
|
margin-top: 15px;
|
||||||
}
|
}
|
||||||
.emoji-packs-header {
|
.emoji-packs-header {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
@ -213,6 +235,10 @@ h1 {
|
||||||
border: 1px solid #eee;
|
border: 1px solid #eee;
|
||||||
margin-bottom: 22px;
|
margin-bottom: 22px;
|
||||||
}
|
}
|
||||||
|
.pagination {
|
||||||
|
margin: 25px 0;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
.reboot-button {
|
.reboot-button {
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
|
|
@ -95,7 +95,7 @@
|
||||||
:total="usersCount"
|
:total="usersCount"
|
||||||
:current-page="currentPage"
|
:current-page="currentPage"
|
||||||
:page-size="pageSize"
|
:page-size="pageSize"
|
||||||
background
|
hide-on-single-page
|
||||||
layout="prev, pager, next"
|
layout="prev, pager, next"
|
||||||
@current-change="handlePageChange"
|
@current-change="handlePageChange"
|
||||||
/>
|
/>
|
||||||
|
|
Loading…
Reference in a new issue