From 662d24e641b73ed56324739f2cdb57d3e03c8bc8 Mon Sep 17 00:00:00 2001 From: Johannes Millan Date: Thu, 22 Jul 2021 13:23:51 +0200 Subject: [PATCH] refactor(localSync): make app models work inside electron context #690 --- src/app/core/data-init/data-init.service.ts | 2 +- .../core/data-repair/data-repair.util.spec.ts | 3 +- src/app/core/migration/legacy-models.ts | 6 ++-- .../migration/legacy-persistence.sevice.ts | 8 ++--- src/app/core/migration/migration.service.ts | 3 +- .../persistence/persistence.service.spec.ts | 3 +- .../core/persistence/persistence.service.ts | 15 +++----- src/app/features/bookmark/bookmark.model.ts | 6 ++++ src/app/features/bookmark/bookmark.service.ts | 3 +- .../bookmark/store/bookmark.actions.ts | 3 +- .../bookmark/store/bookmark.effects.ts | 3 +- .../bookmark/store/bookmark.reducer.ts | 9 ++--- src/app/features/note/note.model.ts | 4 +++ src/app/features/note/note.service.ts | 9 ++--- src/app/features/note/store/note.actions.ts | 3 +- src/app/features/note/store/note.effects.ts | 3 +- src/app/features/note/store/note.reducer.ts | 6 ++-- .../project/migrate-projects-state.util.ts | 3 +- .../features/project/project-archive.model.ts | 4 +-- src/app/features/project/project.model.ts | 6 ++++ .../features/project/store/project.reducer.ts | 8 ++--- src/app/imex/sync/sync.const.ts | 31 ++++++++++++++++ src/app/imex/sync/sync.model.ts | 36 ++----------------- src/app/root-store/root-state.ts | 15 ++++---- 24 files changed, 90 insertions(+), 102 deletions(-) diff --git a/src/app/core/data-init/data-init.service.ts b/src/app/core/data-init/data-init.service.ts index baf3150bfc3..87cb4a78d7c 100644 --- a/src/app/core/data-init/data-init.service.ts +++ b/src/app/core/data-init/data-init.service.ts @@ -6,11 +6,11 @@ import { WorkContextService } from '../../features/work-context/work-context.ser import { Store } from '@ngrx/store'; import { allDataWasLoaded } from '../../root-store/meta/all-data-was-loaded.actions'; import { PersistenceService } from '../persistence/persistence.service'; -import { ProjectState } from '../../features/project/store/project.reducer'; import { MigrationService } from '../migration/migration.service'; import { loadAllData } from '../../root-store/meta/load-all-data.action'; import { isValidAppData } from '../../imex/sync/is-valid-app-data.util'; import { DataRepairService } from '../data-repair/data-repair.service'; +import { ProjectState } from '../../features/project/project.model'; @Injectable({ providedIn: 'root' }) export class DataInitService { diff --git a/src/app/core/data-repair/data-repair.util.spec.ts b/src/app/core/data-repair/data-repair.util.spec.ts index 75ea08513dd..95d97f51197 100644 --- a/src/app/core/data-repair/data-repair.util.spec.ts +++ b/src/app/core/data-repair/data-repair.util.spec.ts @@ -5,8 +5,7 @@ import { fakeEntityStateFromArray } from '../../util/fake-entity-state-from-arra import { DEFAULT_TASK, Task } from '../../features/tasks/task.model'; import { createEmptyEntity } from '../../util/create-empty-entity'; import { Tag, TagState } from '../../features/tag/tag.model'; -import { ProjectState } from '../../features/project/store/project.reducer'; -import { Project } from '../../features/project/project.model'; +import { Project, ProjectState } from '../../features/project/project.model'; import { DEFAULT_PROJECT } from '../../features/project/project.const'; import { DEFAULT_TAG, TODAY_TAG } from '../../features/tag/tag.const'; diff --git a/src/app/core/migration/legacy-models.ts b/src/app/core/migration/legacy-models.ts index 6ff16ccd1d8..a5e8fae2fba 100644 --- a/src/app/core/migration/legacy-models.ts +++ b/src/app/core/migration/legacy-models.ts @@ -1,8 +1,5 @@ -import { ProjectState } from '../../features/project/store/project.reducer'; import { GlobalConfigState } from '../../features/config/global-config.model'; import { TaskArchive, TaskState } from '../../features/tasks/task.model'; -import { BookmarkState } from '../../features/bookmark/store/bookmark.reducer'; -import { NoteState } from '../../features/note/store/note.reducer'; import { Reminder } from '../../features/reminder/reminder.model'; import { MetricState } from '../../features/metric/metric.model'; import { ImprovementState } from '../../features/metric/improvement/improvement.model'; @@ -11,6 +8,9 @@ import { TaskRepeatCfgState } from '../../features/task-repeat-cfg/task-repeat-c import { EntityState } from '@ngrx/entity'; import { TaskAttachment } from '../../features/tasks/task-attachment/task-attachment.model'; import { ProjectArchive } from '../../features/project/project-archive.model'; +import { ProjectState } from '../../features/project/project.model'; +import { BookmarkState } from '../../features/bookmark/bookmark.model'; +import { NoteState } from '../../features/note/note.model'; export interface LegacyAppBaseData { project: ProjectState; diff --git a/src/app/core/migration/legacy-persistence.sevice.ts b/src/app/core/migration/legacy-persistence.sevice.ts index 66fb04a0d94..c95f7a79282 100644 --- a/src/app/core/migration/legacy-persistence.sevice.ts +++ b/src/app/core/migration/legacy-persistence.sevice.ts @@ -1,4 +1,3 @@ -import { ProjectState } from '../../features/project/store/project.reducer'; import { LS_BOOKMARK_STATE, LS_GLOBAL_CFG, @@ -40,10 +39,8 @@ import { LegacyPersistenceBaseModel, LegacyPersistenceForProjectModel, } from './legacy-models'; -import { BookmarkState } from '../../features/bookmark/store/bookmark.reducer'; -import { Bookmark } from '../../features/bookmark/bookmark.model'; -import { NoteState } from '../../features/note/store/note.reducer'; -import { Note } from '../../features/note/note.model'; +import { Bookmark, BookmarkState } from '../../features/bookmark/bookmark.model'; +import { Note, NoteState } from '../../features/note/note.model'; import { Metric, MetricState } from '../../features/metric/metric.model'; import { Improvement, @@ -57,6 +54,7 @@ import { DatabaseService } from '../persistence/database.service'; import { DEFAULT_PROJECT_ID } from '../../features/project/project.const'; import { Action } from '@ngrx/store'; import { Injectable } from '@angular/core'; +import { ProjectState } from '../../features/project/project.model'; @Injectable({ providedIn: 'root', diff --git a/src/app/core/migration/migration.service.ts b/src/app/core/migration/migration.service.ts index 4110276850e..21e3fe970c4 100644 --- a/src/app/core/migration/migration.service.ts +++ b/src/app/core/migration/migration.service.ts @@ -1,6 +1,5 @@ import { Injectable } from '@angular/core'; import { PersistenceService } from '../persistence/persistence.service'; -import { ProjectState } from '../../features/project/store/project.reducer'; import { EMPTY, from, Observable, of } from 'rxjs'; import { TaskArchive, TaskState } from 'src/app/features/tasks/task.model'; import { Dictionary, EntityState } from '@ngrx/entity'; @@ -14,7 +13,7 @@ import { LegacyPersistenceService } from './legacy-persistence.sevice'; import { AppDataComplete } from '../../imex/sync/sync.model'; import { initialTaskState } from '../../features/tasks/store/task.reducer'; import { initialTagState } from '../../features/tag/store/tag.reducer'; -import { Project } from '../../features/project/project.model'; +import { Project, ProjectState } from '../../features/project/project.model'; import { concatMap, map } from 'rxjs/operators'; import { migrateTaskState } from '../../features/tasks/migrate-task-state.util'; import { initialSimpleCounterState } from '../../features/simple-counter/store/simple-counter.reducer'; diff --git a/src/app/core/persistence/persistence.service.spec.ts b/src/app/core/persistence/persistence.service.spec.ts index 0d067bbe5b6..76c865c1f82 100644 --- a/src/app/core/persistence/persistence.service.spec.ts +++ b/src/app/core/persistence/persistence.service.spec.ts @@ -7,8 +7,9 @@ import { TestScheduler } from 'rxjs/testing'; import { of } from 'rxjs'; import { createEmptyEntity } from '../../util/create-empty-entity'; import { provideMockStore } from '@ngrx/store/testing'; -import { AppDataComplete, DEFAULT_APP_BASE_DATA } from '../../imex/sync/sync.model'; +import { AppDataComplete } from '../../imex/sync/sync.model'; import { skip } from 'rxjs/operators'; +import { DEFAULT_APP_BASE_DATA } from '../../imex/sync/sync.const'; const testScheduler = new TestScheduler((actual, expected) => { // asserting the two objects are equal diff --git a/src/app/core/persistence/persistence.service.ts b/src/app/core/persistence/persistence.service.ts index 92436824076..5172c529b63 100644 --- a/src/app/core/persistence/persistence.service.ts +++ b/src/app/core/persistence/persistence.service.ts @@ -20,10 +20,7 @@ import { LS_TASK_STATE, } from './ls-keys.const'; import { GlobalConfigState } from '../../features/config/global-config.model'; -import { - projectReducer, - ProjectState, -} from '../../features/project/store/project.reducer'; +import { projectReducer } from '../../features/project/store/project.reducer'; import { ArchiveTask, Task, @@ -35,10 +32,7 @@ import { AppDataComplete, AppDataCompleteOptionalSyncModelChange, AppDataForProjects, - DEFAULT_APP_BASE_DATA, } from '../../imex/sync/sync.model'; -import { BookmarkState } from '../../features/bookmark/store/bookmark.reducer'; -import { NoteState } from '../../features/note/store/note.reducer'; import { Reminder } from '../../features/reminder/reminder.model'; import { DatabaseService } from './database.service'; import { DEFAULT_PROJECT_ID } from '../../features/project/project.const'; @@ -47,7 +41,7 @@ import { ProjectArchive, ProjectArchivedRelatedData, } from '../../features/project/project-archive.model'; -import { Project } from '../../features/project/project.model'; +import { Project, ProjectState } from '../../features/project/project.model'; import { CompressionService } from '../compression/compression.service'; import { PersistenceBaseEntityModel, @@ -67,8 +61,8 @@ import { TaskRepeatCfg, TaskRepeatCfgState, } from '../../features/task-repeat-cfg/task-repeat-cfg.model'; -import { Bookmark } from '../../features/bookmark/bookmark.model'; -import { Note } from '../../features/note/note.model'; +import { Bookmark, BookmarkState } from '../../features/bookmark/bookmark.model'; +import { Note, NoteState } from '../../features/note/note.model'; import { Action, Store } from '@ngrx/store'; import { taskRepeatCfgReducer } from '../../features/task-repeat-cfg/store/task-repeat-cfg.reducer'; import { Tag, TagState } from '../../features/tag/tag.model'; @@ -102,6 +96,7 @@ import { migrateMetricState, migrateObstructionState, } from '../../features/metric/migrate-metric-states.util'; +import { DEFAULT_APP_BASE_DATA } from '../../imex/sync/sync.const'; @Injectable({ providedIn: 'root', diff --git a/src/app/features/bookmark/bookmark.model.ts b/src/app/features/bookmark/bookmark.model.ts index f2318e933d0..d5a2a4384e3 100644 --- a/src/app/features/bookmark/bookmark.model.ts +++ b/src/app/features/bookmark/bookmark.model.ts @@ -2,6 +2,7 @@ import { DropPasteInput, DropPasteInputType, } from '../../core/drop-paste-input/drop-paste.model'; +import { EntityState } from '@ngrx/entity'; export type BookmarkType = DropPasteInputType; @@ -10,3 +11,8 @@ export interface BookmarkCopy extends DropPasteInput { } export type Bookmark = Readonly; + +export interface BookmarkState extends EntityState { + // additional entities state properties + isShowBookmarks: boolean; +} diff --git a/src/app/features/bookmark/bookmark.service.ts b/src/app/features/bookmark/bookmark.service.ts index 53cce536d97..474dff74fce 100644 --- a/src/app/features/bookmark/bookmark.service.ts +++ b/src/app/features/bookmark/bookmark.service.ts @@ -1,7 +1,6 @@ import { Injectable } from '@angular/core'; import { select, Store } from '@ngrx/store'; import { - BookmarkState, initialBookmarkState, selectAllBookmarks, selectIsShowBookmarkBar, @@ -17,7 +16,7 @@ import { UpdateBookmark, } from './store/bookmark.actions'; import { Observable } from 'rxjs'; -import { Bookmark } from './bookmark.model'; +import { Bookmark, BookmarkState } from './bookmark.model'; import * as shortid from 'shortid'; import { DialogEditBookmarkComponent } from './dialog-edit-bookmark/dialog-edit-bookmark.component'; import { MatDialog } from '@angular/material/dialog'; diff --git a/src/app/features/bookmark/store/bookmark.actions.ts b/src/app/features/bookmark/store/bookmark.actions.ts index c4e9b5d425b..efc9e3db5ea 100644 --- a/src/app/features/bookmark/store/bookmark.actions.ts +++ b/src/app/features/bookmark/store/bookmark.actions.ts @@ -1,7 +1,6 @@ import { Action } from '@ngrx/store'; import { Update } from '@ngrx/entity'; -import { Bookmark } from '../bookmark.model'; -import { BookmarkState } from './bookmark.reducer'; +import { Bookmark, BookmarkState } from '../bookmark.model'; export enum BookmarkActionTypes { 'LoadBookmarkState' = '[Bookmark] Load Bookmark State', diff --git a/src/app/features/bookmark/store/bookmark.effects.ts b/src/app/features/bookmark/store/bookmark.effects.ts index 93cbe7c5cc8..f0371ba199a 100644 --- a/src/app/features/bookmark/store/bookmark.effects.ts +++ b/src/app/features/bookmark/store/bookmark.effects.ts @@ -3,10 +3,11 @@ import { Actions, Effect, ofType } from '@ngrx/effects'; import { first, switchMap, tap } from 'rxjs/operators'; import { select, Store } from '@ngrx/store'; import { BookmarkActionTypes } from './bookmark.actions'; -import { BookmarkState, selectBookmarkFeatureState } from './bookmark.reducer'; +import { selectBookmarkFeatureState } from './bookmark.reducer'; import { PersistenceService } from '../../../core/persistence/persistence.service'; import { combineLatest, Observable } from 'rxjs'; import { WorkContextService } from '../../work-context/work-context.service'; +import { BookmarkState } from '../bookmark.model'; @Injectable() export class BookmarkEffects { diff --git a/src/app/features/bookmark/store/bookmark.reducer.ts b/src/app/features/bookmark/store/bookmark.reducer.ts index 3d18f164ad3..1978062a138 100644 --- a/src/app/features/bookmark/store/bookmark.reducer.ts +++ b/src/app/features/bookmark/store/bookmark.reducer.ts @@ -1,4 +1,4 @@ -import { createEntityAdapter, EntityAdapter, EntityState } from '@ngrx/entity'; +import { createEntityAdapter, EntityAdapter } from '@ngrx/entity'; import { AddBookmark, BookmarkActions, @@ -8,16 +8,11 @@ import { ReorderBookmarks, UpdateBookmark, } from './bookmark.actions'; -import { Bookmark } from '../bookmark.model'; +import { Bookmark, BookmarkState } from '../bookmark.model'; import { createFeatureSelector, createSelector } from '@ngrx/store'; export const BOOKMARK_FEATURE_NAME = 'bookmark'; -export interface BookmarkState extends EntityState { - // additional entities state properties - isShowBookmarks: boolean; -} - export const adapter: EntityAdapter = createEntityAdapter(); export const selectBookmarkFeatureState = createFeatureSelector(BOOKMARK_FEATURE_NAME); diff --git a/src/app/features/note/note.model.ts b/src/app/features/note/note.model.ts index a5e141fb41a..7486ab4e805 100644 --- a/src/app/features/note/note.model.ts +++ b/src/app/features/note/note.model.ts @@ -1,3 +1,5 @@ +import { EntityState } from '@ngrx/entity'; + export interface Note { id: string; content: string; @@ -7,3 +9,5 @@ export interface Note { created: number; modified: number; } + +export type NoteState = EntityState; diff --git a/src/app/features/note/note.service.ts b/src/app/features/note/note.service.ts index 0819f4c716c..7f7870fe31f 100644 --- a/src/app/features/note/note.service.ts +++ b/src/app/features/note/note.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; -import { Note } from './note.model'; +import { Note, NoteState } from './note.model'; import { select, Store } from '@ngrx/store'; import { addNote, @@ -10,12 +10,7 @@ import { updateNoteOrder, } from './store/note.actions'; import * as shortid from 'shortid'; -import { - initialNoteState, - NoteState, - selectAllNotes, - selectNoteById, -} from './store/note.reducer'; +import { initialNoteState, selectAllNotes, selectNoteById } from './store/note.reducer'; import { PersistenceService } from '../../core/persistence/persistence.service'; import { take } from 'rxjs/operators'; import { createFromDrop } from '../../core/drop-paste-input/drop-paste-input'; diff --git a/src/app/features/note/store/note.actions.ts b/src/app/features/note/store/note.actions.ts index 8cc31c7b21c..9a3bb5ed020 100644 --- a/src/app/features/note/store/note.actions.ts +++ b/src/app/features/note/store/note.actions.ts @@ -1,7 +1,6 @@ import { createAction, props } from '@ngrx/store'; import { Update } from '@ngrx/entity'; -import { Note } from '../note.model'; -import { NoteState } from './note.reducer'; +import { Note, NoteState } from '../note.model'; export const loadNoteState = createAction( '[Note] Load Note State', diff --git a/src/app/features/note/store/note.effects.ts b/src/app/features/note/store/note.effects.ts index e59dc0350b1..729032c4396 100644 --- a/src/app/features/note/store/note.effects.ts +++ b/src/app/features/note/store/note.effects.ts @@ -4,9 +4,10 @@ import { PersistenceService } from '../../../core/persistence/persistence.servic import { select, Store } from '@ngrx/store'; import { first, switchMap, tap } from 'rxjs/operators'; import { addNote, deleteNote, updateNote, updateNoteOrder } from './note.actions'; -import { NoteState, selectNoteFeatureState } from './note.reducer'; +import { selectNoteFeatureState } from './note.reducer'; import { WorkContextService } from '../../work-context/work-context.service'; import { combineLatest, Observable } from 'rxjs'; +import { NoteState } from '../note.model'; @Injectable() export class NoteEffects { diff --git a/src/app/features/note/store/note.reducer.ts b/src/app/features/note/store/note.reducer.ts index 0b0cd149f41..8fa315c7680 100644 --- a/src/app/features/note/store/note.reducer.ts +++ b/src/app/features/note/store/note.reducer.ts @@ -1,5 +1,5 @@ -import { createEntityAdapter, EntityAdapter, EntityState } from '@ngrx/entity'; -import { Note } from '../note.model'; +import { createEntityAdapter, EntityAdapter } from '@ngrx/entity'; +import { Note, NoteState } from '../note.model'; import { addNote, addNotes, @@ -21,8 +21,6 @@ import { on, } from '@ngrx/store'; -export type NoteState = EntityState; - export const adapter: EntityAdapter = createEntityAdapter(); export const initialNoteState: NoteState = adapter.getInitialState({}); diff --git a/src/app/features/project/migrate-projects-state.util.ts b/src/app/features/project/migrate-projects-state.util.ts index b9cb2195a86..8f984833cab 100644 --- a/src/app/features/project/migrate-projects-state.util.ts +++ b/src/app/features/project/migrate-projects-state.util.ts @@ -1,6 +1,5 @@ -import { ProjectState } from './store/project.reducer'; import { Dictionary } from '@ngrx/entity'; -import { Project } from './project.model'; +import { Project, ProjectState } from './project.model'; import { DEFAULT_PROJECT, PROJECT_MODEL_VERSION } from './project.const'; import { DEFAULT_ISSUE_PROVIDER_CFGS } from '../issue/issue.const'; import { diff --git a/src/app/features/project/project-archive.model.ts b/src/app/features/project/project-archive.model.ts index cdb8a706d3c..968bafde9f7 100644 --- a/src/app/features/project/project-archive.model.ts +++ b/src/app/features/project/project-archive.model.ts @@ -1,5 +1,3 @@ -import { NoteState } from '../note/store/note.reducer'; -import { BookmarkState } from '../bookmark/store/bookmark.reducer'; import { Task, TaskState } from '../tasks/task.model'; import { EntityState } from '@ngrx/entity'; import { TaskAttachment } from '../tasks/task-attachment/task-attachment.model'; @@ -8,6 +6,8 @@ import { MetricState } from '../metric/metric.model'; import { ImprovementState } from '../metric/improvement/improvement.model'; import { ObstructionState } from '../metric/obstruction/obstruction.model'; import { Project } from './project.model'; +import { BookmarkState } from '../bookmark/bookmark.model'; +import { NoteState } from '../note/note.model'; export interface ProjectArchivedRelatedData { note?: NoteState; diff --git a/src/app/features/project/project.model.ts b/src/app/features/project/project.model.ts index b37eb132e1e..a7e1a15f230 100644 --- a/src/app/features/project/project.model.ts +++ b/src/app/features/project/project.model.ts @@ -3,6 +3,8 @@ import { WorkContextAdvancedCfgKey, WorkContextCommon, } from '../work-context/work-context.model'; +import { EntityState } from '@ngrx/entity'; +import { MODEL_VERSION_KEY } from '../../app.constants'; export type RoundTimeOption = '5M' | 'QUARTER' | 'HALF' | 'HOUR' | null; @@ -32,3 +34,7 @@ export type ProjectCfgFormKey = | IssueProviderKey | 'basic' | 'theme'; + +export interface ProjectState extends EntityState { + [MODEL_VERSION_KEY]?: number; +} diff --git a/src/app/features/project/store/project.reducer.ts b/src/app/features/project/store/project.reducer.ts index b6a4b4bcee7..99d4f3818a8 100644 --- a/src/app/features/project/store/project.reducer.ts +++ b/src/app/features/project/store/project.reducer.ts @@ -1,5 +1,5 @@ -import { createEntityAdapter, EntityAdapter, EntityState, Update } from '@ngrx/entity'; -import { Project } from '../project.model'; +import { createEntityAdapter, EntityAdapter, Update } from '@ngrx/entity'; +import { Project, ProjectState } from '../project.model'; import { ProjectActions, ProjectActionTypes } from './project.actions'; import { createFeatureSelector, createSelector } from '@ngrx/store'; import { FIRST_PROJECT, PROJECT_MODEL_VERSION } from '../project.const'; @@ -58,10 +58,6 @@ import { CaldavCfg } from '../../issue/providers/caldav/caldav.model'; export const PROJECT_FEATURE_NAME = 'projects'; const WORK_CONTEXT_TYPE: WorkContextType = WorkContextType.PROJECT; -export interface ProjectState extends EntityState { - [MODEL_VERSION_KEY]?: number; -} - export const projectAdapter: EntityAdapter = createEntityAdapter(); // SELECTORS diff --git a/src/app/imex/sync/sync.const.ts b/src/app/imex/sync/sync.const.ts index f6c934f217f..2d6fb7cc2cf 100644 --- a/src/app/imex/sync/sync.const.ts +++ b/src/app/imex/sync/sync.const.ts @@ -1,3 +1,16 @@ +import { initialProjectState } from '../../features/project/store/project.reducer'; +import { DEFAULT_GLOBAL_CONFIG } from '../../features/config/default-global-config.const'; +import { initialTaskState } from '../../features/tasks/store/task.reducer'; +import { initialTagState } from '../../features/tag/store/tag.reducer'; +import { initialSimpleCounterState } from '../../features/simple-counter/store/simple-counter.reducer'; +import { createEmptyEntity } from '../../util/create-empty-entity'; +import { TaskArchive } from '../../features/tasks/task.model'; +import { initialTaskRepeatCfgState } from '../../features/task-repeat-cfg/store/task-repeat-cfg.reducer'; +import { initialMetricState } from '../../features/metric/store/metric.reducer'; +import { initialImprovementState } from '../../features/metric/improvement/store/improvement.reducer'; +import { initialObstructionState } from '../../features/metric/obstruction/store/obstruction.reducer'; +import { AppBaseData } from './sync.model'; + export const SYNC_INITIAL_SYNC_TRIGGER = 'INITIAL_SYNC_TRIGGER'; export const SYNC_DEFAULT_AUDIT_TIME = 10000; @@ -6,3 +19,21 @@ export const SYNC_BEFORE_GOING_TO_SLEEP_THROTTLE_TIME = 1000 * 60 * 5; export const SYNC_BEFORE_CLOSE_ID = 'SYNC_BEFORE_CLOSE_ID'; export const SYNC_MIN_INTERVAL = 5000; + +export const DEFAULT_APP_BASE_DATA: AppBaseData = { + project: initialProjectState, + archivedProjects: {}, + globalConfig: DEFAULT_GLOBAL_CONFIG, + reminders: [], + + task: initialTaskState, + tag: initialTagState, + simpleCounter: initialSimpleCounterState, + taskArchive: createEmptyEntity() as TaskArchive, + taskRepeatCfg: initialTaskRepeatCfgState, + + // metric + metric: initialMetricState, + improvement: initialImprovementState, + obstruction: initialObstructionState, +}; diff --git a/src/app/imex/sync/sync.model.ts b/src/app/imex/sync/sync.model.ts index cfb470ccb47..2ce522f4ba7 100644 --- a/src/app/imex/sync/sync.model.ts +++ b/src/app/imex/sync/sync.model.ts @@ -1,11 +1,5 @@ -import { - initialProjectState, - ProjectState, -} from '../../features/project/store/project.reducer'; import { GlobalConfigState } from '../../features/config/global-config.model'; import { TaskArchive, TaskState } from '../../features/tasks/task.model'; -import { BookmarkState } from '../../features/bookmark/store/bookmark.reducer'; -import { NoteState } from '../../features/note/store/note.reducer'; import { Reminder } from '../../features/reminder/reminder.model'; import { MetricState } from '../../features/metric/metric.model'; import { ImprovementState } from '../../features/metric/improvement/improvement.model'; @@ -15,17 +9,11 @@ import { TagState } from '../../features/tag/tag.model'; import { TaskAttachment } from '../../features/tasks/task-attachment/task-attachment.model'; import { EntityState } from '@ngrx/entity'; import { SimpleCounterState } from '../../features/simple-counter/simple-counter.model'; -import { DEFAULT_GLOBAL_CONFIG } from '../../features/config/default-global-config.const'; -import { initialTaskState } from '../../features/tasks/store/task.reducer'; -import { initialTagState } from '../../features/tag/store/tag.reducer'; -import { initialSimpleCounterState } from '../../features/simple-counter/store/simple-counter.reducer'; -import { createEmptyEntity } from '../../util/create-empty-entity'; -import { initialTaskRepeatCfgState } from '../../features/task-repeat-cfg/store/task-repeat-cfg.reducer'; import { ProjectArchive } from '../../features/project/project-archive.model'; import { SyncProvider } from './sync-provider.model'; -import { initialMetricState } from '../../features/metric/store/metric.reducer'; -import { initialImprovementState } from '../../features/metric/improvement/store/improvement.reducer'; -import { initialObstructionState } from '../../features/metric/obstruction/store/obstruction.reducer'; +import { ProjectState } from '../../features/project/project.model'; +import { BookmarkState } from '../../features/bookmark/bookmark.model'; +import { NoteState } from '../../features/note/note.model'; /** @deprecated */ export type TaskAttachmentState = EntityState; @@ -87,24 +75,6 @@ export interface AppDataComplete extends AppBaseData, AppDataForProjects { lastLocalSyncModelChange: number | null; } -export const DEFAULT_APP_BASE_DATA: AppBaseData = { - project: initialProjectState, - archivedProjects: {}, - globalConfig: DEFAULT_GLOBAL_CONFIG, - reminders: [], - - task: initialTaskState, - tag: initialTagState, - simpleCounter: initialSimpleCounterState, - taskArchive: createEmptyEntity() as TaskArchive, - taskRepeatCfg: initialTaskRepeatCfgState, - - // metric - metric: initialMetricState, - improvement: initialImprovementState, - obstruction: initialObstructionState, -}; - export type DialogConflictResolutionResult = 'USE_LOCAL' | 'USE_REMOTE' | false; export type SyncGetRevResult = 'NO_REMOTE_DATA' | 'HANDLED_ERROR' | Error; diff --git a/src/app/root-store/root-state.ts b/src/app/root-store/root-state.ts index 4b263ea25ef..41a1a369a03 100644 --- a/src/app/root-store/root-state.ts +++ b/src/app/root-store/root-state.ts @@ -1,14 +1,8 @@ import { TASK_FEATURE_NAME } from '../features/tasks/store/task.reducer'; import { TaskState } from '../features/tasks/task.model'; -import { - PROJECT_FEATURE_NAME, - ProjectState, -} from '../features/project/store/project.reducer'; -import { NOTE_FEATURE_NAME, NoteState } from '../features/note/store/note.reducer'; -import { - BOOKMARK_FEATURE_NAME, - BookmarkState, -} from '../features/bookmark/store/bookmark.reducer'; +import { PROJECT_FEATURE_NAME } from '../features/project/store/project.reducer'; +import { NOTE_FEATURE_NAME } from '../features/note/store/note.reducer'; +import { BOOKMARK_FEATURE_NAME } from '../features/bookmark/store/bookmark.reducer'; import { LAYOUT_FEATURE_NAME, LayoutState } from '../core-ui/layout/store/layout.reducer'; import { CONFIG_FEATURE_NAME } from '../features/config/store/global-config.reducer'; import { GlobalConfigState } from '../features/config/global-config.model'; @@ -16,6 +10,9 @@ import { WorkContextState } from '../features/work-context/work-context.model'; import { TAG_FEATURE_NAME } from '../features/tag/store/tag.reducer'; import { TagState } from '../features/tag/tag.model'; import { WORK_CONTEXT_FEATURE_NAME } from '../features/work-context/store/work-context.selectors'; +import { ProjectState } from '../features/project/project.model'; +import { BookmarkState } from '../features/bookmark/bookmark.model'; +import { NoteState } from '../features/note/note.model'; export interface RootState { [TASK_FEATURE_NAME]: TaskState;