Store backups in server state
This commit is contained in:
parent
f9878d842c
commit
2eb6ab4d63
6 changed files with 75 additions and 23 deletions
31
resources/scripts/state/server/backups.ts
Normal file
31
resources/scripts/state/server/backups.ts
Normal file
|
@ -0,0 +1,31 @@
|
|||
import { ServerBackup } from '@/api/server/backups/getServerBackups';
|
||||
import { action, Action } from 'easy-peasy';
|
||||
|
||||
export interface ServerBackupStore {
|
||||
data: ServerBackup[];
|
||||
setBackups: Action<ServerBackupStore, ServerBackup[]>;
|
||||
appendBackup: Action<ServerBackupStore, ServerBackup>;
|
||||
removeBackup: Action<ServerBackupStore, string>;
|
||||
}
|
||||
|
||||
const backups: ServerBackupStore = {
|
||||
data: [],
|
||||
|
||||
setBackups: action((state, payload) => {
|
||||
state.data = payload;
|
||||
}),
|
||||
|
||||
appendBackup: action((state, payload) => {
|
||||
if (state.data.find(backup => backup.uuid === payload.uuid)) {
|
||||
state.data = state.data.map(backup => backup.uuid === payload.uuid ? payload : backup);
|
||||
} else {
|
||||
state.data = [ ...state.data, payload ];
|
||||
}
|
||||
}),
|
||||
|
||||
removeBackup: action((state, payload) => {
|
||||
state.data = [ ...state.data.filter(backup => backup.uuid !== payload) ];
|
||||
}),
|
||||
};
|
||||
|
||||
export default backups;
|
|
@ -5,6 +5,7 @@ import { ServerDatabase } from '@/api/server/getServerDatabases';
|
|||
import files, { ServerFileStore } from '@/state/server/files';
|
||||
import subusers, { ServerSubuserStore } from '@/state/server/subusers';
|
||||
import { composeWithDevTools } from 'redux-devtools-extension';
|
||||
import backups, { ServerBackupStore } from '@/state/server/backups';
|
||||
|
||||
export type ServerStatus = 'offline' | 'starting' | 'stopping' | 'running';
|
||||
|
||||
|
@ -73,6 +74,7 @@ export interface ServerStore {
|
|||
subusers: ServerSubuserStore;
|
||||
databases: ServerDatabaseStore;
|
||||
files: ServerFileStore;
|
||||
backups: ServerBackupStore;
|
||||
socket: SocketStore;
|
||||
status: ServerStatusStore;
|
||||
clearServerState: Action<ServerStore>;
|
||||
|
@ -85,6 +87,7 @@ export const ServerContext = createContextStore<ServerStore>({
|
|||
databases,
|
||||
files,
|
||||
subusers,
|
||||
backups,
|
||||
clearServerState: action(state => {
|
||||
state.server.data = undefined;
|
||||
state.server.permissions = [];
|
||||
|
@ -92,6 +95,7 @@ export const ServerContext = createContextStore<ServerStore>({
|
|||
state.subusers.data = [];
|
||||
state.files.directory = '/';
|
||||
state.files.contents = [];
|
||||
state.backups.backups = [];
|
||||
|
||||
if (state.socket.instance) {
|
||||
state.socket.instance.removeAllListeners();
|
||||
|
|
Reference in a new issue