Add break timer, and set length & type on db model (break or pomodoro for now)

This commit is contained in:
Linus Miller 2016-11-10 15:24:16 +01:00
parent 6c51c47e0d
commit 01ed5b6109
5 changed files with 41 additions and 17 deletions

View File

12
assets/less/public.less Normal file
View File

@ -0,0 +1,12 @@
h1 {
text-align: center;
}
.timer {
display: flex;
flex-direction: column;
align-items: center;
> .time {
font-size: 4em;
font-weight: bold;
}
}

View File

@ -6,7 +6,8 @@ export default () => (
<div id="app"> <div id="app">
<main> <main>
<h1>Pomodoro Time!</h1> <h1>Pomodoro Time!</h1>
<Timer /> <Timer type="pomodoro" time={25 * 60 * 1000} />
<Timer type="break" time={5 * 60 * 1000} />
</main> </main>
</div> </div>
); );

View File

@ -1,18 +1,16 @@
import { h, Component } from 'preact'; import { h, Component } from 'preact';
import { bindAll } from 'lowline'; import { startCase, bindAll } from 'lowline';
import timeFilter from '../util/time-filter'; import timeFilter from '../util/time-filter';
const length = 25 * 60 * 1000;
export default class Timer extends Component { export default class Timer extends Component {
constructor() { constructor(props) {
super(); super(props);
this.state = { this.state = {
time: length, time: props.time,
totalTime: length, totalTime: props.time,
startTime: undefined, startTime: undefined,
}; };
@ -28,7 +26,7 @@ export default class Timer extends Component {
startTime: Date.now(), startTime: Date.now(),
}); });
this.interval = setInterval(this.updateTimer.bind(this), 10); this.interval = setInterval(this.updateTimer, 10);
} }
pause() { pause() {
@ -39,8 +37,8 @@ export default class Timer extends Component {
clearInterval(this.interval); clearInterval(this.interval);
this.setState({ this.setState({
time: length, time: this.props.time,
totalTime: length, totalTime: this.props.time,
startTime: undefined, startTime: undefined,
}); });
} }
@ -67,6 +65,8 @@ export default class Timer extends Component {
const data = { const data = {
startTime: this.state.startTime, startTime: this.state.startTime,
endTime: new Date(), endTime: new Date(),
type: this.props.type,
length: this.props.time,
}; };
document.title = 'Pling!'; document.title = 'Pling!';
@ -74,9 +74,11 @@ export default class Timer extends Component {
if (Notification.permission !== 'granted') { if (Notification.permission !== 'granted') {
Notification.requestPermission(); Notification.requestPermission();
} else { } else {
const notification = new Notification('Pomodoro complete!', { const title = this.props.type === 'pomodoro' ? 'Pomodoro Complete!' : 'Break is over!';
const body = this.props.type === 'pomodoro' ? 'Time for a break!' : 'Get back to work!';
const notification = new Notification(title, {
icon: 'https://www.planetnatural.com/wp-content/uploads/2014/03/tomato-supplies.jpg', icon: 'https://www.planetnatural.com/wp-content/uploads/2014/03/tomato-supplies.jpg',
body: 'Time for a break!', body,
}); });
} }
@ -96,14 +98,15 @@ export default class Timer extends Component {
render(props, state) { render(props, state) {
return ( return (
<div class="timer"> <section class="timer">
<h1>{startCase(props.type)}</h1>
<div class="time">{timeFilter(state.time || 0)}</div> <div class="time">{timeFilter(state.time || 0)}</div>
<div class="buttons"> <div class="buttons">
<button onClick={this.start}>Start</button> <button onClick={this.start}>Start</button>
<button>Pause</button> <button onClick={this.reset}>Reset</button>
<button>Reset</button>
</div>
</div> </div>
</section>
); );
} }
} }

View File

@ -11,6 +11,14 @@ const PomodoroSchema = new mongoose.Schema({
type: Date, type: Date,
required: true, required: true,
}, },
type: {
type: String,
required: true,
},
length: {
type: Number,
required: true,
},
name: String, name: String,
location: String, location: String,
user: { user: {