fix: remove attachment by id
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
Dominik Pschenitschni 2021-09-07 16:26:57 +02:00
parent c7c3ef79be
commit b201729cdd
Signed by: dpschen
GPG Key ID: B257AC0149F43A77
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 {findIndexById} from '@/helpers/find'
export default {
namespaced: true,
state: () => ({
@ -15,13 +17,9 @@ export default {
state.attachments.push(attachment)
},
removeById(state, id) {
for (const a in state.attachments) {
if (state.attachments[a].id === id) {
state.attachments.splice(a, 1)
console.debug('Remove attachement', id)
break
}
}
const attachmentIndex = findIndexById(state.attachments, id)
state.attachments.splice(attachmentIndex, 1)
console.debug('Remove attachement', id)
},
},
}