Skip to content

Commit

Permalink
Merge pull request #6 from ganeshh123/reloaded
Browse files Browse the repository at this point in the history
Reloaded
  • Loading branch information
ganeshh123 authored Jun 20, 2020
2 parents 9496d06 + 03033f0 commit a01a496
Show file tree
Hide file tree
Showing 9 changed files with 363 additions and 5 deletions.
Binary file added img/campfire.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ <h1>Headphones Recommended</h1>
<a href="https://ganeshh123.github.io">Ganesh H</a>
</div>
</div>
<script defer src='./js/timer.js' type='text/babel'></script>
<script defer src='./js/app.js' type='text/babel'></script>
</body>

Expand Down
21 changes: 17 additions & 4 deletions js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ let styles = {
display: 'flex',
flexDirection: 'row',
justifyContent: 'space-around',
width: '100%'
width: '100%',
marginTop: 10,
marginBottom: 10
}
}

Expand Down Expand Up @@ -127,6 +129,7 @@ class SceneSelect extends React.Component{
>
<MenuItem value={'rain_on_leaves'}>Rain falling on leaves</MenuItem>
<MenuItem value={'forest_1'}>Calm Forest</MenuItem>
<MenuItem value={'campfire'}>Campfire</MenuItem>
</Select>
<FormHelperText>{this.state.currentScene.description}</FormHelperText>
</FormControl>
Expand Down Expand Up @@ -162,16 +165,26 @@ class App extends React.Component{
}
}

toggleTimer = (e) => {
let timerElement = document.querySelector('#appTimer')
if(!timerElement.style.display || timerElement.style.display === 'none'){
timerElement.style.display = 'flex'
}else{
timerElement.style.display ='none'
}
}


render(){
return(
<div id='app' style={styles.app}>
<MainTimer />
<div id='sceneSwitch' style={styles.sceneSwitch}>
<IconButton aria-label="switch_video" onClick={this.switchVideo}>
<Icon>{this.state.videoMode}</Icon>
</IconButton>
<IconButton disabled>
<Icon></Icon>
<IconButton onClick={this.toggleTimer}>
<Icon>timer</Icon>
</IconButton>
<IconButton disabled>
<Icon></Icon>
Expand All @@ -180,7 +193,7 @@ class App extends React.Component{
</div>
<div id='volControls' style={styles.VolumeControls}>
<VolumeControl type='music'/>
<VolumeControl type='sfx' />'
<VolumeControl type='sfx' />

</div>
</div>
Expand Down
11 changes: 11 additions & 0 deletions js/sceneselect.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ let scenes = [
"musicSource": 'https://www.youtube.com/watch?v=962VmrIh9vQ',
"description" : 'A calm forest with a gentle breeze',
"background" : 'forest1'
},
{
"scene": 'campfire',
"name": 'Campfire',
"video": 'campfire',
"sfx": 'campfire',
"sfxSource": 'https://www.youtube.com/watch?v=O_LJWYzdD4o',
"videoSource": 'https://www.pexels.com/video/bonfire-in-the-woods-2060826/',
"musicSource": 'https://www.youtube.com/watch?v=962VmrIh9vQ',
"description" : 'Waking up to a campfire in the woods.',
"background" : 'campfire'
}
]

Expand Down
236 changes: 236 additions & 0 deletions js/timer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
const containerDOM = document.getElementById('container')
const create = React.createElement

let styles = {

}

class Adjuster extends React.Component{
constructor(props){
super(props)
}

labelText = this.props.type + ' length'

render(){
return(
<div class='adjuster'>
<h6 id={this.props.type+'-label'}>{this.labelText}</h6>
<div class='adjuster_module'>
<a
id={this.props.type+'-decrement'}
class="large waves-effect btn-floating"
onClick={() => {
this.props.adjust(this.props.type+'_length', -1)
}}
>
<Icon id='adjuster_button_up'>keyboard_arrow_down</Icon>
</a>
<div class='adjuster-info'>
<h5 id={this.props.type+'-length'}>{this.props.length}</h5>
</div>
<a
id={this.props.type+'-increment'}
class="large waves-effect btn-floating"
onClick={() => {
this.props.adjust(this.props.type+'_length', 1)
}}
>
<Icon id='adjuster_button_down'>keyboard_arrow_up</Icon>
</a>
</div>

</div>
)
}
}

class Display extends React.Component{
constructor(props){
super(props)
}

render(){
return(
<div id='display'>
<h4 id='timer-label'>{this.props.mode}</h4>
<h2 id='time-left'>{this.props.mins}:{this.props.secs}</h2>
</div>
)
}
}


class MainTimer extends React.Component{
constructor(props){
super(props)
}

interval;

state={
mode: 'Session',
break_length: 5,
session_length: 25,
duration: 25*60,
minutes: '25',
seconds: '00',
status: 'Stopped'
}

startTimer = () => {
let timer = this.state.duration

let minutes = parseInt(timer / 60, 10)
let seconds = parseInt(timer % 60, 10);

minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;

this.setState({
status: 'Running',
minutes: minutes,
seconds: seconds
})

timer = timer - 1

this.interval = setInterval(function () {

if(this.state.status === 'Stopped'){
clearInterval(this.interval)
}

minutes = parseInt(timer / 60, 10)
seconds = parseInt(timer % 60, 10);

minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;

this.setState({
minutes: minutes,
seconds: seconds
})

if (timer === 0) {
document.getElementById('beep').play()
clearInterval(this.interval)
let timerElement = document.querySelector('#appTimer')
if(!timerElement.style.display || timerElement.style.display === 'none'){
timerElement.style.display = 'flex'
}
setTimeout(() => {
if(this.state.mode === 'Session'){
this.startBreak()
}else{
this.startSession()
}
}, 100)
}else{
timer = timer -1
}

}.bind(this), 1000);
}

adjust = (type, value) => {
if(this.state[type] === 1 && value < 0){
return
}

if(this.state[type] === 60 && value >0){
return
}

this.state[type] = this.state[type] + value
this.state.duration = this.state.session_length * 60

let mins = parseInt(this.state.duration / 60, 10)
let secs = parseInt(this.state.duration % 60, 10)

mins= mins < 10 ? "0" + mins : mins
secs = secs < 10 ? "0" + secs : secs

this.setState({
minutes: mins,
seconds: secs
})
}

startSession = () => {
this.setState({
mode: 'Session',
duration: this.state.session_length *60
})
this.startTimer()
this.forceUpdate()
}

startBreak = () => {
this.state.mode = 'Break'
this.state.duration = this.state.break_length * 60
this.forceUpdate()
this.startTimer()
}

reset = () => {
document.getElementById('beep').pause();
document.getElementById('beep').currentTime = 0;
clearInterval(this.interval)
this.setState({
mode: 'Session',
break_length: 5,
session_length: 25,
duration: 25 * 60,
minutes: '25',
seconds: '00',
status: 'Stopped'
})
}

startStop = () => {
if(this.state.status === 'Stopped'){
this.startSession()
}
if(this.state.status === 'Paused'){
this.state.duration = (this.state.minutes * 60) + this.state.seconds
this.startTimer()
}
if(this.state.status === 'Running'){
this.state.status = 'Paused'
clearInterval(this.interval)
}
}

render(){
return(
<div id='appTimer'>
<audio id='beep' ref="audio_tag" src="../sfx/beep.wav"/>
<div id='first'>
<Display mode={this.state.mode} mins={this.state.minutes} secs={this.state.seconds}/>
</div>
<div id='second'>
<a
id='start_stop'
class="large waves-effect btn-floating"
onClick={() => {
this.startStop()
}}
><Icon id='timer_button_start'>play_arrow</Icon></a>
<a
id='reset'
class="large waves-effect btn-floating"
onClick={() => {
this.reset()
}}
><Icon id='timer_button_reset'>restore</Icon></a>
</div>
<div id='third'>
<Adjuster type='session' length={this.state.session_length} adjust={this.adjust}/>
<Adjuster type='break' length={this.state.break_length} adjust={this.adjust}/>
</div>
</div>
)
}
}

Binary file added sfx/beep.wav
Binary file not shown.
Binary file added sfx/campfire.mp3
Binary file not shown.
Loading

0 comments on commit a01a496

Please sign in to comment.