feat: folder creation (#696)

This commit is contained in:
Daniel Lautzenheiser
2023-04-12 15:18:32 -04:00
committed by GitHub
parent bc0331483a
commit 5384b5c7a2
24 changed files with 620 additions and 189 deletions

View File

@ -1,3 +1,4 @@
import { basename, dirname } from 'path';
import { v4 as uuid } from 'uuid';
import {
@ -208,13 +209,41 @@ function mediaLibrary(
};
case MEDIA_PERSIST_SUCCESS: {
const { file } = action.payload;
const { file, currentFolder } = action.payload;
const fileWithKey = { ...file, key: uuid() };
const files = state.files as MediaFile[];
const updatedFiles = [fileWithKey, ...files];
const dir = dirname(file.path);
if (!currentFolder || dir === currentFolder) {
const updatedFiles: MediaFile[] = [fileWithKey, ...files];
return {
...state,
files: updatedFiles,
isPersisting: false,
};
}
const folder = files.find(otherFile => otherFile.isDirectory && otherFile.path === dir);
if (!folder) {
const updatedFiles: MediaFile[] = [
{
name: basename(dir),
id: dir,
path: dir,
isDirectory: true,
},
...files,
];
return {
...state,
files: updatedFiles,
isPersisting: false,
};
}
return {
...state,
files: updatedFiles,
isPersisting: false,
};
}