-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
115 additions
and
2 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React from 'react'; | ||
import Actions from '../actions'; | ||
import CountdownStore from '../stores/countdown-store'; | ||
|
||
let countdownTimer; | ||
|
||
class Countdown extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
timeLeft: null | ||
}; | ||
} | ||
|
||
componentDidMount() { | ||
CountdownStore.addChangeListener(this.updateCountdown.bind(this)); | ||
} | ||
|
||
updateCountdown() { | ||
this.setState({ timeLeft: CountdownStore.getTimeLeft() }) | ||
} | ||
|
||
render() { | ||
return ( | ||
<div className='countdown'>{this.state.timeLeft}</div> | ||
); | ||
} | ||
} | ||
|
||
export default Countdown; |
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import AppDispatcher from '../app-dispatcher.js'; | ||
import BaseStore from './base-store.js'; | ||
|
||
const TIMEOUT_LENGTH = 3; | ||
|
||
let timeLeft; | ||
let timer; | ||
|
||
class _CountdownStore extends BaseStore { | ||
getTimeLeft() { | ||
return timeLeft; | ||
} | ||
} | ||
|
||
const CountdownStore = new _CountdownStore(); | ||
|
||
let initiateCountdown = () => { | ||
clearTimeout(timer); | ||
timeLeft = TIMEOUT_LENGTH; | ||
|
||
timer = setInterval(() => { | ||
timeLeft = timeLeft - 1; | ||
|
||
if (timeLeft == 0) { | ||
clearTimeout(timer); | ||
CountdownStore.emitChange(); | ||
timeLeft = null; | ||
} | ||
|
||
CountdownStore.emitChange(); | ||
}, 1000); | ||
} | ||
|
||
AppDispatcher.register((payload) => { | ||
switch(payload.type) { | ||
case 'initiate-countdown': | ||
initiateCountdown(); | ||
CountdownStore.emitChange(); | ||
break; | ||
default: | ||
break; | ||
} | ||
return true; | ||
}); | ||
|
||
export default CountdownStore; |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.countdown { | ||
font-size: 48px; | ||
} |
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,2 +1,3 @@ | ||
@import 'countdown'; | ||
@import 'snapshot-list'; | ||
@import 'video'; |