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
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue