Skip to content

Commit

Permalink
feat: strict null checks #4
Browse files Browse the repository at this point in the history
  • Loading branch information
johannesjo committed Jul 3, 2020
1 parent 15824ec commit d0ff43b
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 65 deletions.
16 changes: 9 additions & 7 deletions src/app/core-ui/main-header/main-header.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ export class MainHeaderComponent implements OnInit, OnDestroy {
progressCircleRadius: number = 10;
circumference: number = this.progressCircleRadius * Math.PI * 2;

@ViewChild('circleSvg', {static: true}) circleSvg: ElementRef;
@ViewChild('circleSvg', {static: true}) circleSvg?: ElementRef;

currentTaskContext$: Observable<Project | Tag> = this.taskService.currentTaskParentOrCurrent$.pipe(
currentTaskContext$: Observable<Project | Tag | null> = this.taskService.currentTaskParentOrCurrent$.pipe(
filter(ct => !!ct),
switchMap((currentTask) => this.workContextService.activeWorkContextId$.pipe(
switchMap((activeWorkContextId) => {
Expand Down Expand Up @@ -77,12 +77,14 @@ export class MainHeaderComponent implements OnInit, OnDestroy {

ngOnInit() {
this.taskService.currentTaskProgress$.subscribe((progressIN) => {
let progress = progressIN || 1;
if (progress > 1) {
progress = 1;
if (this.circleSvg) {
let progress = progressIN || 1;
if (progress > 1) {
progress = 1;
}
const dashOffset = this.circumference * -1 * progress;
this._renderer.setStyle(this.circleSvg.nativeElement, 'stroke-dashoffset', dashOffset);
}
const dashOffset = this.circumference * -1 * progress;
this._renderer.setStyle(this.circleSvg.nativeElement, 'stroke-dashoffset', dashOffset);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { T } from '../../../t.const';
export class BookmarkBarComponent implements OnDestroy {
isDragOver: boolean = false;
isEditMode: boolean = false;
dragEnterTarget: HTMLElement;
dragEnterTarget?: HTMLElement;
LIST_ID: string = 'BOOKMARKS';
T: any = T;
isContextMenuDisabled: boolean = false;
Expand All @@ -44,7 +44,7 @@ export class BookmarkBarComponent implements OnDestroy {
this._subs.add(this._dragulaService.dropModel(this.LIST_ID)
.subscribe((params: any) => {
const {target, source, targetModel, item} = params;
const newIds = targetModel.map(m => m.id);
const newIds = targetModel.map((m: Bookmark) => m.id);
this.bookmarkService.reorderBookmarks(newIds);
})
);
Expand Down
19 changes: 13 additions & 6 deletions src/app/features/bookmark/bookmark-link/bookmark-link.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import { SnackService } from '../../../core/snack/snack.service';
import { IPC } from '../../../../../electron/ipc-events.const';
import { T } from '../../../t.const';
import { ElectronService } from '../../../core/electron/electron.service';
import { ipcRenderer, shell } from 'electron';

@Directive({
selector: '[bookmarkLink]'
})
export class BookmarkLinkDirective {

@Input() type: BookmarkType;
@Input() href: BookmarkType;
@Input() type?: BookmarkType;
@Input() href?: BookmarkType;

constructor(
private _electronService: ElectronService,
Expand All @@ -21,6 +22,10 @@ export class BookmarkLinkDirective {
}

@HostListener('click', ['$event']) onClick(ev: Event) {
if (!this.type || !this.href) {
return;
}

if (ev.target) {
const el = ev.target as HTMLElement;
el.blur();
Expand All @@ -30,7 +35,7 @@ export class BookmarkLinkDirective {
if (!this.type || this.type === 'LINK') {
this._openExternalUrl(this.href);
} else if (this.type === 'FILE') {
this._electronService.shell.openPath(this.href);
(this._electronService.shell as typeof shell).openPath(this.href);
} else if (this.type === 'COMMAND') {
this._snackService.open({
msg: T.GLOBAL_SNACK.RUNNING_X,
Expand All @@ -51,14 +56,16 @@ export class BookmarkLinkDirective {
.replace('http://http://', 'http://');

if (IS_ELECTRON) {
this._electronService.shell.openExternal(url);
(this._electronService.shell as typeof shell).openExternal(url);
} else {
const win = window.open(url, '_blank');
win.focus();
if (win) {
win.focus();
}
}
}

private _exec(command: string) {
this._electronService.ipcRenderer.send(IPC.EXEC, command);
(this._electronService.ipcRenderer as typeof ipcRenderer).send(IPC.EXEC, command);
}
}
4 changes: 3 additions & 1 deletion src/app/features/pomodoro/pomodoro.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class PomodoroService {
this.currentCycle$,
this.cfg$,
]).pipe(map(([isBreak, currentCycle, cfg]) => {
return isBreak && cfg.cyclesBeforeLongerBreak && Number.isInteger(((currentCycle + 1) / cfg.cyclesBeforeLongerBreak));
return isBreak && !!cfg.cyclesBeforeLongerBreak && Number.isInteger(((currentCycle + 1) / cfg.cyclesBeforeLongerBreak));
}));

isShortBreak$: Observable<boolean> = combineLatest([
Expand Down Expand Up @@ -91,6 +91,8 @@ export class PomodoroService {
return cfg.breakDuration || DEFAULT_GLOBAL_CONFIG.pomodoro.breakDuration;
} else if (isLong) {
return cfg.longerBreakDuration || DEFAULT_GLOBAL_CONFIG.pomodoro.longerBreakDuration;
} else {
throw new Error('Pomodoro: nextSession$');
}
}),
shareReplay(1),
Expand Down
27 changes: 14 additions & 13 deletions src/app/features/pomodoro/store/pomodoro.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,20 @@ import { MatDialog } from '@angular/material/dialog';
import { DialogPomodoroBreakComponent } from '../dialog-pomodoro-break/dialog-pomodoro-break.component';
import { select, Store } from '@ngrx/store';
import { selectCurrentTaskId } from '../../tasks/store/task.selectors';
import { Observable, of } from 'rxjs';
import { EMPTY, Observable, of } from 'rxjs';
import { NotifyService } from '../../../core/notify/notify.service';
import { IS_ELECTRON } from '../../../app.constants';
import { IPC } from '../../../../../electron/ipc-events.const';
import { T } from '../../../t.const';
import { SnackService } from '../../../core/snack/snack.service';
import { ElectronService } from '../../../core/electron/electron.service';
import { ipcRenderer } from 'electron';

const isEnabled = ([action, cfg, ...v]) => cfg && cfg.isEnabled;
const isEnabled = ([action, cfg, ...v]: any[] | any): boolean => !!cfg && !!cfg.isEnabled;

@Injectable()
export class PomodoroEffects {
currentTaskId$: Observable<string> = this._store$.pipe(select(selectCurrentTaskId));
currentTaskId$: Observable<string | null> = this._store$.pipe(select(selectCurrentTaskId));

@Effect()
playPauseOnCurrentUpdate$: Observable<unknown> = this._actions$.pipe(
Expand All @@ -48,7 +49,7 @@ export class PomodoroEffects {
|| (isBreak && currentSessionTime <= 0 && action.type === TaskActionTypes.SetCurrentTask)),
concatMap(([action, , isBreak, currentSessionTime]) => {
// tslint:disable-next-line
const payload = action['payload'];
const payload = (action as any)['payload'];

if (payload && action.type !== TaskActionTypes.UnsetCurrentTask) {
if (isBreak && currentSessionTime <= 0) {
Expand Down Expand Up @@ -178,15 +179,15 @@ export class PomodoroEffects {
);

@Effect({dispatch: false})
setTaskBarIconProgress$: Observable<unknown> = this._pomodoroService.sessionProgress$.pipe(
filter(() => IS_ELECTRON),
withLatestFrom(this._pomodoroService.cfg$),
// we display pomodoro progress for pomodoro
filter(([progress, cfg]: [number, PomodoroConfig]) => cfg && cfg.isEnabled),
tap(([progress, cfg]) => {
this._electronService.ipcRenderer.send(IPC.SET_PROGRESS_BAR, {progress});
}),
);
setTaskBarIconProgress$: Observable<unknown> = IS_ELECTRON
? this._pomodoroService.sessionProgress$.pipe(
withLatestFrom(this._pomodoroService.cfg$),
// we display pomodoro progress for pomodoro
filter(([progress, cfg]: [number, PomodoroConfig]) => cfg && cfg.isEnabled),
tap(([progress, cfg]) => {
(this._electronService.ipcRenderer as typeof ipcRenderer).send(IPC.SET_PROGRESS_BAR, {progress});
}),
) : EMPTY;

constructor(
private _pomodoroService: PomodoroService,
Expand Down
2 changes: 1 addition & 1 deletion src/app/features/pomodoro/store/pomodoro.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface PomodoroState {

export const initialPomodoroState: PomodoroState = {
isManualPause: true,
isBreak: undefined,
isBreak: false,
currentCycle: 0,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import { NotifyService } from '../../../core/notify/notify.service';
import { ElectronService } from '../../../core/electron/electron.service';
import { UiHelperService } from '../../ui-helper/ui-helper.service';
import { WorkContextService } from '../../work-context/work-context.service';
import { Tick } from '../time-tracking';
import { ipcRenderer } from 'electron';

const BREAK_TRIGGER_DURATION = 10 * 60 * 1000;
const PING_UPDATE_BANNER_INTERVAL = 60 * 1000;
Expand All @@ -37,7 +39,7 @@ const LOCK_SCREEN_THROTTLE = 5 * 60 * 1000;
const LOCK_SCREEN_DELAY = 30 * 1000;

// required because typescript freaks out
const reduceBreak = (acc, tick) => {
const reduceBreak = (acc: number, tick: Tick) => {
return acc + tick.duration;
};

Expand Down Expand Up @@ -181,7 +183,7 @@ export class TakeABreakService {

this._triggerLockScreenThrottledAndDelayed$.subscribe(() => {
if (IS_ELECTRON) {
this._electronService.ipcRenderer.send(IPC.LOCK_SCREEN);
(this._electronService.ipcRenderer as typeof ipcRenderer).send(IPC.LOCK_SCREEN);
}
});

Expand All @@ -193,7 +195,7 @@ export class TakeABreakService {
});

this._triggerBanner$.subscribe(([timeWithoutBreak, cfg]) => {
const msg = this._createMessage(timeWithoutBreak, cfg.takeABreak);
const msg: string = this._createMessage(timeWithoutBreak, cfg.takeABreak) as string;
if (IS_ELECTRON && cfg.takeABreak.isLockScreen) {
this._triggerLockScreenCounter$.next(true);
}
Expand Down Expand Up @@ -239,7 +241,7 @@ export class TakeABreakService {
this._triggerLockScreenCounter$.next(false);
}

private _createMessage(duration: number, cfg: TakeABreakConfig) {
private _createMessage(duration: number, cfg: TakeABreakConfig): string | undefined {
if (cfg && cfg.takeABreakMessage) {
const durationStr = msToString(duration);
return cfg.takeABreakMessage
Expand Down
13 changes: 6 additions & 7 deletions src/app/features/work-view/work-view.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { fadeAnimation } from '../../ui/animations/fade.ani';
import { PlanningModeService } from '../planning-mode/planning-mode.service';
import { T } from '../../t.const';
import { ImprovementService } from '../metric/improvement/improvement.service';
import { ProjectService } from '../project/project.service';
import { workViewProjectChangeAnimation } from '../../ui/animations/work-view-project-change.ani';
import { WorkContextService } from '../work-context/work-context.service';

Expand All @@ -36,9 +35,9 @@ const PARENT = 'PARENT';
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class WorkViewComponent implements OnInit, OnDestroy, AfterContentInit {
@Input() undoneTasks: TaskWithSubTasks[];
@Input() doneTasks: TaskWithSubTasks[];
@Input() backlogTasks: TaskWithSubTasks[];
@Input() undoneTasks: TaskWithSubTasks[] = [];
@Input() doneTasks: TaskWithSubTasks[] = [];
@Input() backlogTasks: TaskWithSubTasks[] = [];
@Input() isShowBacklog: boolean = false;

isShowTimeWorkedWithoutBreak: boolean = true;
Expand Down Expand Up @@ -66,7 +65,7 @@ export class WorkViewComponent implements OnInit, OnDestroy, AfterContentInit {
switchMap((el) => fromEvent(el, 'scroll')),
);
private _subs: Subscription = new Subscription();
private _switchListAnimationTimeout: number;
private _switchListAnimationTimeout?: number;

constructor(
public taskService: TaskService,
Expand Down Expand Up @@ -95,15 +94,15 @@ export class WorkViewComponent implements OnInit, OnDestroy, AfterContentInit {
this._dragulaService.createGroup(SUB, {
direction: 'vertical',
moves: (el, container, handle) => {
return handle.className.indexOf && handle.className.indexOf('handle-sub') > -1;
return !!handle && handle.className.indexOf && handle.className.indexOf('handle-sub') > -1;
}
});
}
if (!par) {
this._dragulaService.createGroup(PARENT, {
direction: 'vertical',
moves: (el, container, handle) => {
return handle.className.indexOf && handle.className.indexOf('handle-par') > -1;
return !!handle && handle.className.indexOf && handle.className.indexOf('handle-par') > -1;
}
});
}
Expand Down
Loading

0 comments on commit d0ff43b

Please sign in to comment.