Skip to content

Commit 07c8468

Browse files
committed
chore: use constant for debounce and add other contstants definitions
Signed-off-by: Christian Hartmann <chris-hartmann@gmx.de>
1 parent 32496ba commit 07c8468

14 files changed

Lines changed: 74 additions & 39 deletions

src/Forms.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ import OcsResponse2Data from './utils/OcsResponse2Data.js'
165165
import PermissionTypes from './mixins/PermissionTypes.js'
166166
import Sidebar from './views/Sidebar.vue'
167167
import logger from './utils/Logger.js'
168-
import { FormState } from './models/FormStates.ts'
168+
import { FormState } from './models/Constants.ts'
169169
170170
export default {
171171
name: 'Forms',

src/components/AppNavigationForm.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ import IconDeleteSvg from '@mdi/svg/svg/delete.svg?raw'
123123
124124
import FormsIcon from './Icons/FormsIcon.vue'
125125
126-
import { FormState } from '../models/FormStates.ts'
126+
import { FormState } from '../models/Constants.ts'
127127
import PermissionTypes from '../mixins/PermissionTypes.js'
128128
import logger from '../utils/Logger.js'
129129

src/components/Questions/AnswerInput.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ import NcActions from '@nextcloud/vue/components/NcActions'
8585
import NcActionButton from '@nextcloud/vue/components/NcActionButton'
8686
import NcButton from '@nextcloud/vue/components/NcButton'
8787
88+
import { INPUT_DEBOUNCE_MS } from '../../models/Constants.ts'
8889
import OcsResponse2Data from '../../utils/OcsResponse2Data.js'
8990
import logger from '../../utils/Logger.js'
9091
@@ -174,7 +175,7 @@ export default {
174175
// As data instead of method, to have a separate debounce per AnswerInput
175176
this.debounceOnInput = debounce((event) => {
176177
return this.queue.add(() => this.onInput(event))
177-
}, 400)
178+
}, INPUT_DEBOUNCE_MS)
178179
},
179180
180181
methods: {

src/components/Questions/QuestionFile.vue

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,19 +156,14 @@ import NcLoadingIcon from '@nextcloud/vue/components/NcLoadingIcon'
156156
import OcsResponse2Data from '../../utils/OcsResponse2Data.js'
157157
import QuestionMixin from '../../mixins/QuestionMixin.js'
158158
import axios from '@nextcloud/axios'
159+
import { FILE_SIZE_UNITS } from '../../models/Constants.ts'
159160
import fileTypes from '../../models/FileTypes.js'
160161
import logger from '../../utils/Logger.js'
161162
import { generateOcsUrl } from '@nextcloud/router'
162163
import { loadState } from '@nextcloud/initial-state'
163164
import { showError } from '@nextcloud/dialogs'
164165
import { formatFileSize } from '@nextcloud/files'
165166
166-
const FILE_SIZE_UNITS = {
167-
kb: 1024,
168-
mb: 1024 ** 2,
169-
gb: 1024 ** 3,
170-
}
171-
172167
export default {
173168
name: 'QuestionFile',
174169
components: {

src/components/Questions/QuestionMultiple.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,11 @@ import IconContentPaste from 'vue-material-design-icons/ContentPaste.vue'
194194
import IconRadioboxBlank from 'vue-material-design-icons/RadioboxBlank.vue'
195195
196196
import AnswerInput from './AnswerInput.vue'
197+
import { QUESTION_EXTRASETTINGS_OTHER_PREFIX } from '../../models/Constants.ts'
197198
import QuestionMixin from '../../mixins/QuestionMixin.js'
198199
import OptionInputDialog from '../OptionInputDialog.vue'
199200
import QuestionMultipleMixin from '../../mixins/QuestionMultipleMixin.ts'
200201
201-
const QUESTION_EXTRASETTINGS_OTHER_PREFIX = 'system-other-answer:'
202-
203202
export default {
204203
name: 'QuestionMultiple',
205204

src/components/SidebarTabs/SettingsSidebarTab.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ import TransferOwnership from './TransferOwnership.vue'
138138
139139
import { directive as ClickOutside } from 'v-click-outside'
140140
import { loadState } from '@nextcloud/initial-state'
141-
import { FormState } from '../../models/FormStates.ts'
141+
import { FormState } from '../../models/Constants.ts'
142142
143143
export default {
144144
components: {

src/mixins/QuestionMixin.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { generateOcsUrl } from '@nextcloud/router'
88
import axios from '@nextcloud/axios'
99
import debounce from 'debounce'
1010

11+
import { INPUT_DEBOUNCE_MS } from '../models/Constants.ts'
1112
import logger from '../utils/Logger.js'
1213
import OcsResponse2Data from '../utils/OcsResponse2Data.js'
1314
import Question from '../components/Questions/Question.vue'
@@ -214,7 +215,7 @@ export default {
214215
onTitleChange: debounce(function (text) {
215216
this.$emit('update:text', text)
216217
this.saveQuestionProperty('text', text)
217-
}, 400),
218+
}, INPUT_DEBOUNCE_MS),
218219

219220
/**
220221
* Forward the description change to the parent and store to db
@@ -224,7 +225,7 @@ export default {
224225
onDescriptionChange: debounce(function (description) {
225226
this.$emit('update:description', description)
226227
this.saveQuestionProperty('description', description)
227-
}, 400),
228+
}, INPUT_DEBOUNCE_MS),
228229

229230
/**
230231
* Forward the required change to the parent and store to db
@@ -234,7 +235,7 @@ export default {
234235
onRequiredChange: debounce(function (isRequiredValue) {
235236
this.$emit('update:isRequired', isRequiredValue)
236237
this.saveQuestionProperty('isRequired', isRequiredValue)
237-
}, 400),
238+
}, INPUT_DEBOUNCE_MS),
238239

239240
/**
240241
* Create mapper to forward the required change to the parent and store to db
@@ -247,7 +248,7 @@ export default {
247248
const newExtraSettings = { ...this.extraSettings, ...newSettings }
248249
this.$emit('update:extraSettings', newExtraSettings)
249250
this.saveQuestionProperty('extraSettings', newExtraSettings)
250-
}, 400),
251+
}, INPUT_DEBOUNCE_MS),
251252

252253
/**
253254
* Forward the technical-name change to the parent and store to db
@@ -257,7 +258,7 @@ export default {
257258
onNameChange: debounce(function (name) {
258259
this.$emit('update:name', name)
259260
this.saveQuestionProperty('name', name)
260-
}, 400),
261+
}, INPUT_DEBOUNCE_MS),
261262

262263
/**
263264
* Forward the required change to the parent and store to db

src/mixins/QuestionMultipleMixin.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { translate as t } from '@nextcloud/l10n'
1111
import { generateOcsUrl } from '@nextcloud/router'
1212
import { defineComponent } from 'vue'
1313

14+
import { INPUT_DEBOUNCE_MS } from '../models/Constants.ts'
1415
import axios from '@nextcloud/axios'
1516
import debounce from 'debounce'
1617
import logger from '../utils/Logger'
@@ -82,7 +83,7 @@ export default defineComponent({
8283
* Debounced function to save options order
8384
*/
8485
onOptionsReordered() {
85-
return debounce(this.saveOptionsOrder, 400)
86+
return debounce(this.saveOptionsOrder, INPUT_DEBOUNCE_MS)
8687
},
8788
},
8889

src/mixins/UserSearchMixin.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { getCurrentUser } from '@nextcloud/auth'
77
import axios from '@nextcloud/axios'
88
import debounce from 'debounce'
99

10+
import { INPUT_DEBOUNCE_MS } from '../models/Constants.ts'
1011
import OcsResponse2Data from '../utils/OcsResponse2Data.js'
1112
import logger from '../utils/Logger.js'
1213
import ShareTypes from './ShareTypes.js'
@@ -76,7 +77,7 @@ export default {
7677
*/
7778
debounceGetSuggestions: debounce(function (...args) {
7879
this.getSuggestions(...args)
79-
}, 400),
80+
}, INPUT_DEBOUNCE_MS),
8081

8182
/**
8283
* Get suggestions

src/models/Constants.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
/**
7+
* A constant object representing file size units in bytes.
8+
*
9+
* Each key corresponds to a unit of measurement (e.g., kilobytes, megabytes, gigabytes),
10+
* and its value represents the number of bytes in that unit.
11+
*
12+
* @example
13+
* ```typescript
14+
* const kilobytes = FILE_SIZE_UNITS.kb; // 1024
15+
* const megabytes = FILE_SIZE_UNITS.mb; // 1048576
16+
* const gigabytes = FILE_SIZE_UNITS.gb; // 1073741824
17+
* ```
18+
*/
19+
export const FILE_SIZE_UNITS = {
20+
kb: 1024,
21+
mb: 1024 ** 2,
22+
gb: 1024 ** 3,
23+
}
24+
25+
/**
26+
* Represents the state of a form.
27+
*
28+
* Possible values:
29+
* - `FormActive` (0): The form is currently active and can be interacted with.
30+
* - `FormClosed` (1): The form is closed and no longer accepting input.
31+
* - `FormArchived` (2): The form is archived and stored for reference.
32+
*
33+
* Keep in sync with Constants.php
34+
*/
35+
export enum FormState {
36+
FormActive = 0,
37+
FormClosed = 1,
38+
FormArchived = 2,
39+
}
40+
41+
/**
42+
* The debounce time in milliseconds for input events.
43+
*
44+
* This constant is used to limit the rate at which input-related
45+
* operations are triggered, improving performance and user experience.
46+
*/
47+
export const INPUT_DEBOUNCE_MS = 400
48+
49+
/**
50+
* A constant representing the prefix used for identifying "other" answers
51+
*/
52+
export const QUESTION_EXTRASETTINGS_OTHER_PREFIX = 'system-other-answer:'

0 commit comments

Comments
 (0)