Skip to content

Commit

Permalink
fix(reminderCountdown): not reacting right away to skipped reminders
Browse files Browse the repository at this point in the history
  • Loading branch information
johannesjo committed Feb 1, 2024
1 parent 60a3423 commit b8ef950
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/app/features/reminder/store/reminder-countdown.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { Store } from '@ngrx/store';
import { BannerService } from '../../../core/banner/banner.service';
import { Reminder } from '../reminder.model';
import { selectReminderConfig } from '../../config/store/global-config.reducer';
import { EMPTY, timer } from 'rxjs';
import { BehaviorSubject, combineLatest, EMPTY, timer } from 'rxjs';
import { DataInitService } from '../../../core/data-init/data-init.service';
import { TaskService } from '../../tasks/task.service';
import { Task, TaskWithReminder } from '../../tasks/task.model';
Expand All @@ -40,16 +40,19 @@ export class ReminderCountdownEffects {
concatMap(() => this._store.select(selectReminderConfig)),
switchMap((reminderCfg) =>
reminderCfg.isCountdownBannerEnabled
? this._reminderService.reminders$.pipe(
map((reminders) => {
? combineLatest([
this._reminderService.reminders$,
this._skippedReminderIds$,
]).pipe(
map(([reminders, skippedReminderIds]) => {
const now = Date.now();
return reminders.filter(
(reminder) =>
reminder.type === 'TASK' &&
reminder.remindAt - reminderCfg.countdownDuration < now &&
// reminders due will show as an alert anyway
reminder.remindAt > now &&
!this._skippedReminderIds.includes(reminder.id),
!skippedReminderIds.includes(reminder.id),
);
}),
switchMap((dueReminders) =>
Expand Down Expand Up @@ -82,7 +85,7 @@ export class ReminderCountdownEffects {
},
);

private _skippedReminderIds: string[] = [];
private _skippedReminderIds$ = new BehaviorSubject<string[]>([]);
private _currentBannerReminder?: Reminder;

constructor(
Expand All @@ -98,7 +101,7 @@ export class ReminderCountdownEffects {
) {}

private _skipReminder(reminderId: string): void {
this._skippedReminderIds.push(reminderId);
this._skippedReminderIds$.next([...this._skippedReminderIds$.getValue(), reminderId]);
}

private async _showBanner(
Expand Down

0 comments on commit b8ef950

Please sign in to comment.