swimtracker-app/components/LiveTrainingView.js

78 lines
2.7 KiB
JavaScript
Raw Normal View History

2020-06-02 17:19:09 +02:00
import React from 'react';
2020-06-02 22:43:48 +02:00
import { StyleSheet } from 'react-native';
import { Button, Content, Text } from 'native-base';
2020-06-02 17:19:09 +02:00
import { LinearGradient } from 'expo-linear-gradient';
import IconCard from './IconCard';
import Graph from './Graph';
2020-06-02 22:43:48 +02:00
import { connect } from 'react-redux';
import backgroundColors from './Themes';
2020-06-23 21:36:14 +02:00
import { useKeepAwake } from 'expo-keep-awake';
import { stopSession } from '../state/DeviceReduxCoupling';
2020-06-02 17:19:09 +02:00
function LiveTrainingView(props) {
2020-06-02 22:43:48 +02:00
const analysis = props.session.analysis;
const onStopClick = () => {
props.dispatch(stopSession());
props.navigation.navigate('Home');
2020-06-02 17:19:09 +02:00
};
2020-06-02 22:43:48 +02:00
const laps = (analysis.peaks.size / props.peaksPerLap).toFixed(1);
2020-06-30 18:06:37 +02:00
const totalMomentum = Math.trunc(analysis.totalMomentum * props.kgFactor / 10 / 60);
2020-06-02 22:43:48 +02:00
2020-06-23 21:36:14 +02:00
useKeepAwake();
2020-06-02 22:43:48 +02:00
return (
<LinearGradient
colors={backgroundColors[props.theme]}
start={[0, 0]}
end={[0.5, 1]}
style={{ flex: 1 }}
>
<Content padder contentContainerStyle={{ justifyContent: 'space-around', flex: 1, paddingTop: 60 }}>
<IconCard label="BAHNEN" value={laps} iconName="retweet" iconType="AntDesign" />
<IconCard label="ZÜGE" value={analysis.peaks.size} iconName="dashboard" iconType="AntDesign" />
<IconCard label="KRAFT" value={totalMomentum} iconName="ruler" iconType="Entypo" />
2020-06-28 22:10:54 +02:00
<Graph></Graph>
2020-06-02 17:19:09 +02:00
{/*
2020-06-02 22:43:48 +02:00
<IconCard label="ZÜGE" value={this.state.numPeaks} iconName="dashboard" iconType="AntDesign" />
<IconCard label="BAHNEN" value={this.state.numLaps} iconName="retweet" iconType="AntDesign" />
2020-06-02 17:19:09 +02:00
2020-06-02 22:43:48 +02:00
<IconCard label="KRAFT" value="120" iconName="ruler" iconType="Entypo" />
2020-06-02 17:19:09 +02:00
*/}
2020-06-02 22:43:48 +02:00
<Button block secondary onPress={onStopClick}><Text>Stop</Text></Button>
2020-06-02 17:19:09 +02:00
</Content>
2020-06-02 22:43:48 +02:00
</LinearGradient>
);
2020-06-02 17:19:09 +02:00
}
const styles = StyleSheet.create({
card: {
flexDirection: 'row',
backgroundColor: 'rgba(0, 0, 0, 0.2)',
margin: 5,
padding: 5,
borderRadius: 3,
justifyContent: 'space-between',
/*
shadowColor: "#000",
shadowOffset: {
width: 0,
height: 1,
},
shadowOpacity: 0.18,
shadowRadius: 1.00,
elevation: 1,*/
}
});
2020-06-02 22:43:48 +02:00
const mapStateToProps = (state) => {
return {
session: state.deviceState,
peaksPerLap: state.settings.analysis.peaksPerLap,
theme: state.settings.theme,
2020-06-30 18:06:37 +02:00
kgFactor: state.settings.analysis.kgFactor,
2020-06-02 22:43:48 +02:00
};
};
export default connect(mapStateToProps)(LiveTrainingView);