diff --git a/app/src/router/index.ts b/app/src/router/index.ts index ea1e325..9f3ec75 100644 --- a/app/src/router/index.ts +++ b/app/src/router/index.ts @@ -23,6 +23,10 @@ const routes: Array = [ path: '/pitchers', name: 'Pitchers', component: PitcherList + }, { + path: '/bullpen', + name: 'PreparePitch', + component: PreparePitch }, { path: '/prepare', name: 'PreparePitch', diff --git a/app/src/services/BullpenSessionService.ts b/app/src/services/BullpenSessionService.ts index e9732fd..ebb17ce 100644 --- a/app/src/services/BullpenSessionService.ts +++ b/app/src/services/BullpenSessionService.ts @@ -1,89 +1,32 @@ import Pitch from "@/types/Pitch"; import User from "@/types/User"; -import PitchType from "@/types/PitchType"; +import Bullpen from '@/types/Bullpen'; +import PitchTypeService from '@/services/PitchTypeService'; // import api from './Api'; export class BullpenSessionService { - private static nullPitcher: User = { - id: 0, - firstName: "", - lastName: "", - gender: "male", - handedness: "right", - height: 0.0, - weight: 0.0, - dateOfBirth: new Date(0), - createdAt: new Date(0), - updatedAt: new Date(0), - }; - private static nullPitchType: PitchType = { - id: 0, - name: "", - abbreviation: "" + public create(user: User): Bullpen { + return { + id: null, + startedAt: new Date(), + finishedAt: null, + pitcherId: user.id, + pitches: [] + } } - public constructor() { - this.currentPitch = this.createPitch(); - } + public finish(): void {} - public saveBullpen(): void {} - public startSession(pitcher: User): void { - this.pitcher = pitcher; - this.pitches = []; - this.currentPitch = this.createPitch(); - } - - public clear(): void { - this.pitcher = BullpenSessionService.nullPitcher; - this.pitches = []; - } - - public finishSession(): void { - // Todo: save to backend - } - public cancelSession(): void { - this.pitches = []; - this.pitcher = BullpenSessionService.nullPitcher; - } - - public addBullpenPitch( bullpenPitch: Pitch ): void { - this.pitches.push( bullpenPitch ); - } - - public getBullpenPitches(): Pitch[] { - return this.pitches; - } - - public currentBullpenPitch(): Pitch { - return this.currentPitch; - } - - public nextPitch(): void { - this.pitches.push(this.currentBullpenPitch()); - this.currentPitch = this.createPitch(); - } - - public getPitcher(): User { - return this.pitcher; - } - - public isSessionStarted(): boolean { - return this.pitcher.id === 0; - } - - private createPitch(): Pitch { + public createPitch(): Pitch { return { id: 0, date: new Date(), - pitchType: BullpenSessionService.nullPitchType, + pitchType: PitchTypeService.getLocalPitchTypes()[0], plannedPitchArea: 0, realPitchArea: 0, realPitchSubArea: 0 } } - private pitches: Pitch[] = []; - private pitcher: User = BullpenSessionService.nullPitcher; - private currentPitch: Pitch; } export default new BullpenSessionService(); diff --git a/app/src/store/auth.ts b/app/src/store/auth.ts index 28ad8e3..6ebe186 100644 --- a/app/src/store/auth.ts +++ b/app/src/store/auth.ts @@ -84,6 +84,9 @@ const auth: Module = { registerFailure(state) { state.isAuthenticated = false; } + }, + getters: { + getUser: (state) => state.user } }; diff --git a/app/src/store/bullpen.ts b/app/src/store/bullpen.ts new file mode 100644 index 0000000..1dd0e61 --- /dev/null +++ b/app/src/store/bullpen.ts @@ -0,0 +1,29 @@ +import { 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'; + +export interface BullpenState { + bullpen: Bullpen | null; +} + +const bullpen: Module = { + namespaced: true, + state: { bullpen: null }, + mutations: { + start(state, user: User) { + state.bullpen = BullpenSessionService.create(user); + }, + addPitch(state, pitch: Pitch) { + state.bullpen?.pitches.push({ ...pitch }); + + }, + finish(state) { + state.bullpen = null; + } + } +}; + +export default bullpen; diff --git a/app/src/store/index.ts b/app/src/store/index.ts index c35c7b1..f2122ac 100644 --- a/app/src/store/index.ts +++ b/app/src/store/index.ts @@ -1,11 +1,13 @@ import { InjectionKey } from 'vue' import { createStore, Store } from 'vuex'; import auth, {AuthState} from './auth'; +import bullpen, {BullpenState} from './bullpen'; import pitchTypes, {PitchTypeState} from './pitchType'; // Root state type export interface RootState { auth: AuthState; + bullpen: BullpenState; pitchTypes: PitchTypeState; } @@ -14,6 +16,7 @@ export const key: InjectionKey> = Symbol() const store = createStore({ modules: { auth, + bullpen, pitchTypes } }); diff --git a/app/src/types/Bullpen.ts b/app/src/types/Bullpen.ts index 8303ce4..b916f6c 100644 --- a/app/src/types/Bullpen.ts +++ b/app/src/types/Bullpen.ts @@ -1,9 +1,9 @@ import Pitch from "@/types/Pitch"; export default interface Bullpen { - id: number, + id: number | null, startedAt: Date, - finishedAt: Date, + finishedAt: Date | null, pitcherId: number, pitches: Pitch[] } diff --git a/app/src/types/BullpenStep.ts b/app/src/types/BullpenStep.ts new file mode 100644 index 0000000..66ad75c --- /dev/null +++ b/app/src/types/BullpenStep.ts @@ -0,0 +1,4 @@ +export enum BullpenStep { + Prepare = 1, + Finish = 2 +} diff --git a/app/src/views/PreparePitch.vue b/app/src/views/PreparePitch.vue index e893df8..488d447 100644 --- a/app/src/views/PreparePitch.vue +++ b/app/src/views/PreparePitch.vue @@ -1,6 +1,5 @@ + + + + + + + + + + + + + +