Skip to content

Commit

Permalink
refactor: fix code style
Browse files Browse the repository at this point in the history
  • Loading branch information
johannesjo committed Jan 3, 2024
1 parent 16da66b commit d137e7d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 39 deletions.
9 changes: 6 additions & 3 deletions src/app/core/persistence/persistence.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,13 +428,16 @@ export class PersistenceService {
const model = {
appDataKey,
loadState: async (isSkipMigrate = false) => {
const modelData = await (this._loadFromDb({dbKey: appDataKey, legacyDBKey: legacyKey}));
const modelData = await this._loadFromDb({
dbKey: appDataKey,
legacyDBKey: legacyKey,
});
return modelData
? isSkipMigrate
? modelData
: migrateFn(modelData)
// we want to be sure there is always a valid value returned
: DEFAULT_APP_BASE_DATA[appDataKey];
: // we want to be sure there is always a valid value returned
DEFAULT_APP_BASE_DATA[appDataKey];
},
// In case we want to check on load
// loadState: async (isSkipMigrate = false) => {
Expand Down
74 changes: 39 additions & 35 deletions src/app/features/work-context/work-context.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ import { TODAY_TAG } from '../tag/tag.const';
import { TagService } from '../tag/tag.service';
import { ArchiveTask, Task, TaskPlanned, TaskWithSubTasks } from '../tasks/task.model';
import { hasTasksToWorkOn, mapEstimateRemainingFromTasks } from './work-context.util';
import { flattenTasks, selectAllTasks, selectTasksWithSubTasksByIds, } from '../tasks/store/task.selectors';
import {
flattenTasks,
selectAllTasks,
selectTasksWithSubTasksByIds,
} from '../tasks/store/task.selectors';
import { Actions, ofType } from '@ngrx/effects';
import { WorklogExportSettings } from '../worklog/worklog.model';
import {
Expand Down Expand Up @@ -108,14 +112,14 @@ export class WorkContextService {
);
isActiveWorkContextProject$: Observable<boolean> =
this.activeWorkContextTypeAndId$.pipe(
map(({activeType}) => activeType === WorkContextType.PROJECT),
map(({ activeType }) => activeType === WorkContextType.PROJECT),
shareReplay(1),
);

activeWorkContextIdIfProject$: Observable<string> =
this.activeWorkContextTypeAndId$.pipe(
map(({activeType, activeId}) => {
if(activeType !== WorkContextType.PROJECT) {
map(({ activeType, activeId }) => {
if (activeType !== WorkContextType.PROJECT) {
throw Error('Not in project context');
}
return activeId;
Expand All @@ -135,9 +139,9 @@ export class WorkContextService {
switchMap((activeContext) =>
activeContext.id === TODAY_TAG.id && activeContext.title === TODAY_TAG.title
? this._translateService.onLangChange.pipe(
startWith(this._translateService.currentLang),
map(() => this._translateService.instant(T.G.TODAY_TAG_TITLE)),
)
startWith(this._translateService.currentLang),
map(() => this._translateService.instant(T.G.TODAY_TAG_TITLE)),
)
: of(activeContext.title),
),
);
Expand All @@ -157,12 +161,12 @@ export class WorkContextService {
switchMap((mainWorkContext) =>
mainWorkContext.id === TODAY_TAG.id && mainWorkContext.title === TODAY_TAG.title
? this._translateService.onLangChange.pipe(
startWith(this._translateService.currentLang),
map(() => ({
...mainWorkContext,
title: this._translateService.instant(T.G.TODAY_TAG_TITLE),
})),
)
startWith(this._translateService.currentLang),
map(() => ({
...mainWorkContext,
title: this._translateService.instant(T.G.TODAY_TAG_TITLE),
})),
)
: of(mainWorkContext),
),
);
Expand Down Expand Up @@ -327,26 +331,26 @@ export class WorkContextService {
isAllDataLoaded
? of(next as NavigationEnd)
: this._isAllDataLoaded$.pipe(
filter((isLoaded) => isLoaded),
take(1),
mapTo(next as NavigationEnd),
),
filter((isLoaded) => isLoaded),
take(1),
mapTo(next as NavigationEnd),
),
),
)
.subscribe(({urlAfterRedirects}: NavigationEnd) => {
.subscribe(({ urlAfterRedirects }: NavigationEnd) => {
const split = urlAfterRedirects.split('/');
const id = split[2];

// prevent issue when setActiveContext is called directly
if(this.activeWorkContextId === id) {
if (this.activeWorkContextId === id) {
return;
}

if(urlAfterRedirects.match(/tag\/.+/)) {
if (urlAfterRedirects.match(/tag\/.+/)) {
this._setActiveContext(id, WorkContextType.TAG);
} else if(urlAfterRedirects.match(/project\/.+/)) {
} else if (urlAfterRedirects.match(/project\/.+/)) {
this._setActiveContext(id, WorkContextType.PROJECT);
} else if(urlAfterRedirects.match(/timeline/)) {
} else if (urlAfterRedirects.match(/timeline/)) {
this._setActiveContext(TODAY_TAG.id, WorkContextType.TAG);
}
});
Expand All @@ -367,21 +371,21 @@ export class WorkContextService {
day: string = this._dateService.todayStr(),
): Promise<number> {
const isToday = await this.isToday$.pipe(first()).toPromise();
const {activeId, activeType} = await this.activeWorkContextTypeAndId$
const { activeId, activeType } = await this.activeWorkContextTypeAndId$
.pipe(first())
.toPromise();
const taskArchiveState = await this._persistenceService.taskArchive.loadState();

const {ids, entities} = taskArchiveState;
const { ids, entities } = taskArchiveState;
const tasksWorkedOnToday: ArchiveTask[] = ids
.map((id) => entities[id])
.filter((t) => t?.timeSpentOnDay[day]) as ArchiveTask[];

let tasksToConsider: ArchiveTask[] = [];
if(isToday) {
if (isToday) {
tasksToConsider = tasksWorkedOnToday;
} else {
if(activeType === WorkContextType.PROJECT) {
if (activeType === WorkContextType.PROJECT) {
tasksToConsider = tasksWorkedOnToday.filter((t) => t.projectId === activeId);
} else {
tasksToConsider = tasksWorkedOnToday.filter((t) => t.tagIds.includes(activeId));
Expand Down Expand Up @@ -490,15 +494,15 @@ export class WorkContextService {
sectionKey: WorkContextAdvancedCfgKey,
data: any,
): void {
if(this.activeWorkContextType === WorkContextType.PROJECT) {
if (this.activeWorkContextType === WorkContextType.PROJECT) {
this._store$.dispatch(
updateProjectAdvancedCfg({
projectId: this.activeWorkContextId as string,
sectionKey,
data,
}),
);
} else if(this.activeWorkContextType === WorkContextType.TAG) {
} else if (this.activeWorkContextType === WorkContextType.TAG) {
this._store$.dispatch(
updateAdvancedConfigForTag({
tagId: this.activeWorkContextId as string,
Expand All @@ -511,24 +515,24 @@ export class WorkContextService {

// we don't want a circular dependency that's why we do it here...
private _getTasksByIds$(ids: string[]): Observable<TaskWithSubTasks[]> {
if(!Array.isArray(ids)) {
console.log({ids});
if (!Array.isArray(ids)) {
console.log({ ids });
throw new Error('Invalid param provided for getByIds$ :(');
}
return this._store$.select(selectTasksWithSubTasksByIds, {ids});
return this._store$.select(selectTasksWithSubTasksByIds, { ids });
}

// we don't want a circular dependency that's why we do it here...
private _getNotesByIds$(ids: string[]): Observable<Note[]> {
if(!Array.isArray(ids)) {
console.log({ids});
if (!Array.isArray(ids)) {
console.log({ ids });
throw new Error('Invalid param provided for getByIds$ :(');
}
return this._store$.select(selectNotesById, {ids});
return this._store$.select(selectNotesById, { ids });
}

// NOTE: NEVER call this from some place other than the route change stuff
private _setActiveContext(activeId: string, activeType: WorkContextType): void {
this._store$.dispatch(setActiveWorkContext({activeId, activeType}));
this._store$.dispatch(setActiveWorkContext({ activeId, activeType }));
}
}
2 changes: 1 addition & 1 deletion src/environments/versions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// this file is automatically generated by git.version.ts script
export const versions = {
version: '7.17.0',
version: '7.17.2',
revision: 'NO_REV',
branch: 'NO_BRANCH',
};

0 comments on commit d137e7d

Please sign in to comment.