Skip to content

Commit

Permalink
feat: reset Pomodoro when current task is completed
Browse files Browse the repository at this point in the history
  • Loading branch information
bytrangle committed Oct 31, 2023
1 parent 2b305fc commit 74d0efb
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/app/features/tasks/store/task-internal.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@ import {
unsetCurrentTask,
updateTask,
} from './task.actions';
import { stopPomodoro } from '../../pomodoro/store/pomodoro.actions';
import { select, Store } from '@ngrx/store';
import { filter, map, mergeMap, withLatestFrom } from 'rxjs/operators';
import { selectTaskFeatureState } from './task.selectors';
import { filter, map, mapTo, mergeMap, switchMap, withLatestFrom } from 'rxjs/operators';

Check failure on line 13 in src/app/features/tasks/store/task-internal.effects.ts

View workflow job for this annotation

GitHub Actions / test-on-linux

'switchMap' is defined but never used

Check failure on line 13 in src/app/features/tasks/store/task-internal.effects.ts

View workflow job for this annotation

GitHub Actions / test-on-linux

'switchMap' is defined but never used
import { selectCurrentTask, selectTaskFeatureState } from './task.selectors';
import { selectMiscConfig } from '../../config/store/global-config.reducer';
import { Task, TaskState } from '../task.model';
import { EMPTY, of } from 'rxjs';
import { PomodoroService } from '../../pomodoro/pomodoro.service';
import { WorkContextService } from '../../work-context/work-context.service';
import {
moveProjectTaskToBacklogList,
moveProjectTaskToBacklogListAuto,
} from '../../project/store/project.actions';
import { M } from '@angular/cdk/keycodes';

Check failure on line 24 in src/app/features/tasks/store/task-internal.effects.ts

View workflow job for this annotation

GitHub Actions / test-on-linux

'M' is defined but never used

Check failure on line 24 in src/app/features/tasks/store/task-internal.effects.ts

View workflow job for this annotation

GitHub Actions / test-on-linux

'M' is defined but never used

@Injectable()
export class TaskInternalEffects {
Expand Down Expand Up @@ -142,9 +145,28 @@ export class TaskInternalEffects {
),
);

stopPomodoroOnTaskDone$: any = createEffect(() =>
this._actions$.pipe(
ofType(updateTask),
withLatestFrom(this._store$.pipe(select(selectCurrentTask))),
filter(
([
{
task: { changes, id },
},
currentTask,
]) => !!changes.isDone && id === currentTask?.id,
),
withLatestFrom(this._pomodoroService.isEnabled$),
filter(([changes, isEnabled]) => !!isEnabled),
mapTo(stopPomodoro()),
),
);

constructor(
private _actions$: Actions,
private _store$: Store<any>,
private _pomodoroService: PomodoroService,
private _workContextSession: WorkContextService,
) {}

Expand Down

0 comments on commit 74d0efb

Please sign in to comment.