Skip to content

Commit

Permalink
refactor: Adjust code for some Typescript errors
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux committed Aug 8, 2024
1 parent c2b18e2 commit c63c36b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/actions/DownloadLimitAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import { getCurrentUser } from '@nextcloud/auth'
import { Type as ShareType } from '@nextcloud/sharing'
import { ShareType } from '@nextcloud/sharing'

import DownloadLimitEntry from '../components/DownloadLimitEntry.vue'

Expand All @@ -22,8 +22,8 @@ export class DownloadLimitAction {

get shareType() {
return [
ShareType.SHARE_TYPE_LINK,
ShareType.SHARE_TYPE_EMAIL,
ShareType.Link,
ShareType.Email,
]
}

Expand Down
4 changes: 2 additions & 2 deletions src/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Vue from 'vue'

import AdminSettings from './views/AdminSettings.vue'

new Vue({
el: '#admin-download-limit',
const instance = new Vue({
render: h => h(AdminSettings),
})
instance.$mount('#admin-download-limit')
19 changes: 11 additions & 8 deletions src/components/DownloadLimitEntry.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@
</template>

<script lang="ts">
import { showError } from '@nextcloud/dialogs'
import { loadState } from '@nextcloud/initial-state'
import { n, t } from '@nextcloud/l10n'
import { defineComponent } from 'vue'
import { Fragment } from 'vue-frag'
import { loadState } from '@nextcloud/initial-state'
import { showError } from '@nextcloud/dialogs'
import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js'
import NcNoteCard from '@nextcloud/vue/dist/Components/NcNoteCard.js'
Expand Down Expand Up @@ -74,21 +75,21 @@ export default defineComponent({
data() {
return {
limitEnabled: false,
initialLimit: null,
initialLimit: null as number | null,
limit,
count: null,
count: null as number | null,
loading: false,
hasError: false,
}
},
computed: {
remainingCount() {
return this.initialLimit - this.count
return (this.initialLimit ?? 0) - (this.count ?? 0)
},
helperText() {
if (this.limit > 0) {
if (this.limit && this.limit > 0) {
return ''
}
return t('files_downloadlimit', 'The minimum limit is 1')
Expand Down Expand Up @@ -129,13 +130,15 @@ export default defineComponent({
},
methods: {
n,
t,
handleUpdateLimit(limit: string) {
this.limit = Number(limit) // emitted <input> value is string so we parse it to number
},
async onSave() {
const isValid = typeof this.limit === 'number' && this.limit > 0
if (!isValid) {
if (typeof this.limit !== 'number' || this.limit <= 0) {
return
}
Expand Down
2 changes: 1 addition & 1 deletion src/public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ window.addEventListener('DOMContentLoaded', () => {
}

// Adding double-download warning
const downloadButtons = document.querySelectorAll<HTMLAnchorElement>('a[href*="/download/"]') || []
const downloadButtons = Array.from(document.querySelectorAll<HTMLAnchorElement>('a[href*="/download/"]'))
new Set(downloadButtons).forEach(button => {
button.addEventListener('click', (event) => {
// Warn about download limits
Expand Down

0 comments on commit c63c36b

Please sign in to comment.