Files
spacedrive/interface/app/$libraryId/Explorer/FilePath/DeleteDialog.tsx
Artsiom Voitas 3f91973586 Added even more i18n translation keys (#2453)
* more translation keys

* added i18n keys for future ObjectKindEnum translation

* more keys

* added more keys

* synced all new translation keys with all languages, translated keys on Belarusian and Russian

* added translation for objectkinds in overview

* added translation function for objectkinds

* added more keys to german locale

* renamed 'asc' and 'desc' keys

* rolled back changes

* added missed key

* there are much more keys, than you can imagine

* fixed misspelling

* removed console.log

* removed function "pluralize", added required plural words keys for each language

* fixed condition, which could've lead to undefined value

* hide filter description for boolean filters
2024-05-04 16:16:49 +00:00

128 lines
3.4 KiB
TypeScript

import { useLibraryMutation, useZodForm } from '@sd/client';
import { CheckBox, Dialog, Tooltip, useDialog, UseDialogProps } from '@sd/ui';
import i18n from '~/app/I18n';
import { Icon } from '~/components';
import { useLocale } from '~/hooks';
interface Props extends UseDialogProps {
indexedArgs?: {
locationId: number;
rescan?: () => void;
pathIds: number[];
};
ephemeralArgs?: {
paths: string[];
};
dirCount?: number;
fileCount?: number;
}
function getWording(dirCount: number, fileCount: number) {
let type = 'file';
let prefix = i18n.t('prefix_a');
if (dirCount == 1 && fileCount == 0) {
type = i18n.t('directory');
prefix = i18n.t('prefix_a');
}
if (dirCount > 1 && fileCount == 0) {
type = 'directories';
prefix = dirCount.toString();
}
if (fileCount > 1 && dirCount == 0) {
type = 'files';
prefix = fileCount.toString();
}
if (fileCount > 0 && dirCount > 0) {
type = 'items';
prefix = (fileCount + dirCount).toString();
}
const translatedType = i18n.t(`${type}`);
return { type, prefix, translatedType };
}
export default (props: Props) => {
const { t } = useLocale();
const deleteFile = useLibraryMutation('files.deleteFiles');
const deleteEphemeralFile = useLibraryMutation('ephemeralFiles.deleteFiles');
const moveToTrashFile = useLibraryMutation('files.moveToTrash');
const moveToTrashEphemeralFile = useLibraryMutation('ephemeralFiles.moveToTrash');
const form = useZodForm();
const { dirCount = 0, fileCount = 0, indexedArgs, ephemeralArgs } = props;
const { type, prefix, translatedType } = getWording(dirCount, fileCount);
const icon = type === 'file' || type === 'files' ? 'Document' : 'Folder';
const description = t('delete_warning', { type: translatedType });
return (
<Dialog
form={form}
onSubmit={form.handleSubmit(async () => {
if (indexedArgs != undefined) {
const { locationId, rescan, pathIds } = indexedArgs;
await deleteFile.mutateAsync({
location_id: locationId,
file_path_ids: pathIds
});
rescan?.();
}
if (ephemeralArgs != undefined) {
const { paths } = ephemeralArgs;
await deleteEphemeralFile.mutateAsync(paths);
}
})}
onSubmitSecond={form.handleSubmit(async () => {
if (indexedArgs != undefined) {
console.log(
'DEBUG: DeleteDialog.tsx: onSubmitSecond (Move to Trash) -> Indexed Files'
);
const { locationId, rescan, pathIds } = indexedArgs;
await moveToTrashFile.mutateAsync({
location_id: locationId,
file_path_ids: pathIds
});
rescan?.();
}
if (ephemeralArgs != undefined) {
console.log(
'DEBUG: DeleteDialog.tsx: onSubmitSecond (Move to Trash) -> Ephemeral Files'
);
const { paths } = ephemeralArgs;
await moveToTrashEphemeralFile.mutateAsync(paths);
}
})}
icon={<Icon theme="light" name={icon} size={28} />}
dialog={useDialog(props)}
title={t('delete_dialog_title', { prefix, type: translatedType })}
description={description}
loading={deleteFile.isLoading}
ctaLabel={t('delete_forever')}
ctaSecondLabel={t('move_to_trash')}
closeLabel={t('close')}
ctaDanger
className="w-[200px]"
>
{/* <Tooltip label={t('coming_soon')}>
<div className="flex items-center pt-2 opacity-50">
<CheckBox disabled className="!mt-0" />
<p className="text-sm text-ink-dull">
Delete all matching {type.endsWith('s') ? type : type + 's'}
</p>
</div>
</Tooltip> */}
</Dialog>
);
};