Newer
Older
import {
BackHandler, View, Alert, TouchableOpacity
} from 'react-native'
import { saveSymptom } from '../../../db'
import InfoPopUp from './info-symptom'
import Header from '../../header/symptom-view'
import { headerTitles } from '../../../i18n/en/labels'
import { sharedDialogs } from '../../../i18n/en/cycle-day'
import FeatherIcon from 'react-native-vector-icons/Feather'
import styles, { iconStyles } from '../../../styles'
export default class SymptomView extends Component {
this.backHandler = BackHandler.addEventListener(
'hardwareBackPress',
this.handleBackButtonPressOnSymptomView.bind(this)
)
this.globalBackhandler = props.handleBackButtonPress
this.navigate = props.navigate
this.state = {
showInfo: false
}
async handleBackButtonPressOnSymptomView() {
// every specific symptom view provides their own onBackButtonPress method
const stopHere = await this.onBackButtonPress()
if (!stopHere) this.globalBackhandler()
}
saveSymptomEntry(entry) {
saveSymptom(this.symptomName, this.date, entry)
}
deleteSymptomEntry() {
saveSymptom(this.symptomName, this.date)
}
componentWillUnmount() {
this.backHandler.remove()
}
isDeleteIconActive() {
return Object.keys(this.state).some(key => {
if (key === 'showInfo') return
// is there any meaningful value in the current state?
return this.state[key] || this.state[key] === 0
render() {
return (
<View style={{flex: 1}}>
<Header
title={headerTitles[this.symptomName].toLowerCase()}
date={this.date}
goBack={this.handleBackButtonPressOnSymptomView.bind(this)}
deleteIconActive={this.isDeleteIconActive()}
Alert.alert(
sharedDialogs.areYouSureTitle,
sharedDialogs.areYouSureToDelete,
[{
text: sharedDialogs.cancel,
style: 'cancel'
}, {
text: sharedDialogs.reallyDeleteData,
onPress: () => {
this.deleteSymptomEntry()
this.globalBackhandler()
}
}]
)
<TouchableOpacity
onPress={() => this.setState({showInfo: true})}
style={styles.infoButtonSymptomView}
>
<FeatherIcon
name="info"
{...iconStyles.infoInSymptomView}
style={iconStyles.symptomInfo}
/>
</TouchableOpacity>
{this.renderContent()}
{ this.state.showInfo &&
<InfoPopUp
symptom={this.symptomName}
close={() => this.setState({showInfo: false})}
/>
}
</View>