46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import {ActionContext, Module} from 'vuex';
|
|
import { RootState } from './index';
|
|
import Bullpen from '@/types/Bullpen';
|
|
import User from '@/types/User';
|
|
import BullpenSessionService from '@/services/BullpenSessionService';
|
|
import Pitch from '@/types/Pitch';
|
|
import Pageable from "@/types/PagingDecorator";
|
|
|
|
export interface BullpenState {
|
|
bullpen: Bullpen | null;
|
|
bullpens: Pageable<Bullpen> | null;
|
|
}
|
|
|
|
type BullpenActionContext = ActionContext<BullpenState, RootState>;
|
|
|
|
const bullpen: Module<BullpenState, RootState> = {
|
|
namespaced: true,
|
|
state: {
|
|
bullpen: null,
|
|
bullpens: null
|
|
},
|
|
actions: {
|
|
start({commit}: BullpenActionContext, user: User) {
|
|
const bullpen = BullpenSessionService.create(user);
|
|
commit('start', bullpen);
|
|
},
|
|
},
|
|
mutations: {
|
|
start(state, bullpen: Bullpen) {
|
|
state.bullpen = bullpen;
|
|
},
|
|
addPitch(state, pitch: Pitch) {
|
|
state.bullpen?.pitches.push({ ...pitch });
|
|
|
|
},
|
|
finish(state) {
|
|
state.bullpen = null;
|
|
},
|
|
fetch(state: BullpenState, bullpens: Pageable<Bullpen>) {
|
|
state.bullpens = bullpens;
|
|
}
|
|
}
|
|
};
|
|
|
|
export default bullpen;
|