|
1 | | -import loadDirectory, { FileObject } from '@/api/server/files/loadDirectory'; |
2 | | -import { action, Action, thunk, Thunk } from 'easy-peasy'; |
3 | | -import { ServerStore } from '@/state/server/index'; |
| 1 | +import { action, Action } from 'easy-peasy'; |
4 | 2 | import { cleanDirectoryPath } from '@/helpers'; |
5 | 3 |
|
6 | 4 | export interface ServerFileStore { |
7 | 5 | directory: string; |
8 | | - contents: FileObject[]; |
9 | | - getDirectoryContents: Thunk<ServerFileStore, string, Record<string, unknown>, ServerStore, Promise<void>>; |
10 | | - setContents: Action<ServerFileStore, FileObject[]>; |
11 | | - pushFile: Action<ServerFileStore, FileObject>; |
12 | | - removeFile: Action<ServerFileStore, string>; |
13 | 6 | setDirectory: Action<ServerFileStore, string>; |
14 | 7 | } |
15 | 8 |
|
16 | 9 | const files: ServerFileStore = { |
17 | 10 | directory: '/', |
18 | | - contents: [], |
19 | | - |
20 | | - getDirectoryContents: thunk(async (actions, payload, { getStoreState }) => { |
21 | | - const server = getStoreState().server.data; |
22 | | - if (!server) { |
23 | | - return; |
24 | | - } |
25 | | - |
26 | | - const contents = await loadDirectory(server.uuid, cleanDirectoryPath(payload)); |
27 | | - |
28 | | - actions.setDirectory(payload.length === 0 ? '/' : payload); |
29 | | - actions.setContents(contents); |
30 | | - }), |
31 | | - |
32 | | - setContents: action((state, payload) => { |
33 | | - state.contents = payload; |
34 | | - }), |
35 | | - |
36 | | - pushFile: action((state, payload) => { |
37 | | - const matchIndex = state.contents.findIndex(file => file.uuid === payload.uuid); |
38 | | - if (matchIndex < 0) { |
39 | | - state.contents = state.contents.concat(payload); |
40 | | - return; |
41 | | - } |
42 | | - |
43 | | - state.contents[matchIndex] = payload; |
44 | | - }), |
45 | | - |
46 | | - removeFile: action((state, payload) => { |
47 | | - state.contents = state.contents.filter(file => file.uuid !== payload); |
48 | | - }), |
49 | 11 |
|
50 | 12 | setDirectory: action((state, payload) => { |
51 | 13 | state.directory = cleanDirectoryPath(payload); |
|
0 commit comments