Skip to content

Commit ab65b9c

Browse files
committed
refactor: continue TS migration
Signed-off-by: Christian Hartmann <chris-hartmann@gmx.de>
1 parent b8eb1a0 commit ab65b9c

34 files changed

Lines changed: 1799 additions & 1030 deletions

package-lock.json

Lines changed: 53 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"lint:fix": "eslint --ext .js,.ts,.vue src --fix",
2424
"start:nextcloud": "node playwright/start-nextcloud-server.mjs",
2525
"stylelint": "stylelint \"src/**/*.scss\" \"src/**/*.vue\"",
26-
"stylelint:fix": "stylelint \"src/**/*.scss\" \"src/**/*.vue\" --fix"
26+
"stylelint:fix": "stylelint \"src/**/*.scss\" \"src/**/*.vue\" --fix",
27+
"typecheck": "vue-tsc --noEmit -p tsconfig.json"
2728
},
2829
"browserslist": [
2930
"extends @nextcloud/browserslist-config"
@@ -59,11 +60,13 @@
5960
"@nextcloud/vite-config": "^2.5.2",
6061
"@playwright/test": "^1.61.1",
6162
"@types/node": "^26.1.0",
63+
"@types/qrcode": "^1.5.6",
6264
"@vue/tsconfig": "^0.9.1",
6365
"eslint-config-prettier": "^10.1.8",
6466
"eslint-plugin-prettier": "^5.5.6",
6567
"prettier": "^3.9.4",
66-
"vite": "^7.3.6"
68+
"vite": "^7.3.6",
69+
"vue-tsc": "^3.3.7"
6770
},
6871
"engines": {
6972
"node": "^24.0.0",

src/components/AppNavigationForm.vue

Lines changed: 47 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@
9797
</NcListItem>
9898
</template>
9999

100-
<script>
100+
<script lang="ts">
101+
import type { PropType } from 'vue'
102+
import type { FormsForm } from '../models/Entities.d.ts'
103+
101104
import IconArchive from '@material-symbols/svg-400/outlined/archive.svg?raw'
102105
import IconPoll from '@material-symbols/svg-400/outlined/bar_chart.svg?raw'
103106
import IconCheck from '@material-symbols/svg-400/outlined/check.svg?raw'
@@ -109,8 +112,10 @@ import IconArchiveOff from '@material-symbols/svg-400/outlined/unarchive.svg?raw
109112
import { getCurrentUser } from '@nextcloud/auth'
110113
import axios from '@nextcloud/axios'
111114
import { showConfirmation, showError } from '@nextcloud/dialogs'
115+
import { translate as t } from '@nextcloud/l10n'
112116
import moment from '@nextcloud/moment'
113117
import { generateOcsUrl } from '@nextcloud/router'
118+
import { defineComponent } from 'vue'
114119
import NcActionButton from '@nextcloud/vue/components/NcActionButton'
115120
import NcActionRouter from '@nextcloud/vue/components/NcActionRouter'
116121
import NcActionSeparator from '@nextcloud/vue/components/NcActionSeparator'
@@ -122,7 +127,13 @@ import PermissionTypes from '../mixins/PermissionTypes.ts'
122127
import { FormState } from '../models/Constants.ts'
123128
import logger from '../utils/Logger.ts'
124129
125-
export default {
130+
type NavigationTarget = 'submit' | 'formRoot'
131+
132+
interface AppNavigationFormData {
133+
loading: boolean
134+
}
135+
136+
export default defineComponent({
126137
name: 'AppNavigationForm',
127138
128139
components: {
@@ -138,7 +149,7 @@ export default {
138149
139150
props: {
140151
form: {
141-
type: Object,
152+
type: Object as PropType<FormsForm>,
142153
required: true,
143154
},
144155
@@ -158,6 +169,7 @@ export default {
158169
159170
setup() {
160171
return {
172+
t,
161173
FormsIcon,
162174
IconArchive,
163175
IconArchiveOff,
@@ -170,65 +182,67 @@ export default {
170182
}
171183
},
172184
173-
data() {
185+
data(): AppNavigationFormData {
174186
return {
175187
loading: false,
176188
}
177189
},
178190
179191
computed: {
180-
canEdit() {
192+
canEdit(): boolean {
181193
return this.form.permissions.includes(
182194
this.PERMISSION_TYPES.PERMISSION_EDIT,
183195
)
184196
},
185197
186-
canSeeResults() {
198+
canSeeResults(): boolean {
187199
return (
188200
this.form.permissions.includes(
189201
this.PERMISSION_TYPES.PERMISSION_RESULTS,
190-
) || this.form.submissionCount > 0
202+
) || (this.form.submissionCount ?? 0) > 0
191203
)
192204
},
193205
194206
/**
195207
* Check if form is current form and set active
196208
*/
197-
isActive() {
198-
return this.form.hash === this.$route.params.hash
209+
isActive(): boolean {
210+
return this.form.hash === String(this.$route.params.hash)
199211
},
200212
201213
/**
202214
* Check if the form is archived
203215
*/
204-
isArchived() {
216+
isArchived(): boolean {
205217
return this.form.state === FormState.FormArchived
206218
},
207219
208220
/**
209221
* Check if form is expired
210222
*/
211-
isExpired() {
212-
return this.form.expires && moment().unix() > this.form.expires
223+
isExpired(): boolean {
224+
return Boolean(this.form.expires && moment().unix() > this.form.expires)
213225
},
214226
215227
/**
216228
* Check if form is locked
217229
*/
218-
isFormLocked() {
230+
isFormLocked(): boolean {
231+
const currentUserUid = getCurrentUser()?.uid ?? ''
232+
const lockedUntil = this.form.lockedUntil ?? -1
219233
return (
220-
this.form.lockedUntil === 0
221-
|| (this.form.lockedUntil > moment().unix()
222-
&& this.form.lockedBy !== getCurrentUser().uid)
234+
lockedUntil === 0
235+
|| (lockedUntil > moment().unix()
236+
&& this.form.lockedBy !== currentUserUid)
223237
)
224238
},
225239
226240
/**
227241
* Return form title, or placeholder if not set
228242
*
229-
* @return {string}
243+
* @return
230244
*/
231-
formTitle() {
245+
formTitle(): string {
232246
if (this.form.title) {
233247
return this.form.title
234248
}
@@ -238,7 +252,7 @@ export default {
238252
/**
239253
* Return expiration details for subtitle
240254
*/
241-
formSubtitle() {
255+
formSubtitle(): string {
242256
if (this.form.state === FormState.FormClosed) {
243257
// TRANSLATORS: The form was closed manually so it does not take new submissions
244258
return t('forms', 'Form closed')
@@ -258,16 +272,16 @@ export default {
258272
/**
259273
* Return, if form has Subtitle
260274
*/
261-
hasSubtitle() {
275+
hasSubtitle(): boolean {
262276
return this.formSubtitle !== ''
263277
},
264278
265279
/**
266280
* Route to use, depending on readOnly
267281
*
268-
* @return {string} Route to 'submit' or 'formRoot'
282+
* @return Route to 'submit' or 'formRoot'
269283
*/
270-
routerTarget() {
284+
routerTarget(): NavigationTarget {
271285
if (this.readOnly) {
272286
return 'submit'
273287
}
@@ -280,19 +294,19 @@ export default {
280294
/**
281295
* Closes the App-Navigation on mobile-devices
282296
*/
283-
mobileCloseNavigation() {
297+
mobileCloseNavigation(): void {
284298
this.$emit('mobileCloseNavigation')
285299
},
286300
287-
onShareForm() {
301+
onShareForm(): void {
288302
this.$emit('openSharing', this.form.hash)
289303
},
290304
291-
onCloneForm() {
305+
onCloneForm(): void {
292306
this.$emit('clone', this.form.id)
293307
},
294308
295-
async onConfirmDelete() {
309+
async onConfirmDelete(): Promise<void> {
296310
const shouldDelete = await showConfirmation({
297311
name: t('forms', 'Delete form'),
298312
text: t('forms', 'Are you sure you want to delete {title}?', {
@@ -307,7 +321,7 @@ export default {
307321
}
308322
},
309323
310-
async onToggleArchive() {
324+
async onToggleArchive(): Promise<void> {
311325
try {
312326
// TODO: add loading status feedback ?
313327
await axios.patch(
@@ -322,8 +336,8 @@ export default {
322336
},
323337
},
324338
)
325-
// eslint-disable-next-line vue/no-mutating-props
326-
this.form.state = this.isArchived
339+
340+
;(this.form as FormsForm).state = this.isArchived
327341
? FormState.FormClosed
328342
: FormState.FormArchived
329343
} catch (error) {
@@ -334,7 +348,7 @@ export default {
334348
}
335349
},
336350
337-
async onDeleteForm() {
351+
async onDeleteForm(): Promise<void> {
338352
this.loading = true
339353
try {
340354
await axios.delete(
@@ -344,8 +358,9 @@ export default {
344358
)
345359
this.$emit('delete', this.form.id)
346360
} catch (error) {
361+
const response = (error as { response?: unknown }).response
347362
logger.error(`Error while deleting ${this.formTitle}`, {
348-
error: error.response,
363+
error: response,
349364
})
350365
showError(
351366
t('forms', 'Error while deleting {title}', {
@@ -357,5 +372,5 @@ export default {
357372
}
358373
},
359374
},
360-
}
375+
})
361376
</script>

0 commit comments

Comments
 (0)