Newer
Older
import React from 'react'
import { ImageBackground, StyleSheet, View } from 'react-native'
import AppPage from './common/app-page'
import AppText from './common/app-text'
import Segment from './common/segment'
import Table from './common/table'
tina
committed
import cycleModule from '../lib/cycle'
import {getCycleLengthStats as getCycleInfo} from '../lib/cycle-length'
import {stats as labels} from '../i18n/en/labels'
tina
committed
import { Sizes, Spacing, Typography } from '../styles/redesign'
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const image = require('../assets/cycle-icon.png')
const Stats = () => {
const cycleLengths = cycleModule().getAllCycleLengths()
const atLeastOneCycle = cycleLengths.length >= 1
const numberOfCycles = cycleLengths.length
let cycleData
if (atLeastOneCycle) {
cycleData = getCycleInfo(cycleLengths)
}
const statsData = [
[atLeastOneCycle ? cycleData.minimum : 0, labels.minLabel],
[atLeastOneCycle ? cycleData.maximum : 0, labels.maxLabel],
[atLeastOneCycle && cycleData.stdDeviation ? cycleData.stdDeviation : '—', labels.stdLabel],
[numberOfCycles, labels.basisOfStatsEnd]
]
return (
<AppPage>
<Segment last style={styles.pageContainer}>
<AppText>{labels.cycleLengthExplainer}</AppText>
{!atLeastOneCycle && <AppText>{labels.emptyStats}</AppText>}
{atLeastOneCycle &&
<View style={styles.container}>
<View style={styles.columnLeft}>
<ImageBackground
source={image}
imageStyle={styles.image}
style={styles.imageContainter}
>
<AppText
numberOfLines={1}
ellipsizeMode="clip"
style={styles.accentPurpleGiant}
>
{cycleData.mean}
</AppText>
<AppText style={styles.accentPurpleHuge}>
{labels.daysLabel}
</AppText>
</ImageBackground>
<AppText style={styles.accentOrange}>
{labels.averageLabel}
<View style={styles.columnRight}>
<Table tableContent={statsData} />
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
const column = {
flexDirection: 'column'
}
const styles = StyleSheet.create({
accentOrange: {
...Typography.accentOrange
},
accentPurpleGiant: {
...Typography.accentPurpleGiant,
marginVertical: Sizes.giant * (-0.5)
},
accentPurpleHuge: {
...Typography.accentPurpleHuge,
marginRight: Spacing.base
},
container: {
alignItems: 'center',
flexDirection: 'row',
justifyContent: 'space-between',
},
columnLeft: {
...column,
flex: 4
},
columnRight: {
...column,
flex: 5
},
image: {
height: Sizes.huge * 3,
marginLeft: Sizes.huge / 2,
resizeMode: 'contain',
width: Sizes.huge * 3
},
imageContainter: {
paddingTop: Sizes.huge,
marginBottom: Sizes.huge / 4
},
pageContainer: {
marginVertical: Spacing.large
}
})
export default Stats