From 080a3a2c19c169f1f1ed8f8e7227f74c9908227f Mon Sep 17 00:00:00 2001 From: diced Date: Thu, 13 Jun 2024 21:52:23 -0700 Subject: [PATCH] feat: add to folder from dashboard uploader --- .../pages/upload/UploadOptionsButton.tsx | 61 +++++++++++++++++++ src/components/pages/upload/uploadFiles.tsx | 1 + .../pages/upload/uploadPartialFiles.tsx | 1 + src/lib/store/uploadOptions.ts | 2 + 4 files changed, 65 insertions(+) diff --git a/src/components/pages/upload/UploadOptionsButton.tsx b/src/components/pages/upload/UploadOptionsButton.tsx index 5fcca872..c2d9e196 100755 --- a/src/components/pages/upload/UploadOptionsButton.tsx +++ b/src/components/pages/upload/UploadOptionsButton.tsx @@ -1,8 +1,12 @@ +import { Response } from '@/lib/api/response'; +import { Folder } from '@/lib/db/models/folder'; import { useUploadOptionsStore } from '@/lib/store/uploadOptions'; import { Badge, Button, + Combobox, Group, + InputBase, Modal, NumberInput, PasswordInput, @@ -12,12 +16,14 @@ import { Text, TextInput, Title, + useCombobox, } from '@mantine/core'; import { IconAlarmFilled, IconArrowsMinimize, IconEyeFilled, IconFileInfo, + IconFolderPlus, IconGlobe, IconKey, IconPercentage, @@ -25,6 +31,7 @@ import { IconWriting, } from '@tabler/icons-react'; import { useState } from 'react'; +import useSWR from 'swr'; export default function UploadOptionsButton({ numFiles }: { numFiles: number }) { const [opened, setOpen] = useState(false); @@ -46,6 +53,12 @@ export default function UploadOptionsButton({ numFiles }: { numFiles: number }) clearOptions(); }; + const { data: folders } = useSWR>( + '/api/user/folders?noincl=true', + ); + const combobox = useCombobox(); + const [folderSearch, setFolderSearch] = useState(''); + return ( <> setOpen(false)} title={Upload Options}> @@ -184,6 +197,54 @@ export default function UploadOptionsButton({ numFiles }: { numFiles: number }) onChange={(value) => setOption('maxViews', value === '' ? null : Number(value))} /> + { + setFolderSearch(folders?.find((f) => f.id === value)?.name || ''); + setEphemeral('folderId', value === 'no folder' || value === '' ? null : value); + }} + > + + Add to a Folder} + description='Add this file to a folder. Use the "no folder" option not add the file to a folder. This value is not saved to your browser, and is cleared after uploading.' + rightSection={} + leftSection={} + value={folderSearch} + onChange={(event) => { + combobox.openDropdown(); + combobox.updateSelectedOptionIndex(); + setFolderSearch(event.currentTarget.value); + }} + onClick={() => combobox.openDropdown()} + onFocus={() => combobox.openDropdown()} + onBlur={() => { + combobox.closeDropdown(); + setFolderSearch(folderSearch || ''); + }} + placeholder='Add to folder...' + rightSectionPointerEvents='none' + /> + + + + + {folders + ?.filter((f) => f.name.toLowerCase().includes(folderSearch.toLowerCase().trim())) + .map((f) => ( + + {f.name} + + ))} + + + No Folder + + + + + diff --git a/src/components/pages/upload/uploadFiles.tsx b/src/components/pages/upload/uploadFiles.tsx index 9f9f0c6c..ffcc45fa 100755 --- a/src/components/pages/upload/uploadFiles.tsx +++ b/src/components/pages/upload/uploadFiles.tsx @@ -193,6 +193,7 @@ export function uploadFiles( ephemeral.password && req.setRequestHeader('x-zipline-password', ephemeral.password); ephemeral.filename && req.setRequestHeader('x-zipline-filename', ephemeral.filename); + ephemeral.folderId && req.setRequestHeader('x-zipline-folder', ephemeral.folderId); req.send(body); } diff --git a/src/components/pages/upload/uploadPartialFiles.tsx b/src/components/pages/upload/uploadPartialFiles.tsx index fefeac9f..2d0ce8f7 100755 --- a/src/components/pages/upload/uploadPartialFiles.tsx +++ b/src/components/pages/upload/uploadPartialFiles.tsx @@ -245,6 +245,7 @@ export async function uploadPartialFiles( ephemeral.password && req.setRequestHeader('x-zipline-password', ephemeral.password); ephemeral.filename && req.setRequestHeader('x-zipline-filename', ephemeral.filename); + ephemeral.folderId && req.setRequestHeader('x-zipline-folder', ephemeral.folderId); req.setRequestHeader('x-zipline-p-identifier', identifier); req.setRequestHeader('x-zipline-p-filename', file.name); diff --git a/src/lib/store/uploadOptions.ts b/src/lib/store/uploadOptions.ts index e5a33af8..28d18e6c 100755 --- a/src/lib/store/uploadOptions.ts +++ b/src/lib/store/uploadOptions.ts @@ -14,6 +14,7 @@ export const defaultUploadOptions: UploadOptionsStore['options'] = { export const defaultEphemeralOptions: UploadOptionsStore['ephemeral'] = { password: null, filename: null, + folderId: null, }; export type UploadOptionsStore = { @@ -29,6 +30,7 @@ export type UploadOptionsStore = { ephemeral: { password: string | null; filename: string | null; + folderId: string | null; }; setOption: (