feat: implement manually add file, use every() to check if pdfs can be dropped, implement file delete, remove nested scrollarea for document preview
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/promote/production Build is passing

This commit is contained in:
RaviAnand Mohabir 2025-04-08 20:17:28 +02:00
parent c5eb0115dd
commit e6c0e16e84

View File

@ -23,6 +23,7 @@ import {
IconDownload, IconDownload,
IconEye, IconEye,
IconEyeOff, IconEyeOff,
IconFilePlus,
IconFiles, IconFiles,
IconLayoutSidebarLeftCollapse, IconLayoutSidebarLeftCollapse,
IconLayoutSidebarLeftExpand, IconLayoutSidebarLeftExpand,
@ -314,12 +315,24 @@ function Organizrr() {
<Group> <Group>
<IconFiles /> <IconFiles />
<Title order={3}>Files</Title> <Title order={3}>Files</Title>
<ActionIcon
variant="subtle"
ml="auto"
onClick={() => {
const id = Math.random().toString(36).replace("0.", "file_");
form.insertListItem("files", { id, documents: [] });
setActiveFile(form.getValues().files.length - 1);
}}
>
<IconFilePlus />
</ActionIcon>
</Group> </Group>
</AppShell.Section> </AppShell.Section>
<AppShell.Section grow my="md" component={ScrollArea}> <AppShell.Section grow my="md" component={ScrollArea}>
<Stack> <Stack>
{form.values.files.map((f, idx) => ( {form.values.files.map((f, idx) => (
<Stack key={f.id} gap="xs"> <Stack key={f.id} gap="xs">
<Group>
<Button <Button
variant={idx === activeFile ? "" : "subtle"} variant={idx === activeFile ? "" : "subtle"}
onClick={() => { onClick={() => {
@ -331,9 +344,23 @@ function Organizrr() {
<Loader size="xs" type="bars" color="white" /> <Loader size="xs" type="bars" color="white" />
) : null ) : null
} }
style={{ flex: 1 }}
> >
<Text>{f.suffix || f.id}</Text> <Text>{f.suffix || f.id}</Text>
</Button> </Button>
<ActionIcon
onClick={() => {
if (activeFile === idx) {
setActiveFile(null);
}
form.removeListItem("files", idx);
}}
variant="subtle"
c="red"
>
<IconTrash />
</ActionIcon>
</Group>
{activeFile != idx && {activeFile != idx &&
form.errors && form.errors &&
Object.entries(form.errors) Object.entries(form.errors)
@ -480,14 +507,12 @@ function Organizrr() {
</Stack> </Stack>
) )
)} )}
{form.values.documents {form.values.files[activeFile].documents.every((doc) =>
.find( form.values.documents
(doc) => .find((d) => d.id === doc.id)
doc.id ===
form.values.files[activeFile]?.documents[0].id
)
?.file.name.toLowerCase() ?.file.name.toLowerCase()
.endsWith(".pdf") && ( .endsWith(".pdf")
) && (
<Stack <Stack
w={300} w={300}
key={form.values.files[activeFile]?.documents.length} key={form.values.files[activeFile]?.documents.length}
@ -540,16 +565,12 @@ function Organizrr() {
<Stack align="center"> <Stack align="center">
{activeDocument && {activeDocument &&
activeDocument.file.name.toLowerCase().endsWith(".pdf") && ( activeDocument.file.name.toLowerCase().endsWith(".pdf") && (
<>
<ScrollArea maw="100%">
<Document <Document
file={activeDocument.file} file={activeDocument.file}
onLoadSuccess={onDocumentLoadSuccess} onLoadSuccess={onDocumentLoadSuccess}
> >
<Page pageNumber={pageNumber} scale={0.8} /> <Page pageNumber={pageNumber} scale={0.8} />
</Document> </Document>
</ScrollArea>
</>
)} )}
</Stack> </Stack>
</AppShell.Section> </AppShell.Section>