Skip to content

Commit 61ce318

Browse files
committed
Make Authors not optional in CffType
1 parent aa76018 commit 61ce318

3 files changed

Lines changed: 12 additions & 26 deletions

File tree

src/components/ScreenAuthors.vue

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -107,40 +107,27 @@ export default defineComponent({
107107
const { errors } = useValidation()
108108
const editingId = ref(0)
109109
const addAuthor = async () => {
110-
let newAuthors:AuthorType[]
111110
const newAuthor: AuthorType = {}
112-
if (authors.value === undefined) {
113-
newAuthors = [newAuthor]
114-
} else {
115-
newAuthors = [...authors.value, newAuthor]
116-
}
111+
const newAuthors = [...authors.value, newAuthor]
117112
setAuthors(newAuthors)
118113
editingId.value = newAuthors.length - 1
119114
// await the DOM update that resulted from updating the authors list
120115
await nextTick()
121116
scrollToBottom()
122117
}
123118
const removeAuthor = () => {
124-
if (authors.value !== undefined) {
125-
const newAuthors = [...authors.value]
126-
newAuthors.splice(editingId.value, 1)
127-
setAuthors(newAuthors)
128-
editingId.value = -1
129-
if (Array.isArray(newAuthors) && newAuthors.length === 0) {
130-
setAuthors([])
131-
}
132-
}
119+
const newAuthors = [...authors.value]
120+
newAuthors.splice(editingId.value, 1)
121+
setAuthors(newAuthors)
122+
editingId.value = -1
133123
}
134124
const setAuthorField = (field: keyof AuthorType, value: string) => {
135-
if (authors.value !== undefined) {
136-
const author = { ...authors.value[editingId.value] }
137-
author[field] = value === '' ? undefined : value
138-
authors.value[editingId.value] = author
139-
setAuthors(authors.value)
140-
}
125+
const author = { ...authors.value[editingId.value] }
126+
author[field] = value === '' ? undefined : value
127+
authors.value[editingId.value] = author
128+
setAuthors(authors.value)
141129
}
142130
const moveAuthorUp = (index: number) => {
143-
if (authors.value === undefined) return
144131
moveUp(index, authors.value, setAuthors)
145132
if (editingId.value === index && index > 0) {
146133
editingId.value = editingId.value - 1
@@ -149,7 +136,6 @@ export default defineComponent({
149136
}
150137
}
151138
const moveAuthorDown = (index: number) => {
152-
if (authors.value === undefined) return
153139
moveDown(index, authors.value, setAuthors)
154140
if (editingId.value === index && index < authors.value.length - 1) {
155141
editingId.value = editingId.value + 1

src/store/cff.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function useCff () {
4343
url: computed(() => cff.value.url),
4444
version: computed(() => cff.value.version),
4545
setAbstract: (newAbstract: string) => { cff.value.abstract = newAbstract === '' ? undefined : newAbstract },
46-
setAuthors: (newAuthors: AuthorsType) => { cff.value.authors = newAuthors === [] ? undefined : newAuthors },
46+
setAuthors: (newAuthors: AuthorsType) => { cff.value.authors = newAuthors },
4747
setCommit: (newCommit: string) => { cff.value.commit = newCommit === '' ? undefined : newCommit },
4848
setDateReleased: (newDateReleased: string) => { cff.value.dateReleased = newDateReleased === '' ? undefined : newDateReleased },
4949
setIdentifiers: (newIdentifiers: IdentifiersType) => { cff.value.identifiers = newIdentifiers === [] ? undefined : newIdentifiers },

src/types/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export type AuthorType = {
88
email?: string;
99
}
1010

11-
export type AuthorsType = Array<AuthorType> | undefined
11+
export type AuthorsType = Array<AuthorType>
1212

1313
export type IdentifierTypeType = 'doi' | 'url' | 'swh' | 'other'
1414
export type IdentifierType = {
@@ -25,7 +25,7 @@ export type TypeType = 'software' | 'dataset'
2525

2626
export type CffType = {
2727
abstract?: string,
28-
authors?: AuthorsType,
28+
authors: AuthorsType,
2929
cffVersion: string,
3030
commit?: string,
3131
dateReleased?: string,

0 commit comments

Comments
 (0)