mirror of
https://github.com/get-drexa/drive.git
synced 2025-12-03 23:11:39 +00:00
feat: initial bulk file upload dialog
This commit is contained in:
31
packages/web/src/files/store.ts
Normal file
31
packages/web/src/files/store.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { atom } from "jotai"
|
||||
import { atomFamily } from "jotai/utils"
|
||||
|
||||
type FileUpload = {
|
||||
id: string
|
||||
progress: number
|
||||
}
|
||||
|
||||
export const fileUploadsAtom = atom<Record<string, FileUpload>>({})
|
||||
|
||||
export const fileUploadAtomFamily = atomFamily((id: string) =>
|
||||
atom(
|
||||
(get) => get(fileUploadsAtom)[id],
|
||||
(get, set, progress: number) => {
|
||||
const fileUploads = { ...get(fileUploadsAtom) }
|
||||
fileUploads[id] = { id, progress }
|
||||
set(fileUploadsAtom, fileUploads)
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
export const clearFileUploadAtom = atom(null, (get, set, id: string) => {
|
||||
const fileUploads = { ...get(fileUploadsAtom) }
|
||||
delete fileUploads[id]
|
||||
fileUploadAtomFamily.remove(id)
|
||||
set(fileUploadsAtom, fileUploads)
|
||||
})
|
||||
|
||||
export const hasFileUploadsAtom = atom(
|
||||
(get) => Object.keys(get(fileUploadsAtom)).length > 0,
|
||||
)
|
||||
Reference in New Issue
Block a user