2020-07-10 23:09:37 -07:00
|
|
|
import { action, Action } from 'easy-peasy';
|
2020-04-10 13:57:24 -07:00
|
|
|
import { cleanDirectoryPath } from '@/helpers';
|
2019-08-04 14:58:31 -07:00
|
|
|
|
2021-08-03 20:41:28 -06:00
|
|
|
export interface FileUpload {
|
|
|
|
name: string;
|
|
|
|
loaded: number;
|
|
|
|
readonly total: number;
|
|
|
|
}
|
|
|
|
|
2019-08-04 14:58:31 -07:00
|
|
|
export interface ServerFileStore {
|
|
|
|
directory: string;
|
2020-07-11 16:47:13 -07:00
|
|
|
selectedFiles: string[];
|
2021-08-03 20:41:28 -06:00
|
|
|
uploads: FileUpload[];
|
2020-07-11 16:47:13 -07:00
|
|
|
|
2019-08-04 14:58:31 -07:00
|
|
|
setDirectory: Action<ServerFileStore, string>;
|
2020-07-11 16:47:13 -07:00
|
|
|
setSelectedFiles: Action<ServerFileStore, string[]>;
|
2020-07-11 16:57:30 -07:00
|
|
|
appendSelectedFile: Action<ServerFileStore, string>;
|
|
|
|
removeSelectedFile: Action<ServerFileStore, string>;
|
2021-08-03 20:41:28 -06:00
|
|
|
|
|
|
|
appendFileUpload: Action<ServerFileStore, FileUpload>;
|
|
|
|
removeFileUpload: Action<ServerFileStore, string>;
|
2019-08-04 14:58:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const files: ServerFileStore = {
|
2019-08-05 21:52:48 -07:00
|
|
|
directory: '/',
|
2020-07-11 16:47:13 -07:00
|
|
|
selectedFiles: [],
|
2021-08-03 20:41:28 -06:00
|
|
|
uploads: [],
|
2019-08-04 14:58:31 -07:00
|
|
|
|
|
|
|
setDirectory: action((state, payload) => {
|
2020-06-13 09:49:32 -07:00
|
|
|
state.directory = cleanDirectoryPath(payload);
|
2019-08-04 14:58:31 -07:00
|
|
|
}),
|
2020-07-11 16:47:13 -07:00
|
|
|
setSelectedFiles: action((state, payload) => {
|
|
|
|
state.selectedFiles = payload;
|
|
|
|
}),
|
2020-07-11 16:57:30 -07:00
|
|
|
appendSelectedFile: action((state, payload) => {
|
|
|
|
state.selectedFiles = state.selectedFiles.filter(f => f !== payload).concat(payload);
|
|
|
|
}),
|
|
|
|
removeSelectedFile: action((state, payload) => {
|
|
|
|
state.selectedFiles = state.selectedFiles.filter(f => f !== payload);
|
|
|
|
}),
|
2021-08-03 20:41:28 -06:00
|
|
|
|
|
|
|
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);
|
|
|
|
}),
|
2019-08-04 14:58:31 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
export default files;
|