forked from AkkomaGang/admin-fe
Add optimistic update for managing files in pack
This commit is contained in:
parent
ab77704c97
commit
fbcc5ee524
1 changed files with 19 additions and 8 deletions
|
@ -89,10 +89,12 @@ const emojiPacks = {
|
||||||
|
|
||||||
commit('UPDATE_LOCAL_PACK_FILES', { name: packName, files: result.data })
|
commit('UPDATE_LOCAL_PACK_FILES', { name: packName, files: result.data })
|
||||||
},
|
},
|
||||||
async DeleteEmojiFile({ commit, getters }, { packName, shortcode }) {
|
async DeleteEmojiFile({ commit, dispatch, getters, state }, { packName, shortcode }) {
|
||||||
let result
|
const { [shortcode]: value, ...updatedPackFiles } = state.localPacks[packName].files
|
||||||
|
commit('UPDATE_LOCAL_PACK_FILES', { name: packName, files: updatedPackFiles })
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = await deleteEmojiFile(packName, shortcode, getters.authHost, getters.token)
|
await deleteEmojiFile(packName, shortcode, getters.authHost, getters.token)
|
||||||
} catch (_e) {
|
} catch (_e) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -102,7 +104,7 @@ const emojiPacks = {
|
||||||
duration: 5 * 1000
|
duration: 5 * 1000
|
||||||
})
|
})
|
||||||
|
|
||||||
commit('UPDATE_LOCAL_PACK_FILES', { name: packName, files: result.data })
|
dispatch('FetchSinglePack', { name: packName, page: state.currentFilesPage })
|
||||||
},
|
},
|
||||||
async CreatePack({ getters }, { name }) {
|
async CreatePack({ getters }, { name }) {
|
||||||
await createPack(getters.authHost, getters.token, name)
|
await createPack(getters.authHost, getters.token, name)
|
||||||
|
@ -189,10 +191,19 @@ const emojiPacks = {
|
||||||
SetRemoteInstance({ commit }, instance) {
|
SetRemoteInstance({ commit }, instance) {
|
||||||
commit('SET_REMOTE_INSTANCE', instance)
|
commit('SET_REMOTE_INSTANCE', instance)
|
||||||
},
|
},
|
||||||
async UpdateEmojiFile({ commit, getters }, { packName, shortcode, newShortcode, newFilename, force }) {
|
async UpdateEmojiFile({ commit, dispatch, getters, state }, { packName, shortcode, newShortcode, newFilename, force }) {
|
||||||
let result
|
const updatedPackFiles = Object.keys(state.localPacks[packName].files).reduce((acc, el) => {
|
||||||
|
if (el === shortcode) {
|
||||||
|
acc[newShortcode] = newFilename
|
||||||
|
} else {
|
||||||
|
acc[el] = state.localPacks[packName].files[el]
|
||||||
|
}
|
||||||
|
return acc
|
||||||
|
}, {})
|
||||||
|
commit('UPDATE_LOCAL_PACK_FILES', { name: packName, files: updatedPackFiles })
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = await updateEmojiFile(packName, shortcode, newShortcode, newFilename, force, getters.authHost, getters.token)
|
await updateEmojiFile(packName, shortcode, newShortcode, newFilename, force, getters.authHost, getters.token)
|
||||||
} catch (_e) {
|
} catch (_e) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -202,7 +213,7 @@ const emojiPacks = {
|
||||||
duration: 5 * 1000
|
duration: 5 * 1000
|
||||||
})
|
})
|
||||||
|
|
||||||
commit('UPDATE_LOCAL_PACK_FILES', { name: packName, files: result.data })
|
dispatch('FetchSinglePack', { name: packName, page: state.currentFilesPage })
|
||||||
},
|
},
|
||||||
async UpdateLocalPackVal({ commit }, args) {
|
async UpdateLocalPackVal({ commit }, args) {
|
||||||
commit('UPDATE_LOCAL_PACK_VAL', args)
|
commit('UPDATE_LOCAL_PACK_VAL', args)
|
||||||
|
|
Loading…
Reference in a new issue