Skip to content

Commit

Permalink
refactor(files): Fix nullish operator usage and add missing code comment
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux committed Jun 18, 2024
1 parent f2e3dcb commit 7fec223
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
7 changes: 3 additions & 4 deletions apps/files/src/components/FileEntry/FileEntryActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,14 @@ import type { PropType } from 'vue'
import { DefaultType, FileAction, Node, NodeStatus, View, getFileActions } from '@nextcloud/files'
import { showError, showSuccess } from '@nextcloud/dialogs'
import { translate as t } from '@nextcloud/l10n'
import { defineComponent } from 'vue'

import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton.js'
import NcActions from '@nextcloud/vue/dist/Components/NcActions.js'
import NcActionSeparator from '@nextcloud/vue/dist/Components/NcActionSeparator.js'
import NcIconSvgWrapper from '@nextcloud/vue/dist/Components/NcIconSvgWrapper.js'
import NcLoadingIcon from '@nextcloud/vue/dist/Components/NcLoadingIcon.js'
import ArrowLeftIcon from 'vue-material-design-icons/ArrowLeft.vue'
import Vue, { defineComponent } from 'vue'

import CustomElementRender from '../CustomElementRender.vue'

import logger from '../../logger.js'
Expand Down Expand Up @@ -270,7 +269,7 @@ export default defineComponent({
try {
// Set the loading marker
this.$emit('update:loading', action.id)
Vue.set(this.source, 'status', NodeStatus.LOADING)
this.$set(this.source, 'status', NodeStatus.LOADING)

const success = await action.exec(this.source, this.currentView, this.currentDir)

Expand All @@ -290,7 +289,7 @@ export default defineComponent({
} finally {
// Reset the loading marker
this.$emit('update:loading', '')
Vue.set(this.source, 'status', undefined)
this.$set(this.source, 'status', undefined)

// If that was a submenu, we just go back after the action
if (isSubmenu) {
Expand Down
4 changes: 2 additions & 2 deletions apps/files/src/components/FileEntryMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ export default defineComponent({

currentDir() {
// Remove any trailing slash but leave root slash
return (this.$route?.query?.dir?.toString() || '/').replace(/^(.+)\/$/, '$1')
return (this.$route.query?.dir?.toString() || '/').replace(/^(.+)\/$/, '$1')
},
currentFileId() {
return this.$route.params?.fileid || this.$route.query?.fileid || null
},

fileid() {
return this.source?.fileid
return this.source.fileid ?? 0
},
uniqueId() {
return hashCode(this.source.source)
Expand Down
5 changes: 5 additions & 0 deletions apps/files/src/utils/hashUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

/**
* Simple non-secure hashing function similar to Java's `hashCode`
* @param str The string to hash
* @return {number} a non secure hash of the string
*/
export const hashCode = function(str: string): number {
let hash = 0
for (let i = 0; i < str.length; i++) {
Expand Down

0 comments on commit 7fec223

Please sign in to comment.