-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Alarm component #77
Merged
Merged
Alarm component #77
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
299fd65
setup alarmmodescreen
Wennxn 2e136cc
Snooze screen layout
Wennxn 78e9618
add logic to render time, change background colour, trigger alert di…
Wennxn 7da9c0f
Merge branch 'master' into alarm-component
Asiapenguin 1a049d1
Fixed prop types, and consistent background color, flashing yellow an…
Asiapenguin 8d54f2a
Readded title
Asiapenguin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,108 @@ | ||
import React, { Component } from "react"; | ||
import { | ||
StyleSheet, | ||
Button | ||
} from "react-native"; | ||
import { StyleSheet, Alert } from "react-native"; | ||
import { Button } from "../components/buttons"; | ||
import { Actions } from "react-native-router-flux"; | ||
import { Container, Content, Header, View } from "../components/layout"; | ||
import { Text } from "../components/typography"; | ||
import { connect } from 'react-redux'; | ||
import { increaseTime, decreaseTime, countdown, clearTime, resetTime } from '../store/actions'; | ||
|
||
const SnoozeScreen = () => { | ||
return ( | ||
<Container> | ||
<Header>Snooze Mode</Header> | ||
<Content> | ||
<View style={styles.container}> | ||
<Text style={styles.welcome}> | ||
Snooze Screen | ||
</Text> | ||
<Button title="Snooze" onPress={() => Actions.alarm()} /> | ||
</View> | ||
</Content> | ||
</Container> | ||
); | ||
class SnoozeScreen extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.countdown = this.countdown.bind(this); | ||
this.snoozeHandler = this.snoozeHandler.bind(this); | ||
} | ||
|
||
countdown() { | ||
if (this.props.time.timeRemaining - 1 <= 0) { | ||
this.props.clearTime(); | ||
clearInterval(this.interval); | ||
Alert.alert("Help request sent", "Help request has been sent to your responder network", [{text: 'OK', onPress: () => Actions.main()}], {cancelable: false}); | ||
} else { | ||
this.props.countdown(this.props.time.timeRemaining); | ||
} | ||
}; | ||
|
||
convertSeconds = (seconds) => { | ||
let second = Math.floor(seconds % 3600 % 60); | ||
if (second <= 9) { | ||
second = "0" + second; | ||
} | ||
return second; | ||
}; | ||
|
||
convertSecondsToMinutes = (seconds) => { | ||
let minute = Math.floor(seconds % 3600 / 60); | ||
return minute; | ||
}; | ||
|
||
snoozeHandler() { | ||
clearInterval(this.interval); | ||
this.props.resetTime(); | ||
Actions.alarm(); | ||
}; | ||
|
||
componentDidMount() { | ||
this.props.countdown(this.props.time.timeRemaining); | ||
this.interval = setInterval(this.countdown, 1000); | ||
}; | ||
|
||
render() { | ||
const { timeRemaining } = this.props.time; | ||
return ( | ||
<Container style={{backgroundColor: (timeRemaining % 2 === 0)? "#ff0000" : "#ffa500"}}> | ||
<Header>Snooze Mode</Header> | ||
<Content> | ||
<View style={styles.container, {backgroundColor: (timeRemaining % 2 === 0)? "#ff0000" : "#ffa500"}}> | ||
<Text style={styles.textStyle}> | ||
your responders{"\n"}will be notified in: | ||
</Text> | ||
<Text style={styles.timeStyle}> | ||
{this.convertSecondsToMinutes(timeRemaining)}:{this.convertSeconds(timeRemaining)} | ||
</Text> | ||
<Button variant="snooze" onPress={this.snoozeHandler}> | ||
snooze | ||
</Button> | ||
<Text style={styles.textStyle}> | ||
We'll check up on your in 2 minutes | ||
</Text> | ||
</View> | ||
</Content> | ||
</Container> | ||
); | ||
} | ||
} | ||
|
||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
justifyContent: "center", | ||
alignItems: "center", | ||
backgroundColor: "cyan", | ||
}, | ||
welcome: { | ||
fontSize: 20, | ||
textStyle: { | ||
fontSize: 18, | ||
fontWeight: "bold", | ||
textAlign: "center", | ||
margin: 10, | ||
color: "#ffffff", | ||
alignItems: "center", | ||
}, | ||
timeStyle: { | ||
fontSize: 72, | ||
fontWeight: "bold", | ||
color: "#ffffff", | ||
textAlign: "center", | ||
paddingTop: 60, | ||
paddingBottom: 80, | ||
justifyContent: "center", | ||
alignItems: "center", | ||
}, | ||
}); | ||
|
||
export default SnoozeScreen; | ||
function mapStateToProps(state) { | ||
return { | ||
time: state.timer | ||
} | ||
} | ||
|
||
export default connect(mapStateToProps, { increaseTime, decreaseTime, countdown, clearTime, resetTime })(SnoozeScreen); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would likely want to make these into utility functions that can be used throughout app. I think I would maybe consider that we start using "momentjs" for time and date manipulations and stuff, but maybe a bit overkill too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. This should be extracted into a service class to deal with time related conversions and calculations. However, I wouldnt add a dependency just for this.
Creating the service and refactoring will be another task. Here