Skip to content

Commit

Permalink
feat(pomodoro): prevent timer resetting itself on play #32
Browse files Browse the repository at this point in the history
  • Loading branch information
johannesjo committed Jan 5, 2018
1 parent 47f30d6 commit 92147d0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
2 changes: 1 addition & 1 deletion app-src/scripts/pomodoro-button/_pomodoro-button-cp.scss
Expand Up @@ -34,7 +34,7 @@ pomodoro-button {
color: #333333;
background: #ffffff;
margin-bottom: -4px;
padding: 1px 2px;
padding: 1px 4px;
z-index: 10;
}

Expand Down
5 changes: 2 additions & 3 deletions app-src/scripts/pomodoro-button/pomodoro-button-cp.html
Expand Up @@ -14,7 +14,7 @@
<ng-md-icon icon="free_breakfast"
ng-if="$ctrl.svc.data.isOnBreak && $ctrl.svc.data.status!=='MANUAL_PAUSE'"></ng-md-icon>
<span class="timer-btn-text"
md-whiteframe="1"
md-whiteframe="2"
ng-bind="($ctrl.svc.data.currentSessionTime | date:'mm:ss')"></span>
</md-button>
</md-fab-trigger>
Expand All @@ -33,8 +33,7 @@
</md-button>
<md-button class="md-fab md-raised md-mini"
ng-click="$ctrl.stop($event)"
aria-label="Stop Pomodoro Session"
ng-if="$ctrl.svc.data.status==='PLAY'">
aria-label="Stop Pomodoro Session">
<ng-md-icon icon="stop"></ng-md-icon>
</md-button>
</md-fab-actions>
Expand Down
30 changes: 14 additions & 16 deletions app-src/scripts/pomodoro-button/pomodoro-button-s.js
Expand Up @@ -16,10 +16,11 @@

class PomodoroButton {
/* @ngInject */
constructor($rootScope, $interval, Dialogs, Tasks, SimpleToast, LS_DEFAULTS, EV) {
constructor($rootScope, $interval, $q, Dialogs, Tasks, SimpleToast, LS_DEFAULTS, EV) {
this.$rootScope = $rootScope;
this.EV = EV;
this.$interval = $interval;
this.$q = $q;
this.Dialogs = Dialogs;
this.SimpleToast = SimpleToast;
this.Tasks = Tasks;
Expand Down Expand Up @@ -75,16 +76,14 @@

play() {
// select task if none selected
this.selectTask(this.start);
this.selectTask()
.then(() => {
this.start();
});
}

start() {
if (this.data.status !== MANUAL_PAUSE) {
this.setSessionTimerTime();
}

this.initTimer();
// import that the status is set afterwards
this.data.status = PLAY;
}

Expand Down Expand Up @@ -175,26 +174,25 @@
return (this.data.isOnBreak && (this.data.currentCycle % this.config.cyclesBeforeLongerBreak !== 0));
}

selectTask(cb) {
const execCbIfGiven = () => {
if (cb) {
cb.apply(this);
}
};
selectTask() {
const defer = this.$q.defer();

if (!this.Tasks.getCurrent()) {
const lastCurrentTask = this.Tasks.getLastCurrent();

if (lastCurrentTask) {
this.Tasks.updateCurrent(lastCurrentTask);
execCbIfGiven();
defer.resolve();
} else {
this.Dialogs('TASK_SELECTION')
.then(execCbIfGiven);
.then(defer.resolve)
.catch(defer.reject);
}
} else {
execCbIfGiven();
defer.resolve();
}

return defer.promise;
}

playSessionDoneSound() {
Expand Down

0 comments on commit 92147d0

Please sign in to comment.