changes footer depending on new entry or edit mode
This commit is contained in:
@@ -23,7 +23,13 @@ export default class SelectTabGroup extends Component {
|
|||||||
if (isActive) activeStyle = styles.selectTabActive
|
if (isActive) activeStyle = styles.selectTabActive
|
||||||
return (
|
return (
|
||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
onPress={() => isActive ? this.props.onSelect(null) : this.props.onSelect(value)}
|
onPress={() => {
|
||||||
|
if (this.props.isRadioButton) {
|
||||||
|
this.props.onSelect(value)
|
||||||
|
} else {
|
||||||
|
isActive ? this.props.onSelect(null) : this.props.onSelect(value)
|
||||||
|
}
|
||||||
|
}}
|
||||||
key={i}
|
key={i}
|
||||||
activeOpacity={1}
|
activeOpacity={1}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -3,11 +3,13 @@ import {
|
|||||||
View, TouchableOpacity, Text
|
View, TouchableOpacity, Text
|
||||||
} from 'react-native'
|
} from 'react-native'
|
||||||
import Icon from 'react-native-vector-icons/MaterialCommunityIcons'
|
import Icon from 'react-native-vector-icons/MaterialCommunityIcons'
|
||||||
|
import { saveSymptom } from '../../../db'
|
||||||
import styles, {iconStyles} from '../../../styles'
|
import styles, {iconStyles} from '../../../styles'
|
||||||
|
|
||||||
export default class ActionButtonFooter extends Component {
|
export default class ActionButtonFooter extends Component {
|
||||||
render() {
|
render() {
|
||||||
const {
|
const {
|
||||||
|
symptom,
|
||||||
cycleDay,
|
cycleDay,
|
||||||
saveAction,
|
saveAction,
|
||||||
saveDisabled,
|
saveDisabled,
|
||||||
@@ -15,33 +17,65 @@ export default class ActionButtonFooter extends Component {
|
|||||||
autoShowDayView = true}
|
autoShowDayView = true}
|
||||||
= this.props
|
= this.props
|
||||||
const navigateToOverView = () => navigate('CycleDay', {cycleDay})
|
const navigateToOverView = () => navigate('CycleDay', {cycleDay})
|
||||||
const saveButton = {
|
const buttonsNewEntry = [
|
||||||
title: 'Save',
|
{
|
||||||
action: () => {
|
title: 'Cancel',
|
||||||
saveAction()
|
action: () => navigateToOverView(),
|
||||||
if (autoShowDayView) navigateToOverView()
|
icon: 'cancel'
|
||||||
},
|
},
|
||||||
disabledCondition: saveDisabled,
|
{
|
||||||
icon: 'content-save-outline'
|
title: 'Add',
|
||||||
}
|
action: () => {
|
||||||
const textStyle = saveButton.disabledCondition ? styles.menuTextInActive : styles.menuText
|
saveAction()
|
||||||
const iconStyle = saveButton.disabledCondition ?
|
if (autoShowDayView) navigateToOverView()
|
||||||
Object.assign({}, iconStyles.menuIcon, iconStyles.menuIconInactive) :
|
},
|
||||||
iconStyles.menuIcon
|
disabledCondition: saveDisabled,
|
||||||
|
icon: 'content-save-outline'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
const buttonsEdit = [
|
||||||
|
{
|
||||||
|
title: 'Delete',
|
||||||
|
action: () => {
|
||||||
|
saveSymptom(symptom, cycleDay)
|
||||||
|
navigateToOverView()
|
||||||
|
},
|
||||||
|
disabledCondition: !cycleDay[symptom],
|
||||||
|
icon: 'delete-outline'
|
||||||
|
}, {
|
||||||
|
title: 'Save',
|
||||||
|
action: () => {
|
||||||
|
saveAction()
|
||||||
|
if (autoShowDayView) navigateToOverView()
|
||||||
|
},
|
||||||
|
disabledCondition: saveDisabled,
|
||||||
|
icon: 'content-save-outline'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
const buttons = !cycleDay[symptom] ? buttonsNewEntry : buttonsEdit
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.menu}>
|
<View style={styles.menu}>
|
||||||
<TouchableOpacity
|
{buttons.map(({ title, action, disabledCondition, icon }, i) => {
|
||||||
onPress={saveButton.action}
|
const textStyle = disabledCondition ? styles.menuTextInActive : styles.menuText
|
||||||
style={styles.menuItem}
|
const iconStyle = disabledCondition ?
|
||||||
disabled={saveButton.disabledCondition}
|
Object.assign({}, iconStyles.menuIcon, iconStyles.menuIconInactive) :
|
||||||
key={'save'}
|
iconStyles.menuIcon
|
||||||
>
|
|
||||||
<Icon name={saveButton.icon} {...iconStyle} />
|
return (
|
||||||
<Text style={textStyle}>
|
<TouchableOpacity
|
||||||
{saveButton.title}
|
onPress={action}
|
||||||
</Text>
|
style={styles.menuItem}
|
||||||
</TouchableOpacity>
|
disabled={disabledCondition}
|
||||||
|
key={i.toString()}
|
||||||
|
>
|
||||||
|
<Icon name={icon} {...iconStyle} />
|
||||||
|
<Text style={textStyle}>
|
||||||
|
{title}
|
||||||
|
</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
)
|
||||||
|
})}
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ export default class Bleeding extends Component {
|
|||||||
buttons={bleedingRadioProps}
|
buttons={bleedingRadioProps}
|
||||||
active={this.state.currentValue}
|
active={this.state.currentValue}
|
||||||
onSelect={val => this.setState({ currentValue: val })}
|
onSelect={val => this.setState({ currentValue: val })}
|
||||||
|
isRadioButton={true}
|
||||||
/>
|
/>
|
||||||
</SymptomSection>
|
</SymptomSection>
|
||||||
<SymptomSection
|
<SymptomSection
|
||||||
@@ -56,6 +57,7 @@ export default class Bleeding extends Component {
|
|||||||
</SymptomSection>
|
</SymptomSection>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
<ActionButtonFooter
|
<ActionButtonFooter
|
||||||
|
symptom='bleeding'
|
||||||
cycleDay={this.props.cycleDay}
|
cycleDay={this.props.cycleDay}
|
||||||
saveAction={() => {
|
saveAction={() => {
|
||||||
saveSymptom('bleeding', this.props.cycleDay, {
|
saveSymptom('bleeding', this.props.cycleDay, {
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ export default class Cervix extends Component {
|
|||||||
buttons={cervixOpeningRadioProps}
|
buttons={cervixOpeningRadioProps}
|
||||||
active={this.state.opening}
|
active={this.state.opening}
|
||||||
onSelect={val => this.setState({ opening: val })}
|
onSelect={val => this.setState({ opening: val })}
|
||||||
|
isRadioButton={true}
|
||||||
/>
|
/>
|
||||||
</SymptomSection>
|
</SymptomSection>
|
||||||
<SymptomSection
|
<SymptomSection
|
||||||
@@ -60,6 +61,7 @@ export default class Cervix extends Component {
|
|||||||
buttons={cervixFirmnessRadioProps}
|
buttons={cervixFirmnessRadioProps}
|
||||||
active={this.state.firmness}
|
active={this.state.firmness}
|
||||||
onSelect={val => this.setState({ firmness: val })}
|
onSelect={val => this.setState({ firmness: val })}
|
||||||
|
isRadioButton={true}
|
||||||
/>
|
/>
|
||||||
</SymptomSection>
|
</SymptomSection>
|
||||||
<SymptomSection
|
<SymptomSection
|
||||||
@@ -70,6 +72,7 @@ export default class Cervix extends Component {
|
|||||||
buttons={cervixPositionRadioProps}
|
buttons={cervixPositionRadioProps}
|
||||||
active={this.state.position}
|
active={this.state.position}
|
||||||
onSelect={val => this.setState({ position: val })}
|
onSelect={val => this.setState({ position: val })}
|
||||||
|
isRadioButton={false}
|
||||||
/>
|
/>
|
||||||
</SymptomSection>
|
</SymptomSection>
|
||||||
<SymptomSection
|
<SymptomSection
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ export default class Desire extends Component {
|
|||||||
buttons={desireRadioProps}
|
buttons={desireRadioProps}
|
||||||
active={this.state.currentValue}
|
active={this.state.currentValue}
|
||||||
onSelect={val => this.setState({ currentValue: val })}
|
onSelect={val => this.setState({ currentValue: val })}
|
||||||
|
isRadioButton={true}
|
||||||
/>
|
/>
|
||||||
</SymptomSection>
|
</SymptomSection>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|||||||
Reference in New Issue
Block a user