fix: remove attachment by id (#725)

Co-authored-by: Dominik Pschenitschni <mail@celement.de>
Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/725
Co-authored-by: dpschen <dpschen@noreply.kolaente.de>
Co-committed-by: dpschen <dpschen@noreply.kolaente.de>
This commit is contained in:
dpschen 2021-09-10 12:50:41 +00:00 committed by konrad
parent 7ab308b846
commit 0376ef53e3
2 changed files with 8 additions and 7 deletions

3
src/helpers/find.ts Normal file
View file

@ -0,0 +1,3 @@
export function findIndexById(array : [], id : string | number) {
return array.findIndex(({id: currentId}) => currentId === id)
}

View file

@ -1,5 +1,7 @@
import Vue from 'vue' import Vue from 'vue'
import {findIndexById} from '@/helpers/find'
export default { export default {
namespaced: true, namespaced: true,
state: () => ({ state: () => ({
@ -15,13 +17,9 @@ export default {
state.attachments.push(attachment) state.attachments.push(attachment)
}, },
removeById(state, id) { removeById(state, id) {
for (const a in state.attachments) { const attachmentIndex = findIndexById(state.attachments, id)
if (state.attachments[a].id === id) { state.attachments.splice(attachmentIndex, 1)
state.attachments.splice(a, 1)
console.debug('Remove attachement', id) console.debug('Remove attachement', id)
break
}
}
}, },
}, },
} }