Cleanup code, add basic functionality for Nests
This commit is contained in:
parent
6c85be72fa
commit
88ac1ce1fd
37 changed files with 331 additions and 159 deletions
|
@ -1,5 +1,6 @@
|
|||
import { createContextStore } from 'easy-peasy';
|
||||
import { composeWithDevTools } from 'redux-devtools-extension';
|
||||
|
||||
import nests, { AdminNestStore } from '@/state/admin/nests';
|
||||
import roles, { AdminRoleStore } from '@/state/admin/roles';
|
||||
|
||||
|
|
|
@ -3,13 +3,20 @@ import { Nest } from '@/api/admin/nests/getNests';
|
|||
|
||||
export interface AdminNestStore {
|
||||
data: Nest[];
|
||||
selectedNests: number[];
|
||||
|
||||
setNests: Action<AdminNestStore, Nest[]>;
|
||||
appendNest: Action<AdminNestStore, Nest>;
|
||||
removeNest: Action<AdminNestStore, number>;
|
||||
|
||||
setSelectedNests: Action<AdminNestStore, number[]>;
|
||||
appendSelectedNest: Action<AdminNestStore, number>;
|
||||
removeSelectedNest: Action<AdminNestStore, number>;
|
||||
}
|
||||
|
||||
const nests: AdminNestStore = {
|
||||
data: [],
|
||||
selectedNests: [],
|
||||
|
||||
setNests: action((state, payload) => {
|
||||
state.data = payload;
|
||||
|
@ -26,6 +33,22 @@ const nests: AdminNestStore = {
|
|||
removeNest: action((state, payload) => {
|
||||
state.data = [ ...state.data.filter(nest => nest.id !== payload) ];
|
||||
}),
|
||||
|
||||
setSelectedNests: action((state, payload) => {
|
||||
state.selectedNests = payload;
|
||||
}),
|
||||
|
||||
appendSelectedNest: action((state, payload) => {
|
||||
if (state.selectedNests.find(id => id === payload)) {
|
||||
state.selectedNests = state.selectedNests.map(id => id === payload ? payload : id);
|
||||
} else {
|
||||
state.selectedNests = [ ...state.selectedNests, payload ];
|
||||
}
|
||||
}),
|
||||
|
||||
removeSelectedNest: action((state, payload) => {
|
||||
state.selectedNests = [ ...state.selectedNests.filter(id => id !== payload) ];
|
||||
}),
|
||||
};
|
||||
|
||||
export default nests;
|
||||
|
|
|
@ -3,6 +3,7 @@ import { Role } from '@/api/admin/roles/getRoles';
|
|||
|
||||
export interface AdminRoleStore {
|
||||
data: Role[];
|
||||
|
||||
setRoles: Action<AdminRoleStore, Role[]>;
|
||||
appendRole: Action<AdminRoleStore, Role>;
|
||||
removeRole: Action<AdminRoleStore, number>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue