Skip to content

Commit

Permalink
delete entry from edit screen #174
Browse files Browse the repository at this point in the history
  • Loading branch information
kenpower committed Jun 29, 2021
1 parent 41d0c99 commit 7a0721d
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 13 deletions.
18 changes: 14 additions & 4 deletions src/components/EntryList.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
images as gip_images
} from '../components/GipTracker/GipTrackerClassConstants';

import GlutonManager from '../manager/GlutonManager';

export default class EntryList extends React.Component {
state = {
Expand Down Expand Up @@ -222,7 +223,12 @@ export default class EntryList extends React.Component {
return (
//<TouchableOpacity onPress={() => this.props.navigation.navigate('ViewSymptom', { event: item })}>
<HistoryEntry
onEditButtonClicked={() => this.props.navigation.navigate('AddSymptom', { event: item, edit: true })}
onEditButtonClicked={() => this.props.navigation.navigate('AddSymptom',
{
event: item,
edit: true,
deleteThisEntry: this.deleteEntry,
})}
onRightButtonClicked={() => this.props.navigation.navigate('DeleteScreen', { event: item })}
navigationName={LanguageManager.getInstance().getText(objData.name)}
title={time}
Expand All @@ -244,7 +250,12 @@ export default class EntryList extends React.Component {
//<TouchableOpacity onPress={() => this.props.navigation.navigate('ViewMeal', { event: item })}>
<HistoryEntry
onLeftButtonClicked={() => { this.toggleCulprit(item); }}
onEditButtonClicked={() => this.props.navigation.navigate('AddMeal', { event: item, edit: true })}
onEditButtonClicked={() => this.props.navigation.navigate('AddMeal',
{
event: item,
edit: true,
deleteThisEntry: this.deleteEntry,
})}
onRightButtonClicked={() => this.props.navigation.navigate('DeleteScreen', { event: item })}
navigationName={LanguageManager.getInstance().getText(objData.name)}
title={time}
Expand All @@ -270,7 +281,6 @@ export default class EntryList extends React.Component {
event: item,
edit: true,
deleteThisEntry: this.deleteEntry,
key: "EditScreen"
})}
onRightButtonClicked={() => this.props.navigation.navigate('DeleteScreen', { event: item })}
navigationName={LanguageManager.getInstance().getText(objData.name)}
Expand All @@ -297,7 +307,7 @@ export default class EntryList extends React.Component {
{
event: item,
edit: true,
deleteThisEntry: () => this.props.navigation.navigate('DeleteScreen', { event: item })
deleteThisEntry: this.deleteEntry,
})}
onRightButtonClicked={() => this.props.navigation.navigate('DeleteScreen', { event: item })}
navigationName={LanguageManager.getInstance().getText(objData.name)}
Expand Down
30 changes: 28 additions & 2 deletions src/screens/EmoteTrackerScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ export default class EmoteTrackerScreen extends React.Component {
emoteNote: objData.note,
selectedDateAndTime: new Date(eventData.created),
edit : true,
originalEventData: eventData
originalEventData: eventData,
eventId:eventData.id,
deleteThisEntry: this.props.navigation.getParam("deleteThisEntry",null)
})
}
}
Expand Down Expand Up @@ -161,6 +163,15 @@ export default class EmoteTrackerScreen extends React.Component {
})
}

handleDeleteButton = () =>{
this.setState({deleteDialogVisible: true});
};

handleDelete = () =>{
this.state.deleteThisEntry(this.state.eventId);
this.props.navigation.goBack();
};

toggleShowEmotionInformation = () => {
this.setState({showEmotionInformation: !this.state.showEmotionInformation})
}
Expand Down Expand Up @@ -205,6 +216,9 @@ export default class EmoteTrackerScreen extends React.Component {
<TouchableHighlight style={styles.buttonSaveAndCancel} onPress={this.saveCurrentData}>
<Text style={{ textAlign: 'center', color: '#707070' }}>{this.state.edit? "Update":"Save"}</Text>
</TouchableHighlight>
{this.state.edit && <TouchableHighlight style={styles.buttonSaveAndCancel} onPress={this.handleDeleteButton}>
<Text style={{textAlign: 'center', color: '#707070'}}>Delete</Text>
</TouchableHighlight> }
</View>
</View>

Expand All @@ -219,7 +233,18 @@ export default class EmoteTrackerScreen extends React.Component {
<Dialog.Button label={LanguageManager.getInstance().getText("DISCARD")} onPress={this.handleDiscard} />
</Dialog.Container>
</View>

<View>
<Dialog.Container visible={this.state.deleteDialogVisible}>
<Dialog.Title>{LanguageManager.getInstance().getText("DELETE")}</Dialog.Title>
<Dialog.Description>
{LanguageManager.getInstance().getText("DO_YOU_WANT_TO_DELETE")}
</Dialog.Description>
<Dialog.Button label={LanguageManager.getInstance().getText("No")}
onPress={() => this.handleBack()}/>
<Dialog.Button label={LanguageManager.getInstance().getText("YES")}
onPress={() => this.handleDelete()}/>
</Dialog.Container>
</View>
{this.state.showEmotionInformation &&
<EmotionInformation color={themeColor} position={this.state.informationPosition}/>
}
Expand Down Expand Up @@ -285,6 +310,7 @@ export default class EmoteTrackerScreen extends React.Component {

handleBack = () => {
this.setState({ cancelSaveDialogVisible: false });
this.setState({deleteDialogVisible: false});
};

handleDiscard = () => {
Expand Down
27 changes: 27 additions & 0 deletions src/screens/FoodDiaryScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ export default class FoodDiaryScreen extends React.Component {
edit: true,
originalEventData: eventData,
photo: this.state.photo || objData.icon,
eventId:eventData.id,
deleteThisEntry: this.props.navigation.getParam("deleteThisEntry",null)
})
}
}
Expand Down Expand Up @@ -303,6 +305,7 @@ export default class FoodDiaryScreen extends React.Component {
handleBack() {
this.setState({cancelSaveDialogVisible: false});
this.setState({saveAsEmptyFoodDialogVisible: false});
this.setState({deleteDialogVisible: false});
};

handleDiscard() {
Expand All @@ -311,6 +314,15 @@ export default class FoodDiaryScreen extends React.Component {
this.navigateHome()
};

handleDeleteButton = () =>{
this.setState({deleteDialogVisible: true});
};

handleDelete = () =>{
this.state.deleteThisEntry(this.state.eventId);
this.props.navigation.goBack();
};


toggleShowFoodInformation = () => {
this.setState({showFoodInformation: !this.state.showFoodInformation})
Expand Down Expand Up @@ -392,6 +404,9 @@ export default class FoodDiaryScreen extends React.Component {
color: '#707070'
}}>{this.state.edit ? "Update" : "Save"}</Text>
</TouchableHighlight>
{this.state.edit && <TouchableHighlight style={styles.buttonSaveAndCancel} onPress={this.handleDeleteButton}>
<Text style={{textAlign: 'center', color: '#707070'}}>Delete</Text>
</TouchableHighlight> }
</View>
</View>

Expand Down Expand Up @@ -423,6 +438,18 @@ export default class FoodDiaryScreen extends React.Component {
onPress={() => this.handleDiscard()}/>
</Dialog.Container>
</View>
<View>
<Dialog.Container visible={this.state.deleteDialogVisible}>
<Dialog.Title>{LanguageManager.getInstance().getText("DELETE")}</Dialog.Title>
<Dialog.Description>
{LanguageManager.getInstance().getText("DO_YOU_WANT_TO_DELETE")}
</Dialog.Description>
<Dialog.Button label={LanguageManager.getInstance().getText("No")}
onPress={() => this.handleBack()}/>
<Dialog.Button label={LanguageManager.getInstance().getText("YES")}
onPress={() => this.handleDelete()}/>
</Dialog.Container>
</View>
</KeyboardAwareScrollView>
</>
)
Expand Down
8 changes: 4 additions & 4 deletions src/screens/GIPScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export default class GIPScreen extends React.Component {
edit: true,
originalEventData: eventData,
eventId:eventData.id,
deleteThisEntry: this.props.navigation.getParam("deleteEntry",null)
deleteThisEntry: this.props.navigation.getParam("deleteThisEntry",null)
})
}
}
Expand Down Expand Up @@ -348,15 +348,15 @@ export default class GIPScreen extends React.Component {
</Dialog.Container>
</View>
<View>
<Dialog.Container visible={this.state.cancelDeleteDialogVisible}>
<Dialog.Container visible={this.state.cancelSaveDialogVisible}>
<Dialog.Title>{LanguageManager.getInstance().getText("DISCARD")}</Dialog.Title>
<Dialog.Description>
{LanguageManager.getInstance().getText("DO_YOU_WANT_TO_DISCARD")}
</Dialog.Description>
<Dialog.Button label={LanguageManager.getInstance().getText("No")}
onPress={() => this.handleBack()}/>
<Dialog.Button label={LanguageManager.getInstance().getText("YES")}
onPress={() => this.handleDelete()}/>
onPress={() => this.handleDiscard()}/>
</Dialog.Container>
</View>
<View>
Expand All @@ -368,7 +368,7 @@ export default class GIPScreen extends React.Component {
<Dialog.Button label={LanguageManager.getInstance().getText("No")}
onPress={() => this.handleBack()}/>
<Dialog.Button label={LanguageManager.getInstance().getText("YES")}
onPress={() => this.handleDiscard()}/>
onPress={() => this.handleDelete()}/>
</Dialog.Container>
</View>
</KeyboardAwareScrollView>
Expand Down
32 changes: 29 additions & 3 deletions src/screens/SymptomTrackerScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ export default class SymptomTrackerScreen extends React.Component {
symptomEntryNote : objData.note,
selectedDateAndTime: new Date(eventData.created),
edit : true,
originalEventData: eventData
originalEventData: eventData,
eventId:eventData.id,
deleteThisEntry: this.props.navigation.getParam("deleteThisEntry",null)
})
}
}
Expand Down Expand Up @@ -138,6 +140,7 @@ export default class SymptomTrackerScreen extends React.Component {

handleBack = () => {
this.setState({ cancelSaveDialogVisible: false });
this.setState({deleteDialogVisible: false});
};

handleDiscard = () => {
Expand Down Expand Up @@ -187,14 +190,22 @@ export default class SymptomTrackerScreen extends React.Component {
});
}

handleDeleteButton = () =>{
this.setState({deleteDialogVisible: true});
};

handleDelete = () =>{
this.state.deleteThisEntry(this.state.eventId);
this.props.navigation.goBack();
};

toggleShowSymptomInformation = () => {
this.setState({showSymptomInformation: !this.state.showSymptomInformation})
}

render() {
console.log("Symptom tracker state:", this.state)
return (
<>
return (<>
<SafeAreaView style={{ flex: 0, backgroundColor: themeColor }} />
<KeyboardAwareScrollView style={{ backgroundColor: "#fff" }} keyboardShouldPersistTaps="handled">
{/* <TextInput onSubmitEditing={Keyboard.dismiss} /> */}
Expand Down Expand Up @@ -222,6 +233,9 @@ export default class SymptomTrackerScreen extends React.Component {
<TouchableHighlight style={styles.buttonSaveAndCancel} onPress={this.saveCurrentData}>
<Text style={{ textAlign: 'center', color: '#707070' }}>{this.state.edit? "Update":"Save"}</Text>
</TouchableHighlight>
{this.state.edit && <TouchableHighlight style={styles.buttonSaveAndCancel} onPress={this.handleDeleteButton}>
<Text style={{textAlign: 'center', color: '#707070'}}>Delete</Text>
</TouchableHighlight> }
</View>
</View>
{this.state.showSymptomInformation &&
Expand All @@ -238,6 +252,18 @@ export default class SymptomTrackerScreen extends React.Component {
<Dialog.Button label={LanguageManager.getInstance().getText("DISCARD")} onPress={this.handleDiscard} />
</Dialog.Container>
</View>
<View>
<Dialog.Container visible={this.state.deleteDialogVisible}>
<Dialog.Title>{LanguageManager.getInstance().getText("DELETE")}</Dialog.Title>
<Dialog.Description>
{LanguageManager.getInstance().getText("DO_YOU_WANT_TO_DELETE")}
</Dialog.Description>
<Dialog.Button label={LanguageManager.getInstance().getText("No")}
onPress={() => this.handleBack()}/>
<Dialog.Button label={LanguageManager.getInstance().getText("YES")}
onPress={() => this.handleDelete()}/>
</Dialog.Container>
</View>
{/* <KeyboardListener
onWillShow={() => { this.setState({ keyboardOpen: true }); }}
onWillHide={() => { this.setState({ keyboardOpen: false }); }}
Expand Down

0 comments on commit 7a0721d

Please sign in to comment.