feat(reminders): add persistence

This commit is contained in:
Johannes Millan 2018-11-25 20:14:05 +01:00
parent 56cab041e1
commit 44a2b00905
4 changed files with 21 additions and 5 deletions

View file

@ -6,6 +6,7 @@ export const LS_GLOBAL_CFG = LS_PREFIX + 'GLOBAL_CFG';
export const LS_BACKUP = LS_PREFIX + 'COMPLETE_BACKUP';
export const LS_LAST_ACTIVE = LS_PREFIX + 'LAST_ACTIVE';
export const LS_LAYOUT = LS_PREFIX + 'LAYOUT';
export const LS_REMINDER = LS_PREFIX + 'REMINDER';
export const LS_PROJECT_META_LIST = LS_PREFIX + 'PROJECT_META_LIST';
export const LS_PROJECT_CFG: ProjectDataLsKey = 'CFG';

View file

@ -8,6 +8,7 @@ import {
LS_NOTE_STATE,
LS_PROJECT_META_LIST,
LS_PROJECT_PREFIX,
LS_REMINDER,
LS_TASK_ARCHIVE,
LS_TASK_ATTACHMENT_STATE,
LS_TASK_STATE
@ -24,6 +25,7 @@ import { AppDataComplete } from '../sync/sync.model';
import { BookmarkState } from '../../bookmark/store/bookmark.reducer';
import { AttachmentState } from '../../tasks/attachment/store/attachment.reducer';
import { NoteState } from '../../note/store/note.reducer';
import { Reminder } from '../../reminder/reminder.model';
@Injectable({
providedIn: 'root'
@ -42,6 +44,14 @@ export class PersistenceService {
saveToLsWithLastActive(LS_PROJECT_META_LIST, projectData);
}
loadReminders(): Reminder[] {
return loadFromLs(LS_REMINDER);
}
saveReminders(reminders: Reminder[]) {
saveToLsWithLastActive(LS_REMINDER, reminders);
}
saveTasksForProject(projectId, taskState: TaskState) {
saveToLsWithLastActive(this._makeProjectKey(projectId, LS_TASK_STATE), taskState);
}

View file

@ -1,7 +1,6 @@
<form (submit)="save()">
<mat-dialog-content>
<h2 class="mat-h2">{{isEdit ? 'Edit' : 'Add'}} reminder
reminder for note</h2>
<h2 class="mat-h2">{{isEdit ? 'Edit' : 'Add'}} reminder for note</h2>
<mat-form-field>
<!--[matDatepicker]="myDatepicker"-->

View file

@ -52,17 +52,20 @@ export class ReminderService {
});
// this._persistenceService
this._updateRemindersInWorker(this._reminders);
this._saveToLS(this._reminders);
console.log(this._reminders);
return id;
}
updateReminder(reminderChanges: Partial<Reminder>) {
updateReminder(reminderId: string, reminderChanges: Partial<Reminder>) {
this._saveToLS(this._reminders);
}
removeReminder(reminderIdToRemove: string) {
const i = this._reminders.findIndex(reminder => reminder.id === reminderIdToRemove);
if (i > -1) {
this._reminders.splice(i, 1);
this._saveToLS(this._reminders);
} else {
throw new Error('Unable to find reminder with id ' + reminderIdToRemove);
}
@ -82,8 +85,11 @@ export class ReminderService {
}
private _loadFromLs(): Reminder[] {
// this._persistenceService.
return [];
return this._persistenceService.loadReminders() || [];
}
private _saveToLS(reminders: Reminder[]) {
this._persistenceService.saveReminders(reminders);
}
private _updateRemindersInWorker(reminders: Reminder[]) {