Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(files): Add more visual move / copy notification #47910

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions apps/files/src/actions/moveOrCopyAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import type { MoveCopyResult } from './moveOrCopyActionUtils'

import { isAxiosError } from '@nextcloud/axios'
import { FilePickerClosed, getFilePickerBuilder, showError, showInfo } from '@nextcloud/dialogs'
import { FilePickerClosed, getFilePickerBuilder, showError, showInfo, TOAST_PERMANENT_TIMEOUT } from '@nextcloud/dialogs'
import { emit } from '@nextcloud/event-bus'
import { FileAction, FileType, NodeStatus, davGetClient, davRootPath, davResultToNode, davGetDefaultPropfind, getUniqueName, Permission } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
Expand Down Expand Up @@ -40,6 +40,28 @@
return MoveCopyAction.COPY
}

/**
* Create a loading notification toast
* @param mode The move or copy mode
* @param source Name of the node that is copied / moved
* @param destination Destination path
* @return {() => void} Function to hide the notification
*/
function createLoadingNotification(mode: MoveCopyAction, source: string, destination: string): () => void {
const text = mode === MoveCopyAction.MOVE ? t('files', 'Moving "{source}" to "{destination}" …', { source, destination }) : t('files', 'Copying "{source}" to "{destination}" …', { source, destination })

let toast: ReturnType<typeof showInfo>|undefined
toast = showInfo(
`<span class="icon icon-loading-small toast-loading-icon"></span> ${text}`,
{
isHTML: true,
timeout: TOAST_PERMANENT_TIMEOUT,
onRemove: () => { toast?.hideToast(); toast = undefined },
},
)
return () => toast && toast.hideToast()
}

/**
* Handle the copy/move of a node to a destination
* This can be imported and used by other scripts/components on server
Expand Down Expand Up @@ -80,6 +102,7 @@

// Set loading state
Vue.set(node, 'status', NodeStatus.LOADING)
const actionFinished = createLoadingNotification(method, node.basename, destination.path)

const queue = getQueue()
return await queue.add(async () => {
Expand Down Expand Up @@ -162,7 +185,8 @@
logger.debug(error as Error)
throw new Error()
} finally {
Vue.set(node, 'status', undefined)
Vue.set(node, 'status', '')
actionFinished()
}
})
}
Expand All @@ -172,7 +196,7 @@
* @param action The action to open the file picker for
* @param dir The directory to start the file picker in
* @param nodes The nodes to move/copy
* @return The picked destination or false if cancelled by user

Check warning on line 199 in apps/files/src/actions/moveOrCopyAction.ts

View workflow job for this annotation

GitHub Actions / NPM lint

Missing JSDoc @return type
*/
async function openFilePickerForAction(
action: MoveCopyAction,
Expand Down Expand Up @@ -313,7 +337,7 @@
if (result === false) {
showInfo(nodes.length === 1
? t('files', 'Cancelled move or copy of "{filename}".', { filename: nodes[0].displayname })
: t('files', 'Cancelled move or copy operation')
: t('files', 'Cancelled move or copy operation'),
)
return nodes.map(() => null)
}
Expand Down
3 changes: 2 additions & 1 deletion apps/files/src/components/FileEntryMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ export default defineComponent({
uniqueId() {
return hashCode(this.source.source)
},

isLoading() {
return this.source.status === NodeStatus.LOADING
return this.source.status === NodeStatus.LOADING || this.loading !== ''
},

/**
Expand Down
7 changes: 7 additions & 0 deletions apps/files/src/views/FilesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,13 @@ export default defineComponent({
</script>

<style scoped lang="scss">
:global(.toast-loading-icon) {
// Reduce start margin (it was made for text but this is an icon)
margin-inline-start: -4px;
// 16px icon + 5px on both sides
min-width: 26px;
}

.app-content {
// Virtual list needs to be full height and is scrollable
display: flex;
Expand Down
4 changes: 2 additions & 2 deletions dist/core-common.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/core-common.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/files-init.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files-init.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/files-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files-main.js.map

Large diffs are not rendered by default.

Loading