Newer
Older
import { ScrollView, StyleSheet, View } from 'react-native'
import { LocalDate } from 'js-joda'
import { connect } from 'react-redux'
import { navigate } from '../slices/navigation'
import { getDate, setDate } from '../slices/date'
emelko
committed
import AppText from './common/app-text'
import cycleModule from '../lib/cycle'
import { getFertilityStatusForDay } from '../lib/sympto-adapter'
import { determinePredictionText, formatWithOrdinalSuffix } from './helpers/home'
import { Colors, Fonts, Sizes, Spacing } from '../styles'
import { home as labels } from '../i18n/en/labels'
class Home extends Component {
static propTypes = {
navigate: PropTypes.func,
const today = LocalDate.now()
this.todayDateString = today.toString()
const { getCycleDayNumber, getPredictedMenses } = cycleModule()
this.cycleDayNumber = getCycleDayNumber(this.todayDateString)
const { status, phase, statusText } =
getFertilityStatusForDay(this.todayDateString)
const prediction = getPredictedMenses()
this.prediction = determinePredictionText(prediction)
this.title = `${today.dayOfMonth()} ${today.month()} ${today.year()}`
if (this.cycleDayNumber) {
this.cycleDayText = formatWithOrdinalSuffix(this.cycleDayNumber)
}
if (phase) {
this.phase = phase
this.phaseText = formatWithOrdinalSuffix(phase)
this.status = status
this.statusText = statusText
}
navigateToCycleDayView = () => {
this.props.setDate(this.todayDateString)
this.props.navigate('CycleDay')
}
cycleDayText,
phase,
phaseText,
prediction,
status,
statusText,
title
<ScrollView
style={styles.container}
contentContainerStyle={styles.contentContainer}
>
<AppText style={styles.title}>{title}</AppText>
{cycleDayNumber &&
<View style={styles.line}>
<AppText style={styles.whiteSubtitle}>{cycleDayText}</AppText>
<AppText style={styles.tourquiseText}>{labels.cycleDay}</AppText>
</View>
}
{phase &&
<View style={styles.line}>
<AppText style={styles.whiteSubtitle}>{phaseText}</AppText>
<AppText style={styles.tourquiseText}>
{labels.cyclePhase}
</AppText>
<AppText style={styles.tourquiseText}>{status}</AppText>
<Asterisk />
</View>
}
<AppText style={styles.tourquiseText}>{prediction}</AppText>
<Button isCTA isSmall={false} onPress={this.navigateToCycleDayView}>
{labels.addData}
</Button>
{phase && (
<View style={styles.line}>
<Asterisk />
<AppText linkStyle={styles.whiteText}>
const Asterisk = () => {
return <AppText style={styles.asterisk}>*</AppText>
}
const styles = StyleSheet.create({
asterisk: {
color: Colors.orange,
},
container: {
backgroundColor: Colors.purple,
},
line: {
flexDirection: 'row',
justifyContent: 'flex-start',
marginBottom: Spacing.tiny,
marginTop: Spacing.small,
},
title: {
color: Colors.purpleLight,
fontFamily: Fonts.bold,
fontSize: Sizes.huge,
marginVertical: Spacing.base,
},
tourquiseText: {
color: Colors.tourquise,
fontSize: Sizes.subtitle,
},
whiteSubtitle: {
color: 'white',
fontSize: Sizes.subtitle,
const mapStateToProps = (state) => {
date: getDate(state),
})
}
const mapDispatchToProps = (dispatch) => {
navigate: (page) => dispatch(navigate(page)),
setDate: (date) => dispatch(setDate(date)),
})
}
export default connect(
mapDispatchToProps,
)(Home)