summaryrefslogtreecommitdiff
path: root/app/presentation/components/set.js
blob: cd668f49e3b35b617587cb54cddc20fdf6fcdd7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import React, { Component } from 'react';
import { View } from 'react-native';
import { Button, Icon, Spinner, Text } from 'native-base';
import Weight from './weight';

export default class Set extends Component {
  constructor(props) {
    super(props);
    this.state = {
      actual_repetitions: 0
    };
  }
  render() {
    return (
      <Button style={{backgroundColor: this.backgroundColor()}} block info onPress={this.onPress.bind(this)}>
      {this.state.actual_repetitions} / {this.props.target_repetitions} @ <Weight weight={this.props.target_weight} />
      </Button>
    );
  }

  onPress() {
    let actual_repetitions = this.isCompleted() ? 0 : this.state.actual_repetitions + 1;
    this.setState({ actual_repetitions });
  }

  isCompleted() {
    console.log([this.state.actual_repetitions, this.props.target_repetitions]);
    return this.state.actual_repetitions === this.props.target_repetitions;
  }

  backgroundColor() {
    if (this.isCompleted()) { return "green"; }
    return this.props.type == "WarmUpSet" ? "pink" : "blue";
  }
}