Created
December 3, 2019 01:54
-
-
Save maddyonline/939e464efd7d067ed90e1af918632aeb to your computer and use it in GitHub Desktop.
Vue Pomodoro Timer Scotch Challenge Main
This file contains hidden or 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
<!-- our template --> | |
<section id="app" class="hero is-info is-fullheight is-bold"> | |
<div class="hero-body"> | |
<div class="container has-text-centered"> | |
<h2 class="title is-6">{{title}}</h2> | |
<div id="timer"> | |
<span id="minutes">{{ minutes }}</span> | |
<span id="middle">:</span> | |
<span id="seconds">{{ seconds }}</span> | |
</div> | |
<div id="buttons"> | |
<!-- Start TImer --> | |
<button | |
id="start" | |
class="button is-dark is-large" | |
v-if="!timer" | |
@click="startTimer"> | |
<i class="far fa-play-circle"></i> | |
</button> | |
<!-- Pause Timer --> | |
<button | |
id="stop" | |
class="button is-dark is-large" | |
v-if="timer" | |
@click="stopTimer"> | |
<i class="far fa-pause-circle"></i> | |
</button> | |
<!-- Restart Timer --> | |
<button | |
id="reset" | |
class="button is-dark is-large" | |
v-if="resetButton" | |
@click="resetTimer"> | |
<i class="fas fa-undo"></i> | |
</button> | |
</div> | |
</div> | |
</div> | |
</section> |
This file contains hidden or 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
const app = new Vue({ | |
el: '#app', | |
// ======================== | |
data: { | |
timer: null, | |
totalTime: (25 * 60), | |
resetButton: false, | |
title: "Let the countdown begin!!" | |
}, | |
// ======================== | |
methods: { | |
startTimer: function() { | |
this.timer = setInterval(() => this.countdown(), 1000); | |
this.resetButton = true; | |
this.title = "Greatness is within sight!!" | |
}, | |
stopTimer: function() { | |
clearInterval(this.timer); | |
this.timer = null; | |
this.resetButton = true; | |
this.title = "Never quit, keep going!!" | |
}, | |
resetTimer: function() { | |
this.totalTime = (25 * 60); | |
clearInterval(this.timer); | |
this.timer = null; | |
this.resetButton = false; | |
this.title = "Let the countdown begin!!" | |
}, | |
padTime: function(time) { | |
return (time < 10 ? '0' : '') + time; | |
}, | |
countdown: function() { | |
if(this.totalTime >= 1){ | |
this.totalTime--; | |
} else{ | |
this.totalTime = 0; | |
this.resetTimer() | |
} | |
} | |
}, | |
// ======================== | |
computed: { | |
minutes: function() { | |
const minutes = Math.floor(this.totalTime / 60); | |
return this.padTime(minutes); | |
}, | |
seconds: function() { | |
const seconds = this.totalTime - (this.minutes * 60); | |
return this.padTime(seconds); | |
} | |
} | |
}) |
This file contains hidden or 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
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.3/vue.min.js"></script> |
This file contains hidden or 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
#message { | |
color: #DDD; | |
font-size: 50px; | |
margin-bottom: 20px; | |
} | |
#timer { | |
font-size: 200px; | |
line-height: 1; | |
margin-bottom: 40px; | |
} |
This file contains hidden or 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
<link href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.6.1/css/bulma.min.css" rel="stylesheet" /> | |
<link href="https://use.fontawesome.com/releases/v5.0.6/css/all.css" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment