Commit 17326cf
Changed files (4)
app
screens
services
commands
app/screens/new-workout-screen.js
@@ -66,11 +66,26 @@ export default class NewWorkoutScreen extends Screen {
}
onPress(exercise) {
- console.log(`pressed ${exercise.name}`)
+ console.log(`pressed ${exercise.name}`);
}
onBeginWorkout() {
console.log("BEGIN WORKOUT");
+ const sets = this.state.sets.map((set) => {
+ return {
+ exercise_id: set.exercise_id,
+ target_repetitions: set.target_repetitions,
+ target_weight: set.target_weight,
+ type: set.type,
+ };
+ });
+
+ this.publish({
+ body_weight: this.state.body_weight,
+ event: events.CREATE_WORKOUT,
+ routine_id: this.state.routine.id,
+ sets: sets,
+ });
}
onLoadWorkout() {
app/services/commands/create-workout-command.js
@@ -0,0 +1,26 @@
+import * as events from '../events';
+
+export default class CreateWorkoutCommand {
+ constructor(eventAggregator, api) {
+ this.eventAggregator = eventAggregator;
+ this.api = api;
+ }
+
+ subscribeTo(eventAggregator) {
+ eventAggregator.subscribe(events.CREATE_WORKOUT, this);
+ }
+
+ notify(event) {
+ const body = {
+ body_weight: event.body_weight,
+ exercise_sets_attributes: event.sets,
+ routine_id: event.routine_id,
+ };
+ this.api.post('/workouts', body, this.onResponse.bind(this));
+ }
+
+ onResponse(json) {
+ console.log("CREATED");
+ console.log(json);
+ }
+}
app/services/commands/index.js
@@ -1,7 +1,9 @@
+import CreateWorkoutCommand from './create-workout-command';
import LoginCommand from './login-command';
import LogoutCommand from './logout-command';
export {
+ CreateWorkoutCommand,
LoginCommand,
LogoutCommand,
};
app/services/events.js
@@ -5,3 +5,4 @@ export const FETCH_WORKOUTS = 'FETCH_WORKOUTS';
export const FETCHED_WORKOUTS = 'FETCHED_WORKOUTS';
export const FETCH_NEW_WORKOUT = 'FETCH_NEW_WORKOUT';
export const FETCHED_NEW_WORKOUT = 'FETCHED_NEW_WORKOUT';
+export const CREATE_WORKOUT = 'CREATE_WORKOUT';