Skip to content

Commit 887dcfa

Browse files
committed
Add remove button to view cards in Author and Identifiers screens
1 parent bcfdc6f commit 887dcfa

4 files changed

Lines changed: 36 additions & 10 deletions

File tree

src/components/AuthorCardViewing.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@
3838
title="Edit"
3939
v-on:click="$emit('editPressed')"
4040
/>
41+
<q-btn
42+
class="author-button"
43+
color="negative"
44+
hover-color="negative"
45+
icon="delete"
46+
title="Remove author"
47+
v-on:click="$emit('removePressed')"
48+
/>
4149
</div>
4250
</q-card>
4351
</template>
@@ -92,7 +100,7 @@ export default defineComponent({
92100
authorErrors
93101
}
94102
},
95-
emits: ['editPressed', 'moveDown', 'moveUp']
103+
emits: ['editPressed', 'moveDown', 'moveUp', 'removePressed']
96104
})
97105
</script>
98106
<style scoped>

src/components/IdentifierCardViewing.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@
3737
title="Edit"
3838
v-on:click="$emit('editPressed')"
3939
/>
40+
<q-btn
41+
class="identifier-button"
42+
color="negative"
43+
hover-color="negative"
44+
icon="delete"
45+
title="Remove Identifier"
46+
v-on:click="$emit('removePressed')"
47+
/>
4048
</div>
4149
</q-card>
4250
</template>
@@ -81,7 +89,7 @@ export default defineComponent({
8189
identifierErrors
8290
}
8391
},
84-
emits: ['editPressed', 'moveDown', 'moveUp']
92+
emits: ['editPressed', 'moveDown', 'moveUp', 'removePressed']
8593
})
8694
</script>
8795
<style scoped>

src/components/ScreenAuthors.vue

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@
2626
v-on:editPressed="() => (editingId = index)"
2727
v-on:moveDown="moveAuthorDown(index)"
2828
v-on:moveUp="moveAuthorUp(index)"
29+
v-on:removePressed="removeAuthor(index)"
2930
/>
3031
<AuthorCardEditing
3132
v-else
3233
v-bind:index="index"
3334
v-bind="author"
3435
v-on:update="setAuthorField"
3536
v-on:closePressed="() => (editingId = -1)"
36-
v-on:removePressed="removeAuthor"
37+
v-on:removePressed="removeAuthor(editingId)"
3738
/>
3839
</div>
3940
</div>
@@ -99,11 +100,15 @@ export default defineComponent({
99100
await nextTick()
100101
scrollToBottom()
101102
}
102-
const removeAuthor = () => {
103+
const removeAuthor = (index: number) => {
103104
const newAuthors = [...authors.value]
104-
newAuthors.splice(editingId.value, 1)
105+
newAuthors.splice(index, 1)
105106
setAuthors(newAuthors)
106-
editingId.value = -1
107+
if (index < editingId.value) {
108+
editingId.value -= 1
109+
} else if (index === editingId.value) {
110+
editingId.value = -1
111+
}
107112
}
108113
const setAuthorField = (field: keyof AuthorType, value: string) => {
109114
const newAuthor = { ...authors.value[editingId.value] }

src/components/ScreenIdentifiers.vue

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
v-on:editPressed="() => (editingId = index)"
2727
v-on:moveDown="moveIdentifierDown(index)"
2828
v-on:moveUp="moveIdentifierUp(index)"
29+
v-on:removePressed="removeIdentifier(index)"
2930
/>
3031
<IdentifierCardEditing
3132
v-else
@@ -35,7 +36,7 @@
3536
v-on:updateValue="setIdentifierValueField"
3637
v-on:updateDescription="setIdentifierDescriptionField"
3738
v-on:closePressed="() => (editingId = -1)"
38-
v-on:removePressed="removeIdentifier"
39+
v-on:removePressed="removeIdentifier(editingId)"
3940
/>
4041
</div>
4142
</div>
@@ -109,12 +110,16 @@ export default defineComponent({
109110
await nextTick()
110111
scrollToBottom()
111112
}
112-
const removeIdentifier = () => {
113+
const removeIdentifier = (index: number) => {
113114
if (identifiers.value !== undefined) {
114115
const newIdentifiers = [...identifiers.value]
115-
newIdentifiers.splice(editingId.value, 1)
116+
newIdentifiers.splice(index, 1)
116117
setIdentifiers(newIdentifiers)
117-
editingId.value = -1
118+
if (index < editingId.value) {
119+
editingId.value -= 1
120+
} else if (index === editingId.value) {
121+
editingId.value = -1
122+
}
118123
if (Array.isArray(newIdentifiers) && newIdentifiers.length === 0) {
119124
setIdentifiers(undefined)
120125
}

0 commit comments

Comments
 (0)