2020-04-10 17:56:25 +00:00
|
|
|
import { action, Action } from 'easy-peasy';
|
2020-11-09 02:09:22 +00:00
|
|
|
import { ServerDatabase } from '@/api/server/databases/getServerDatabases';
|
2020-04-10 17:56:25 +00:00
|
|
|
|
|
|
|
export interface ServerDatabaseStore {
|
|
|
|
data: ServerDatabase[];
|
|
|
|
setDatabases: Action<ServerDatabaseStore, ServerDatabase[]>;
|
|
|
|
appendDatabase: Action<ServerDatabaseStore, ServerDatabase>;
|
|
|
|
removeDatabase: Action<ServerDatabaseStore, string>;
|
|
|
|
}
|
|
|
|
|
|
|
|
const databases: ServerDatabaseStore = {
|
|
|
|
data: [],
|
|
|
|
|
|
|
|
setDatabases: action((state, payload) => {
|
|
|
|
state.data = payload;
|
|
|
|
}),
|
|
|
|
|
|
|
|
appendDatabase: action((state, payload) => {
|
2022-11-25 20:25:03 +00:00
|
|
|
if (state.data.find(database => database.id === payload.id)) {
|
|
|
|
state.data = state.data.map(database => (database.id === payload.id ? payload : database));
|
2020-04-10 17:56:25 +00:00
|
|
|
} else {
|
2022-06-26 19:13:52 +00:00
|
|
|
state.data = [...state.data, payload];
|
2020-04-10 17:56:25 +00:00
|
|
|
}
|
|
|
|
}),
|
|
|
|
|
|
|
|
removeDatabase: action((state, payload) => {
|
2022-11-25 20:25:03 +00:00
|
|
|
state.data = [...state.data.filter(database => database.id !== payload)];
|
2020-04-10 17:56:25 +00:00
|
|
|
}),
|
|
|
|
};
|
|
|
|
|
|
|
|
export default databases;
|