React 18 and Vite (#4510)

This commit is contained in:
Matthew Penner 2022-11-25 13:25:03 -07:00 committed by GitHub
parent 1bb1b13f6d
commit 21613fa602
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
244 changed files with 4547 additions and 8933 deletions

View file

@ -1,13 +1,15 @@
import { action, Action } from 'easy-peasy';
import type { Action } from 'easy-peasy';
import { action } from 'easy-peasy';
import { cleanDirectoryPath } from '@/helpers';
export interface FileUploadData {
interface FileUploadData {
loaded: number;
readonly abort: AbortController;
readonly total: number;
}
export interface ServerFileStore {
interface ServerFileStore {
directory: string;
selectedFiles: string[];
uploads: Record<string, FileUploadData>;
@ -37,15 +39,15 @@ const files: ServerFileStore = {
}),
appendSelectedFile: action((state, payload) => {
state.selectedFiles = state.selectedFiles.filter((f) => f !== payload).concat(payload);
state.selectedFiles = state.selectedFiles.filter(f => f !== payload).concat(payload);
}),
removeSelectedFile: action((state, payload) => {
state.selectedFiles = state.selectedFiles.filter((f) => f !== payload);
state.selectedFiles = state.selectedFiles.filter(f => f !== payload);
}),
clearFileUploads: action((state) => {
Object.values(state.uploads).forEach((upload) => upload.abort.abort());
clearFileUploads: action(state => {
Object.values(state.uploads).forEach(upload => upload.abort.abort());
state.uploads = {};
}),
@ -55,20 +57,27 @@ const files: ServerFileStore = {
}),
setUploadProgress: action((state, { name, loaded }) => {
if (state.uploads[name]) {
state.uploads[name].loaded = loaded;
const upload = state.uploads[name];
if (upload === undefined) {
return;
}
upload.loaded = loaded;
}),
removeFileUpload: action((state, payload) => {
if (state.uploads[payload]) {
// Abort the request if it is still in flight. If it already completed this is
// a no-op.
state.uploads[payload].abort.abort();
delete state.uploads[payload];
const upload = state.uploads[payload];
if (upload === undefined) {
return;
}
// Abort the request if it is still in flight. If it already completed this is
// a no-op.
upload.abort.abort();
delete state.uploads[payload];
}),
};
export type { FileUploadData, ServerFileStore };
export default files;