Files
spacedrive/interface/app/$libraryId/Explorer/File/EraseDialog.tsx
T
Brendan AllanandJamie Pine c65d92ee4c [ENG-380] Interface code structure improvement (#581)
* beginnings of app directory

* settings mostly good

* colocate way more components

* flatten components folder

* reexport QueryClientProvider from client

* move CodeBlock back to interface

* colocate Explorer, KeyManager + more

* goddamn captialisation

* get toasts out of components

* please eslint

* no more src directory

* $ instead of :

* added back RowHeader component

* fix settings modal padding

* more spacing, less margin

* fix sidebar locations button

* fix tags sidebar link

* clean up back button

* added margin to explorer context menu to prevent contact with edge of viewport

* don't export QueryClientProvider from @sd/client

* basic guidelines

* import interface correctly

* remove old demo data

* fix onboarding layout

* fix onboarding navigation

* fix key manager settings button

---------

Co-authored-by: Jamie Pine <ijamespine@me.com>
2023-02-27 21:29:48 -08:00

72 lines
1.6 KiB
TypeScript

import { useState } from 'react';
import { useLibraryMutation } from '@sd/client';
import { Dialog, Slider, UseDialogProps, useDialog } from '@sd/ui';
import { useZodForm, z } from '@sd/ui/src/forms';
interface Props extends UseDialogProps {
location_id: number;
path_id: number;
}
const schema = z.object({
passes: z.number()
});
export default (props: Props) => {
const dialog = useDialog(props);
const eraseFile = useLibraryMutation('files.eraseFiles');
const form = useZodForm({
schema,
defaultValues: {
passes: 4
}
});
const onSubmit = form.handleSubmit((data) =>
eraseFile.mutateAsync({
location_id: props.location_id,
path_id: props.path_id,
passes: data.passes.toString()
})
);
const [passes, setPasses] = useState([4]);
return (
<Dialog
form={form}
onSubmit={onSubmit}
dialog={dialog}
title="Erase a file"
description="Configure your erasure settings."
loading={eraseFile.isLoading}
ctaLabel="Erase"
>
<div className="mt-2 flex flex-col">
<span className="text-xs font-bold"># of passes</span>
<div className="flex flex-row space-x-2">
<div className="relative mt-2 flex grow">
<Slider
value={passes}
max={16}
min={1}
step={1}
defaultValue={[4]}
onValueChange={(val) => {
setPasses(val);
form.setValue('passes', val[0] ?? 1);
}}
/>
</div>
<span className="mt-2.5 text-sm font-medium">{passes}</span>
</div>
</div>
<p>TODO: checkbox for "erase all matching files" (only if a file is selected)</p>
</Dialog>
);
};