From f4e0f384bc05725ba45a0070959dfb8fa90e4bbc Mon Sep 17 00:00:00 2001 From: Ramon Candel Date: Tue, 1 Oct 2024 16:57:02 +0200 Subject: [PATCH] Added task subtitle to rename or move tasks --- src/app/drive/types/index.ts | 1 + .../storage/storage.thunks/moveItemsThunk.ts | 4 +- .../storage.thunks/renameItemsThunk.ts | 64 ++++++++++--------- src/app/tasks/services/tasks.service/index.ts | 14 +++- 4 files changed, 50 insertions(+), 33 deletions(-) diff --git a/src/app/drive/types/index.ts b/src/app/drive/types/index.ts index 6e4ac4b7b..6d53299d5 100644 --- a/src/app/drive/types/index.ts +++ b/src/app/drive/types/index.ts @@ -27,6 +27,7 @@ export interface DriveFolderData { shares?: Array; sharings?: { type: string; id: string }[]; uuid: string; + type?: string; } export interface DriveFolderMetadataPayload { diff --git a/src/app/store/slices/storage/storage.thunks/moveItemsThunk.ts b/src/app/store/slices/storage/storage.thunks/moveItemsThunk.ts index 270468f8e..c363b0b58 100644 --- a/src/app/store/slices/storage/storage.thunks/moveItemsThunk.ts +++ b/src/app/store/slices/storage/storage.thunks/moveItemsThunk.ts @@ -110,9 +110,9 @@ export const moveItemsThunkExtraReducers = (builder: ActionReducerMapBuilder undefined) .addCase(moveItemsThunk.fulfilled, () => undefined) - .addCase(moveItemsThunk.rejected, (state, action) => { + .addCase(moveItemsThunk.rejected, (_, action) => { notificationsService.show({ - text: 'error', + text: action.error.message ?? t('error.movingItem'), type: ToastType.Error, }); }); diff --git a/src/app/store/slices/storage/storage.thunks/renameItemsThunk.ts b/src/app/store/slices/storage/storage.thunks/renameItemsThunk.ts index 79fbc3444..27b4bb2fa 100644 --- a/src/app/store/slices/storage/storage.thunks/renameItemsThunk.ts +++ b/src/app/store/slices/storage/storage.thunks/renameItemsThunk.ts @@ -9,7 +9,6 @@ import { t } from 'i18next'; import storageThunks from '.'; import { storageActions } from '..'; import { RootState } from '../../..'; -import errorService from '../../../../core/services/error.service'; import { uiActions } from '../../ui'; import { checkDuplicatedFiles } from '../fileUtils/checkDuplicatedFiles'; import { getUniqueFilename } from '../fileUtils/getUniqueFilename'; @@ -66,7 +65,7 @@ export interface RenameItemsPayload { export const renameItemsThunk = createAsyncThunk( 'storage/renameItems', - async ({ items, destinationFolderId, onRenameSuccess }: RenameItemsPayload, { getState, dispatch }) => { + async ({ items, destinationFolderId, onRenameSuccess }: RenameItemsPayload, { dispatch }) => { const promises: Promise[] = []; if (items.some((item) => item.isFolder && item.uuid === destinationFolderId)) { @@ -97,39 +96,44 @@ export const renameItemsThunk = createAsyncThunk({ - action: TaskType.RenameFolder, - showNotification: true, - folder: itemParsed, - destinationFolderId, - cancellable: true, - }); - } else { - taskId = tasksService.create({ - action: TaskType.RenameFile, - showNotification: true, - file: itemParsed, - destinationFolderId, - cancellable: true, - }); - } + const taskId: string = itemParsed.isFolder + ? tasksService.create({ + action: TaskType.RenameFolder, + showNotification: true, + folder: itemParsed, + destinationFolderId, + cancellable: true, + }) + : tasksService.create({ + action: TaskType.RenameFile, + showNotification: true, + file: itemParsed, + destinationFolderId, + cancellable: true, + }); promises.push(dispatch(storageThunks.updateItemMetadataThunk({ item, metadata: { itemName: itemParsed.name } }))); promises[index] - .then(async () => { - tasksService.updateTask({ - taskId, - merge: { - status: TaskStatus.Success, - }, - }); - setTimeout(() => onRenameSuccess?.(itemParsed), 1000); + .then(async (result) => { + if (!result.error) { + tasksService.updateTask({ + taskId, + merge: { + status: TaskStatus.Success, + }, + }); + setTimeout(() => onRenameSuccess?.(itemParsed), 1000); + } else { + tasksService.updateTask({ + taskId, + merge: { + status: TaskStatus.Error, + }, + }); + } }) - .catch((e) => { - errorService.reportError(e); + .catch(() => { tasksService.updateTask({ taskId, merge: { diff --git a/src/app/tasks/services/tasks.service/index.ts b/src/app/tasks/services/tasks.service/index.ts index 48c003244..8df7b4d3c 100644 --- a/src/app/tasks/services/tasks.service/index.ts +++ b/src/app/tasks/services/tasks.service/index.ts @@ -4,6 +4,7 @@ import { uniqueId } from 'lodash'; import { FunctionComponent, SVGProps } from 'react'; import iconService from 'app/drive/services/icon.service'; +import { t } from 'i18next'; import { BaseTask, DownloadFilesData, @@ -203,7 +204,9 @@ class TaskManagerService { break; } case TaskType.RenameFolder: { - title = itemsLib.getItemDisplayName(task.folder); + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const { type, ...driveFolderWithoutType } = task.folder; + title = itemsLib.getItemDisplayName(driveFolderWithoutType); break; } } @@ -212,9 +215,18 @@ class TaskManagerService { } private getTaskNotificationSubtitle(task: TaskData): string { + const isRenameOrMoveTask = + task.action === TaskType.RenameFolder || + task.action === TaskType.RenameFile || + task.action === TaskType.MoveFile || + task.action === TaskType.MoveFolder; + if (task.status === TaskStatus.Error && task.subtitle) { return task.subtitle; } + + if (isRenameOrMoveTask) return t(`tasks.${task.action}.status.${task.status}`); + return ''; }