From c2b112834e5a678f60288b6cbe25068b21701d1b Mon Sep 17 00:00:00 2001 From: hyunmoahn Date: Thu, 25 Oct 2018 06:03:03 +0900 Subject: [PATCH 1/4] Add class for manage timer --- app/page/timer.js | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/app/page/timer.js b/app/page/timer.js index 2240cd9..c20aabb 100644 --- a/app/page/timer.js +++ b/app/page/timer.js @@ -1,7 +1,35 @@ import { remote } from 'electron'; -function setTimer() { - return `
Set!!
` +/** + * Manager data of timer. + */ +class Timer { + constructor(time) { + this.time = time; + this.remain = this.time; + this.tick = null; + } + + setTime(num) { + this.time = num; + this.remain = num; + } + + getRemainTime() { + return this.remain; + } + + runTimeProgress(cb) { + this.tick = setInterval(() => { + this.remain -= 1; + cb(); + }, 1000); + } + + stopTimeProgress() { + clearInterval(this.tick); + this.tick = null; + } } function countTimer() { From f522be22500f7475ccff4d14edb343ecc1324cf3 Mon Sep 17 00:00:00 2001 From: hyunmoahn Date: Thu, 25 Oct 2018 06:05:01 +0900 Subject: [PATCH 2/4] Add function to draw DOM. --- app/page/timer.js | 63 ++++++++++++++++++++++++++++++++++++++++++++--- package.json | 1 + yarn.lock | 4 +++ 3 files changed, 65 insertions(+), 3 deletions(-) diff --git a/app/page/timer.js b/app/page/timer.js index c20aabb..a81127c 100644 --- a/app/page/timer.js +++ b/app/page/timer.js @@ -1,4 +1,4 @@ -import { remote } from 'electron'; +import cx from 'classnames'; /** * Manager data of timer. @@ -32,8 +32,65 @@ class Timer { } } -function countTimer() { - return `
Count
` +/** + * Update DOM about progress count. + * @param(Number) time: number of remain timer + */ +function renderProgressView(time) { + function progressView(number) { + const hour = parseInt(number / 3600); + const minute = parseInt((number - hour * 60) / 60); + const second = number % 60; + + const hourClassName = cx('Progress__hour', { 'Progress__hour--hide': hour === 0 }); + const minuteClassName = cx('Progress__minute', { 'Progress__minute--hide': minute === 0 && hour === 0 }); + const secondClassName = cx('Progress__second'); + + return ` +
+ ${hour} + ${minute} + ${second} +
+ `; + } + + const timerRoot = document.getElementById('timer-root'); + + timerRoot.innerHTML = progressView(time); +} + +/** + * Update DOM about setting count. + * @param(Number) time: number of set timer + */ +function settingView(number) { + const hour = parseInt(number / 3600); + const minute = parseInt((number - hour * 60) / 60); + const second = number % 60; + + return ` +
+ + : + + : + + +
+ `; +} + +/** + * DOM about comment for alert when time is zero. + * @returns {string} + */ +function commentView() { + return ` +
+ +
+ `; } function init() { diff --git a/package.json b/package.json index 12fd3a0..2724fd8 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "start": "NODE_ENV=development webpack-dev-server --hot --inline --watch" }, "dependencies": { + "classnames": "^2.2.6", "electron": "^3.0.4", "menubar": "^5.2.3" }, diff --git a/yarn.lock b/yarn.lock index a20ea69..905986e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1189,6 +1189,10 @@ class-utils@^0.3.5: isobject "^3.0.0" static-extend "^0.1.1" +classnames@^2.2.6: + version "2.2.6" + resolved "https://registry.yarnpkg.com/classnames/-/classnames-2.2.6.tgz#43935bffdd291f326dad0a205309b38d00f650ce" + clean-css@4.2.x: version "4.2.1" resolved "https://registry.yarnpkg.com/clean-css/-/clean-css-4.2.1.tgz#2d411ef76b8569b6d0c84068dabe85b0aa5e5c17" From dbfe21fd071fb5544625c75d89030dc81efe6dd2 Mon Sep 17 00:00:00 2001 From: hyunmoahn Date: Thu, 25 Oct 2018 06:05:34 +0900 Subject: [PATCH 3/4] Add managing function about DOM and event. --- app/page/timer.html | 3 +- app/page/timer.js | 74 +++++++++++++++++++++++++++++++++++++++++++-- package.json | 3 +- yarn.lock | 4 +++ 4 files changed, 79 insertions(+), 5 deletions(-) diff --git a/app/page/timer.html b/app/page/timer.html index dba4bae..d3fb98f 100644 --- a/app/page/timer.html +++ b/app/page/timer.html @@ -8,7 +8,8 @@ Timer -
+
+