File upload status (v2 backport) (#4219)

This commit is contained in:
Boy132 2022-07-24 23:18:32 +02:00 committed by GitHub
parent 2eda1995b9
commit 12242848b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 156 additions and 25 deletions

View file

@ -1,19 +1,30 @@
import { action, Action } from 'easy-peasy';
import { cleanDirectoryPath } from '@/helpers';
export interface FileUpload {
name: string;
loaded: number;
readonly total: number;
}
export interface ServerFileStore {
directory: string;
selectedFiles: string[];
uploads: FileUpload[];
setDirectory: Action<ServerFileStore, string>;
setSelectedFiles: Action<ServerFileStore, string[]>;
appendSelectedFile: Action<ServerFileStore, string>;
removeSelectedFile: Action<ServerFileStore, string>;
appendFileUpload: Action<ServerFileStore, FileUpload>;
removeFileUpload: Action<ServerFileStore, string>;
}
const files: ServerFileStore = {
directory: '/',
selectedFiles: [],
uploads: [],
setDirectory: action((state, payload) => {
state.directory = cleanDirectoryPath(payload);
@ -30,6 +41,14 @@ const files: ServerFileStore = {
removeSelectedFile: action((state, payload) => {
state.selectedFiles = state.selectedFiles.filter((f) => f !== payload);
}),
appendFileUpload: action((state, payload) => {
state.uploads = state.uploads.filter((f) => f.name !== payload.name).concat(payload);
}),
removeFileUpload: action((state, payload) => {
state.uploads = state.uploads.filter((f) => f.name !== payload);
}),
};
export default files;