Files
spacedrive/interface/app/$libraryId/Explorer/FilePath/DeleteDialog.tsx
T
Vítor Vasconcellos 1181cd2709 Frontend misc fixes and deps update (#1650)
Dependencies overhaul
 - Update dependencies for all projects (except Mobile-only deps)
 - Remove unused dependencies from all projects (except Mobile-only deps)
 - Fix Storybook failing to import sd/ui style
 - Add Node 21 as not supported due to sass-loader not working on it yet
 - Add work-around for new rook version requiring webpack specific global property
 - Fix landing dev not working due to missing default env value on dev
 - Fix some incorrect uses of phosphor-icons non server side icons on server components on landing
 - Fix some incorrect uses of phosphor-icons server side icon on client components on landing
 - Fix landing fail to build on dev due to always required a Github Token to get the latest release
 - Fix new Next.js version not suporting Response.redirect due to immutable Headers
 - Add Gitlab as social link for teams page
 - Update Vítor's team photo
 - Add Vítor's twitter link
 - Fix some warning due to missing useEffect dependencies
 - Remove test-files dir
 - Fix QuickPreview unblurred buttons in Linux
 - Formatting
2023-10-24 07:51:58 +00:00

79 lines
1.8 KiB
TypeScript

import { useLibraryMutation, useZodForm } from '@sd/client';
import { CheckBox, Dialog, Tooltip, useDialog, UseDialogProps } from '@sd/ui';
interface Props extends UseDialogProps {
locationId: number;
rescan?: () => void;
pathIds: number[];
dirCount?: number;
fileCount?: number;
}
function getWording(dirCount: number, fileCount: number) {
let type = 'file';
let prefix = 'a';
if (dirCount == 1 && fileCount == 0) {
type = 'directory';
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();
}
return { type, prefix };
}
export default (props: Props) => {
const deleteFile = useLibraryMutation('files.deleteFiles');
const form = useZodForm();
const { dirCount = 0, fileCount = 0 } = props;
const { type, prefix } = getWording(dirCount, fileCount);
const description = `Warning: This will delete your ${type} forever, we don't have a trash can yet...`;
return (
<Dialog
form={form}
onSubmit={form.handleSubmit(async () => {
await deleteFile.mutateAsync({
location_id: props.locationId,
file_path_ids: props.pathIds
});
props.rescan?.();
})}
dialog={useDialog(props)}
title={'Delete ' + prefix + ' ' + type}
description={description}
loading={deleteFile.isLoading}
ctaLabel="Delete"
ctaDanger
className="w-[200px]"
>
<Tooltip label="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>
);
};