Skip to content

Commit

Permalink
feat: strict null checks #5
Browse files Browse the repository at this point in the history
  • Loading branch information
johannesjo committed Jul 5, 2020
1 parent 33de270 commit f010cdb
Show file tree
Hide file tree
Showing 25 changed files with 116 additions and 98 deletions.
4 changes: 2 additions & 2 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,12 @@ export class AppComponent implements OnDestroy {
}

if (IS_ELECTRON) {
this._electronService.ipcRenderer.send(IPC.APP_READY);
(this._electronService.ipcRenderer as typeof ipcRenderer).send(IPC.APP_READY);
this._initElectronErrorHandler();
this._uiHelperService.initElectron();

this._electronService.ipcRenderer.on(IPC.TRANSFER_SETTINGS_REQUESTED, () => {
this._electronService.ipcRenderer.send(IPC.TRANSFER_SETTINGS_TO_ELECTRON, this._configService.cfg);
(this._electronService.ipcRenderer as typeof ipcRenderer).send(IPC.TRANSFER_SETTINGS_TO_ELECTRON, this._configService.cfg);
});
} else {
// WEB VERSION
Expand Down
2 changes: 1 addition & 1 deletion src/app/core-ui/shortcut/shortcut.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export class ShortcutService {
// special hidden dev tools combo to use them for production
if (IS_ELECTRON) {
if (checkKeyCombo(ev, 'Ctrl+Shift+J')) {
this._electronService.ipcRenderer.send('TOGGLE_DEV_TOOLS');
(this._electronService.ipcRenderer as typeof ipcRenderer).send('TOGGLE_DEV_TOOLS');
} else if (checkKeyCombo(ev, keys.zoomIn)) {
this._uiHelperService.zoomBy(0.05);
} else if (checkKeyCombo(ev, keys.zoomOut)) {
Expand Down
1 change: 1 addition & 0 deletions src/app/core/compression/lz.worker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/// <reference lib="webworker" />
// @ts-ignore
import * as LZString from 'lz-string/libs/lz-string';

function handleData(msgData: any) {
Expand Down
4 changes: 2 additions & 2 deletions src/app/features/config/store/global-config.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class GlobalConfigEffects {
filter((action: UpdateGlobalConfigSection) => IS_ELECTRON && action.payload.sectionKey === 'keyboard'),
tap((action: UpdateGlobalConfigSection) => {
const keyboardCfg: KeyboardConfig = action.payload.sectionCfg as KeyboardConfig;
this._electronService.ipcRenderer.send(IPC.REGISTER_GLOBAL_SHORTCUTS_EVENT, keyboardCfg);
(this._electronService.ipcRenderer as typeof ipcRenderer).send(IPC.REGISTER_GLOBAL_SHORTCUTS_EVENT, keyboardCfg);
}),
);

Expand All @@ -66,7 +66,7 @@ export class GlobalConfigEffects {
tap((action) => {
const appDataComplete = action.appDataComplete;
const keyboardCfg: KeyboardConfig = (appDataComplete.globalConfig || DEFAULT_GLOBAL_CONFIG).keyboard;
this._electronService.ipcRenderer.send(IPC.REGISTER_GLOBAL_SHORTCUTS_EVENT, keyboardCfg);
(this._electronService.ipcRenderer as typeof ipcRenderer).send(IPC.REGISTER_GLOBAL_SHORTCUTS_EVENT, keyboardCfg);
}),
);

Expand Down
2 changes: 1 addition & 1 deletion src/app/features/google/google-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class GoogleApiService {
return new Promise((resolve) => resolve(true));
}

this._electronService.ipcRenderer.send(IPC.TRIGGER_GOOGLE_AUTH, session.refreshToken);
(this._electronService.ipcRenderer as typeof ipcRenderer).send(IPC.TRIGGER_GOOGLE_AUTH, session.refreshToken);
return new Promise((resolve, reject) => {
this._electronService.ipcRenderer.on(IPC.GOOGLE_AUTH_TOKEN, (ev, data: any) => {
this._updateSession({
Expand Down
2 changes: 1 addition & 1 deletion src/app/features/issue/providers/jira/jira-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ export class JiraApiService {

const requestToSend = {requestId, requestInit, url};
if (this._electronService.isElectronApp) {
this._electronService.ipcRenderer.send(IPC.JIRA_MAKE_REQUEST_EVENT, {...requestToSend, jiraCfg});
(this._electronService.ipcRenderer as typeof ipcRenderer).send(IPC.JIRA_MAKE_REQUEST_EVENT, {...requestToSend, jiraCfg});
} else if (this._isExtension) {
this._chromeExtensionInterfaceService.dispatchEvent('SP_JIRA_REQUEST', requestToSend);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,18 @@ import {
OnInit,
Output
} from '@angular/core';
import {MetricCopy} from '../metric.model';
import {MetricService} from '../metric.service';
import {ObstructionService} from '../obstruction/obstruction.service';
import {ImprovementService} from '../improvement/improvement.service';
import {BehaviorSubject, Observable, Subscription} from 'rxjs';
import {NoteService} from '../../note/note.service';
import {getWorklogStr} from '../../../util/get-work-log-str';
import {switchMap} from 'rxjs/operators';
import {ProjectService} from '../../project/project.service';
import {T} from '../../../t.const';
import {DialogAddNoteComponent} from '../../note/dialog-add-note/dialog-add-note.component';
import {MatDialog} from '@angular/material/dialog';

import { MetricCopy } from '../metric.model';
import { MetricService } from '../metric.service';
import { ObstructionService } from '../obstruction/obstruction.service';
import { ImprovementService } from '../improvement/improvement.service';
import { BehaviorSubject, Observable, Subscription } from 'rxjs';
import { NoteService } from '../../note/note.service';
import { getWorklogStr } from '../../../util/get-work-log-str';
import { switchMap } from 'rxjs/operators';
import { ProjectService } from '../../project/project.service';
import { T } from '../../../t.const';
import { DialogAddNoteComponent } from '../../note/dialog-add-note/dialog-add-note.component';
import { MatDialog } from '@angular/material/dialog';

@Component({
selector: 'evaluation-sheet',
Expand All @@ -31,7 +30,7 @@ import {MatDialog} from '@angular/material/dialog';
export class EvaluationSheetComponent implements OnDestroy, OnInit {
@Output() save: EventEmitter<any> = new EventEmitter();
T: any = T;
metricForDay: MetricCopy;
metricForDay?: MetricCopy;
day$: BehaviorSubject<string> = new BehaviorSubject(getWorklogStr());
private _metricForDay$: Observable<MetricCopy> = this.day$.pipe(
switchMap((day) => this._metricService.getMetricForDayOrDefaultWithCheckedImprovements$(day)),
Expand Down Expand Up @@ -74,43 +73,43 @@ export class EvaluationSheetComponent implements OnDestroy, OnInit {
}

addObstruction(v: string) {
this._update({obstructions: [...this.metricForDay.obstructions, v]});
this._update({obstructions: [...(this.metricForDay as MetricCopy).obstructions, v]});
}

addNewObstruction(v: string) {
const id = this.obstructionService.addObstruction(v);
this._update({obstructions: [...this.metricForDay.obstructions, id]});
this._update({obstructions: [...(this.metricForDay as MetricCopy).obstructions, id]});
}

removeObstruction(idToRemove: string) {
this._update({obstructions: this.metricForDay.obstructions.filter(id => id !== idToRemove)});
this._update({obstructions: (this.metricForDay as MetricCopy).obstructions.filter(id => id !== idToRemove)});
}

addImprovement(v: string) {
this._update({improvements: [...this.metricForDay.improvements, v]});
this._update({improvements: [...(this.metricForDay as MetricCopy).improvements, v]});
}

addNewImprovement(v: string) {
const id = this.improvementService.addImprovement(v);
this._update({improvements: [...this.metricForDay.improvements, id]});
this._update({improvements: [...(this.metricForDay as MetricCopy).improvements, id]});
}

removeImprovement(idToRemove: string) {
this._update({improvements: this.metricForDay.improvements.filter(id => id !== idToRemove)});
this._update({improvements: (this.metricForDay as MetricCopy).improvements.filter(id => id !== idToRemove)});
}

addImprovementTomorrow(v: string) {
this._update({improvementsTomorrow: [...this.metricForDay.improvementsTomorrow, v]});
this._update({improvementsTomorrow: [...(this.metricForDay as MetricCopy).improvementsTomorrow, v]});
}

addNewImprovementTomorrow(v: string) {
const id = this.improvementService.addImprovement(v);
this._update({improvementsTomorrow: [...this.metricForDay.improvementsTomorrow, id]});
this._update({improvementsTomorrow: [...(this.metricForDay as MetricCopy).improvementsTomorrow, id]});
}

removeImprovementTomorrow(idToRemove: string) {
this._update({
improvementsTomorrow: this.metricForDay.improvementsTomorrow.filter(id => id !== idToRemove),
improvementsTomorrow: (this.metricForDay as MetricCopy).improvementsTomorrow.filter(id => id !== idToRemove),
});
// this.improvementService.disableImprovementRepeat(idToRemove);
}
Expand All @@ -125,9 +124,9 @@ export class EvaluationSheetComponent implements OnDestroy, OnInit {

private _update(updateData: Partial<MetricCopy>) {
this.metricForDay = {
...this.metricForDay,
...(this.metricForDay as MetricCopy),
...updateData,
} as MetricCopy;
this._metricService.upsertMetric(this.metricForDay);
this._metricService.upsertMetric((this.metricForDay as MetricCopy));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { T } from '../../../t.const';
})
export class ImprovementBannerComponent implements OnDestroy {
T: any = T;
improvements: Improvement[];
improvements?: Improvement[];

private _subs: Subscription = new Subscription();

Expand Down
2 changes: 1 addition & 1 deletion src/app/features/planning-mode/planning-mode.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { WorkContextService } from '../work-context/work-context.service';
@Injectable({providedIn: 'root'})
export class PlanningModeService {
private _iPlanningModeEndedUser$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
private _manualTriggerCheck$: BehaviorSubject<unknown> = new BehaviorSubject(null);
private _manualTriggerCheck$: BehaviorSubject<unknown> = new BehaviorSubject<unknown>(null);
private _triggerCheck$: Observable<unknown> = merge(
this._manualTriggerCheck$,
// TODO fix hacky way of waiting for data to be loaded
Expand Down
2 changes: 1 addition & 1 deletion src/app/features/tag/store/tag.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export class TagEffects {
// remove orphaned for archive
const taskArchiveState: TaskArchive = await this._persistenceService.taskArchive.loadState() || createEmptyEntity();
const archiveTaskIdsToDelete = (taskArchiveState.ids as string[]).filter((id) => {
const t = taskArchiveState.entities[id];
const t = taskArchiveState.entities[id] as Task;
return isOrphanedParentTask(t);
});
await this._persistenceService.taskArchive.execAction(new DeleteMainTasks({taskIds: archiveTaskIdsToDelete}));
Expand Down
14 changes: 7 additions & 7 deletions src/app/features/tag/tag-list/tag-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ export class TagListComponent implements OnDestroy {
@Output() addedTagsToTask: EventEmitter<string[]> = new EventEmitter();
@Output() removedTagsFromTask: EventEmitter<string[]> = new EventEmitter();
@Output() replacedTagForTask: EventEmitter<string[]> = new EventEmitter();
projectTag: TagComponentTag;
tags: Tag[];
projectTag?: TagComponentTag | null;
tags?: Tag[];
private _isShowProjectTagAlways$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
private _projectId$: BehaviorSubject<string> = new BehaviorSubject(null);
projectTag$: Observable<TagComponentTag> = combineLatest([
private _projectId$: BehaviorSubject<string | null> = new BehaviorSubject<string | null>(null);
projectTag$: Observable<TagComponentTag | null> = combineLatest([
this._workContextService.activeWorkContextTypeAndId$,
this._isShowProjectTagAlways$
]).pipe(
switchMap(([{activeType}, isShowAlways]) => isShowAlways || (activeType === WorkContextType.TAG)
? this._projectId$.pipe(
switchMap(id => this._projectService.getByIdOnce$(id)),
switchMap(id => this._projectService.getByIdOnce$(id as string)),
map(project => (project && {
...project,
icon: 'list'
Expand All @@ -44,7 +44,7 @@ export class TagListComponent implements OnDestroy {
: of(null)
),
);
private _tagIds$: BehaviorSubject<string[]> = new BehaviorSubject([]);
private _tagIds$: BehaviorSubject<string[]> = new BehaviorSubject<string[]>([]);
tags$: Observable<Tag[]> = combineLatest([
this._tagIds$,
this._workContextService.activeWorkContextId$,
Expand All @@ -71,7 +71,7 @@ export class TagListComponent implements OnDestroy {

// NOTE: should normally be enough

private _task: Task;
private _task?: Task;

@Input() set task(task: Task) {
this._task = task;
Expand Down
4 changes: 2 additions & 2 deletions src/app/features/tag/tag/tag.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ export interface TagComponentTag {
changeDetection: ChangeDetectionStrategy.OnPush
})
export class TagComponent {
tag: TagComponentTag;
tag?: TagComponentTag;
// @HostBinding('style.background')
color: string;
color?: string;

constructor() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ export class DialogViewTaskRemindersComponent implements OnDestroy {
first(),
map((tasks: Task[]) => tasks
.filter(task => !!task)
.map((task) => ({
.map((task): TaskWithReminderData => ({
...task,
reminderData: reminders.find(r => r.relatedId === task.id)
reminderData: reminders.find(r => r.relatedId === task.id) as Reminder
}))
)
)),
Expand Down Expand Up @@ -87,22 +87,22 @@ export class DialogViewTaskRemindersComponent implements OnDestroy {
reminderId: null,
});
this._reminderService.removeReminder(task.reminderData.id);
this._removeFromList(task.reminderId);
this._removeFromList(task.reminderId as string);
}

snooze(task: TaskWithReminderData, snoozeInMinutes: number) {
this._reminderService.updateReminder(task.reminderData.id, {
remindAt: Date.now() + (snoozeInMinutes * M)
});
this._removeFromList(task.reminderId);
this._removeFromList(task.reminderId as string);
}

editReminder(task: TaskWithReminderData, isCloseAfter: boolean = false) {
this._subs.add(this._matDialog.open(DialogAddTaskReminderComponent, {
restoreFocus: true,
data: {task} as AddTaskReminderInterface
}).afterClosed().subscribe(() => {
this._removeFromList(task.reminderId);
this._removeFromList(task.reminderId as string);
if (isCloseAfter) {
this._close();
}
Expand Down
7 changes: 4 additions & 3 deletions src/app/features/tasks/store/task-electron.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { IS_ELECTRON } from '../../../app.constants';
import { GlobalConfigState } from '../../config/global-config.model';
import { GlobalConfigService } from '../../config/global-config.service';
import { ElectronService } from '../../../core/electron/electron.service';
import { ipcRenderer } from 'electron';

// TODO send message to electron when current task changes here

Expand All @@ -25,7 +26,7 @@ export class TaskElectronEffects {
withLatestFrom(this._store$.pipe(select(selectCurrentTask))),
tap(([action, current]) => {
if (IS_ELECTRON) {
this._electronService.ipcRenderer.send(IPC.CURRENT_TASK_UPDATED, {current});
(this._electronService.ipcRenderer as typeof ipcRenderer).send(IPC.CURRENT_TASK_UPDATED, {current});
}
})
);
Expand All @@ -38,7 +39,7 @@ export class TaskElectronEffects {
filter(() => IS_ELECTRON),
tap((act: SetCurrentTask) => {
if (!act.payload) {
this._electronService.ipcRenderer.send(IPC.SET_PROGRESS_BAR, {progress: 0});
(this._electronService.ipcRenderer as typeof ipcRenderer).send(IPC.SET_PROGRESS_BAR, {progress: 0});
}
}),
);
Expand All @@ -55,7 +56,7 @@ export class TaskElectronEffects {
map(([act]) => act.payload.task),
tap((task: Task) => {
const progress = task.timeSpent / task.timeEstimate;
this._electronService.ipcRenderer.send(IPC.SET_PROGRESS_BAR, {progress});
(this._electronService.ipcRenderer as typeof ipcRenderer).send(IPC.SET_PROGRESS_BAR, {progress});
}),
);

Expand Down
Loading

0 comments on commit f010cdb

Please sign in to comment.