2020-07-11 07:09:37 +01:00
|
|
|
import { action, Action } from 'easy-peasy';
|
2020-04-10 21:57:24 +01:00
|
|
|
import { cleanDirectoryPath } from '@/helpers';
|
2019-08-04 22:58:31 +01:00
|
|
|
|
|
|
|
export interface ServerFileStore {
|
|
|
|
directory: string;
|
2020-07-12 00:47:13 +01:00
|
|
|
selectedFiles: string[];
|
|
|
|
|
2019-08-04 22:58:31 +01:00
|
|
|
setDirectory: Action<ServerFileStore, string>;
|
2020-07-12 00:47:13 +01:00
|
|
|
setSelectedFiles: Action<ServerFileStore, string[]>;
|
2020-07-12 00:57:30 +01:00
|
|
|
appendSelectedFile: Action<ServerFileStore, string>;
|
|
|
|
removeSelectedFile: Action<ServerFileStore, string>;
|
2019-08-04 22:58:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const files: ServerFileStore = {
|
2019-08-06 05:52:48 +01:00
|
|
|
directory: '/',
|
2020-07-12 00:47:13 +01:00
|
|
|
selectedFiles: [],
|
2019-08-04 22:58:31 +01:00
|
|
|
|
|
|
|
setDirectory: action((state, payload) => {
|
2020-06-13 17:49:32 +01:00
|
|
|
state.directory = cleanDirectoryPath(payload);
|
2019-08-04 22:58:31 +01:00
|
|
|
}),
|
2020-07-12 00:47:13 +01:00
|
|
|
|
|
|
|
setSelectedFiles: action((state, payload) => {
|
|
|
|
state.selectedFiles = payload;
|
|
|
|
}),
|
2020-07-12 00:57:30 +01:00
|
|
|
|
|
|
|
appendSelectedFile: action((state, payload) => {
|
2022-06-26 20:13:52 +01:00
|
|
|
state.selectedFiles = state.selectedFiles.filter((f) => f !== payload).concat(payload);
|
2020-07-12 00:57:30 +01:00
|
|
|
}),
|
|
|
|
|
|
|
|
removeSelectedFile: action((state, payload) => {
|
2022-06-26 20:13:52 +01:00
|
|
|
state.selectedFiles = state.selectedFiles.filter((f) => f !== payload);
|
2020-07-12 00:57:30 +01:00
|
|
|
}),
|
2019-08-04 22:58:31 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
export default files;
|