Skip to content

Commit

Permalink
Added task subtitle to rename or move tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramon Candel authored and Ramon Candel committed Oct 1, 2024
1 parent c2ae5eb commit f4e0f38
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 33 deletions.
1 change: 1 addition & 0 deletions src/app/drive/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface DriveFolderData {
shares?: Array<ShareLink>;
sharings?: { type: string; id: string }[];
uuid: string;
type?: string;
}

export interface DriveFolderMetadataPayload {
Expand Down
4 changes: 2 additions & 2 deletions src/app/store/slices/storage/storage.thunks/moveItemsThunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ export const moveItemsThunkExtraReducers = (builder: ActionReducerMapBuilder<Sto
builder
.addCase(moveItemsThunk.pending, () => 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,
});
});
Expand Down
64 changes: 34 additions & 30 deletions src/app/store/slices/storage/storage.thunks/renameItemsThunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -66,7 +65,7 @@ export interface RenameItemsPayload {

export const renameItemsThunk = createAsyncThunk<void, RenameItemsPayload, { state: RootState }>(
'storage/renameItems',
async ({ items, destinationFolderId, onRenameSuccess }: RenameItemsPayload, { getState, dispatch }) => {
async ({ items, destinationFolderId, onRenameSuccess }: RenameItemsPayload, { dispatch }) => {
const promises: Promise<any>[] = [];

if (items.some((item) => item.isFolder && item.uuid === destinationFolderId)) {
Expand Down Expand Up @@ -97,39 +96,44 @@ export const renameItemsThunk = createAsyncThunk<void, RenameItemsPayload, { sta
itemParsed = { ...item, name: finalFilename, plain_name: finalFilename };
}

let taskId: string;
if (itemParsed.isFolder) {
taskId = tasksService.create<RenameFolderTask>({
action: TaskType.RenameFolder,
showNotification: true,
folder: itemParsed,
destinationFolderId,
cancellable: true,
});
} else {
taskId = tasksService.create<RenameFileTask>({
action: TaskType.RenameFile,
showNotification: true,
file: itemParsed,
destinationFolderId,
cancellable: true,
});
}
const taskId: string = itemParsed.isFolder
? tasksService.create<RenameFolderTask>({
action: TaskType.RenameFolder,
showNotification: true,
folder: itemParsed,
destinationFolderId,
cancellable: true,
})
: tasksService.create<RenameFileTask>({
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: {
Expand Down
14 changes: 13 additions & 1 deletion src/app/tasks/services/tasks.service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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 '';
}

Expand Down

0 comments on commit f4e0f38

Please sign in to comment.