From 30a417ecf90e22d7f5509188a4bb40e55fb2504e Mon Sep 17 00:00:00 2001 From: William Brawner Date: Fri, 2 Oct 2020 14:57:06 +0000 Subject: [PATCH] Fix occurences of ExpressionChangedAfterItHasBeenCheckedError --- src/app/app.component.ts | 48 ++++++++++++++----- .../add-edit-budget.component.ts | 4 +- .../budget-details.component.ts | 4 +- src/app/budgets/budget.component.ts | 4 +- src/app/categories/categories.component.ts | 4 +- .../category-details.component.ts | 8 ++-- .../category-form/category-form.component.ts | 4 +- .../edit-category/edit-category.component.ts | 4 +- .../add-edit-transaction.component.ts | 4 +- .../transactions/transactions.component.ts | 4 +- src/app/users/login/login.component.ts | 4 +- src/app/users/register/register.component.ts | 4 +- 12 files changed, 61 insertions(+), 35 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index b9edcc4..8fc7358 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,4 +1,4 @@ -import { Component, Inject, ApplicationRef } from '@angular/core'; +import { Component, Inject, ApplicationRef, ChangeDetectorRef } from '@angular/core'; import { Location } from '@angular/common'; import { User } from './users/user'; import { TWIGS_SERVICE, TwigsService } from './shared/twigs.service'; @@ -31,6 +31,7 @@ export class AppComponent { private activatedRoute: ActivatedRoute, private appRef: ApplicationRef, private updates: SwUpdate, + private changeDetector: ChangeDetectorRef, ) { if (this.cookieService.check('Authorization')) { this.twigsService.getProfile().subscribe(user => { @@ -43,16 +44,26 @@ export class AppComponent { this.router.navigateByUrl("/login") } - updates.available.subscribe(event => { - console.log('current version is', event.current); - console.log('available version is', event.available); - // TODO: Prompt user to click something to update - updates.activateUpdate(); - }); - updates.activated.subscribe(event => { - console.log('old version was', event.previous); - console.log('new version is', event.current); - }); + updates.available.subscribe( + event => { + console.log('current version is', event.current); + console.log('available version is', event.available); + // TODO: Prompt user to click something to update + updates.activateUpdate(); + }, + err => { + + } + ); + updates.activated.subscribe( + event => { + console.log('old version was', event.previous); + console.log('new version is', event.current); + }, + err => { + + } + ); const appIsStable$ = appRef.isStable.pipe(first(isStable => isStable === true)); const everySixHours$ = interval(6 * 60 * 60 * 1000); @@ -82,4 +93,19 @@ export class AppComponent { this.location.go('/'); }); } + + setActionable(actionable: Actionable): void { + this.actionable = actionable; + this.changeDetector.detectChanges(); + } + + setBackEnabled(enabled: boolean): void { + this.backEnabled = enabled; + this.changeDetector.detectChanges(); + } + + setTitle(title: string) { + this.title = title; + this.changeDetector.detectChanges(); + } } diff --git a/src/app/budgets/add-edit-budget/add-edit-budget.component.ts b/src/app/budgets/add-edit-budget/add-edit-budget.component.ts index 37cc652..532eed4 100644 --- a/src/app/budgets/add-edit-budget/add-edit-budget.component.ts +++ b/src/app/budgets/add-edit-budget/add-edit-budget.component.ts @@ -20,8 +20,8 @@ export class AddEditBudgetComponent { private app: AppComponent, @Inject(TWIGS_SERVICE) private twigsService: TwigsService, ) { - this.app.title = this.title; - this.app.backEnabled = true; + this.app.setTitle(this.title) + this.app.setBackEnabled(true); this.users = [new UserPermission(this.app.user.value.id, Permission.OWNER)]; } diff --git a/src/app/budgets/budget-details/budget-details.component.ts b/src/app/budgets/budget-details/budget-details.component.ts index e805446..b2e1a1b 100644 --- a/src/app/budgets/budget-details/budget-details.component.ts +++ b/src/app/budgets/budget-details/budget-details.component.ts @@ -39,7 +39,7 @@ export class BudgetDetailsComponent implements OnInit { ngOnInit() { this.getBudget(); - this.app.backEnabled = false; + this.app.setBackEnabled(false); this.categoryBalances = new Map(); } @@ -47,7 +47,7 @@ export class BudgetDetailsComponent implements OnInit { const id = Number.parseInt(this.route.snapshot.paramMap.get('id')); this.twigsService.getBudget(id) .subscribe(budget => { - this.app.title = budget.name; + this.app.setTitle(budget.name) this.budget = budget; this.getBalance(); this.getTransactions(); diff --git a/src/app/budgets/budget.component.ts b/src/app/budgets/budget.component.ts index c1a3796..54bf813 100644 --- a/src/app/budgets/budget.component.ts +++ b/src/app/budgets/budget.component.ts @@ -20,8 +20,8 @@ export class BudgetsComponent implements OnInit { ) { } ngOnInit() { - this.app.backEnabled = false; - this.app.title = 'Budgets'; + this.app.setBackEnabled(false); + this.app.setTitle('Budgets') this.app.user.subscribe( user => { if (!user) { diff --git a/src/app/categories/categories.component.ts b/src/app/categories/categories.component.ts index 53e30cf..b08d2db 100644 --- a/src/app/categories/categories.component.ts +++ b/src/app/categories/categories.component.ts @@ -26,8 +26,8 @@ export class CategoriesComponent implements OnInit { ngOnInit() { this.budgetId = Number.parseInt(this.route.snapshot.paramMap.get('budgetId')); - this.app.title = 'Categories'; - this.app.backEnabled = true; + this.app.setTitle('Categories') + this.app.setBackEnabled(true); this.getCategories(); this.categoryBalances = new Map(); } diff --git a/src/app/categories/category-details/category-details.component.ts b/src/app/categories/category-details/category-details.component.ts index 95e663a..ee49f1f 100644 --- a/src/app/categories/category-details/category-details.component.ts +++ b/src/app/categories/category-details/category-details.component.ts @@ -33,13 +33,13 @@ export class CategoryDetailsComponent implements OnInit, OnDestroy, Actionable { } ngOnInit() { - this.app.backEnabled = true; - this.app.actionable = this; + this.app.setBackEnabled(true); + this.app.setActionable(this) this.getCategory(); } ngOnDestroy() { - this.app.actionable = null; + this.app.setActionable(null) } getCategory(): void { @@ -47,7 +47,7 @@ export class CategoryDetailsComponent implements OnInit, OnDestroy, Actionable { this.twigsService.getCategory(id) .subscribe(category => { category.amount /= 100; - this.app.title = category.title; + this.app.setTitle(category.title) this.category = category; this.budgetId = category.budgetId; }); diff --git a/src/app/categories/category-form/category-form.component.ts b/src/app/categories/category-form/category-form.component.ts index 957fe4e..64f1d6c 100644 --- a/src/app/categories/category-form/category-form.component.ts +++ b/src/app/categories/category-form/category-form.component.ts @@ -20,8 +20,8 @@ export class CategoryFormComponent implements OnInit { ) { } ngOnInit() { - this.app.backEnabled = true; - this.app.title = this.title; + this.app.setBackEnabled(true); + this.app.setTitle(this.title) } save(): void { diff --git a/src/app/categories/edit-category/edit-category.component.ts b/src/app/categories/edit-category/edit-category.component.ts index f3110ba..3c413c6 100644 --- a/src/app/categories/edit-category/edit-category.component.ts +++ b/src/app/categories/edit-category/edit-category.component.ts @@ -21,7 +21,7 @@ export class EditCategoryComponent implements OnInit { ) { } ngOnInit(): void { - this.app.backEnabled = true; + this.app.setBackEnabled(true); this.getCategory(); } @@ -30,7 +30,7 @@ export class EditCategoryComponent implements OnInit { this.twigsService.getCategory(id) .subscribe(category => { category.amount /= 100; - this.app.title = category.title; + this.app.setTitle(category.title) this.category = category; this.budgetId = category.budgetId; }); diff --git a/src/app/transactions/add-edit-transaction/add-edit-transaction.component.ts b/src/app/transactions/add-edit-transaction/add-edit-transaction.component.ts index ab038c7..189b488 100644 --- a/src/app/transactions/add-edit-transaction/add-edit-transaction.component.ts +++ b/src/app/transactions/add-edit-transaction/add-edit-transaction.component.ts @@ -27,8 +27,8 @@ export class AddEditTransactionComponent implements OnInit, OnChanges { ) { } ngOnInit() { - this.app.title = this.title; - this.app.backEnabled = true; + this.app.setTitle(this.title) + this.app.setBackEnabled(true); let d: Date, expense: boolean; if (this.currentTransaction) { d = new Date(this.currentTransaction.date); diff --git a/src/app/transactions/transactions.component.ts b/src/app/transactions/transactions.component.ts index afbda28..4e49dca 100644 --- a/src/app/transactions/transactions.component.ts +++ b/src/app/transactions/transactions.component.ts @@ -20,7 +20,7 @@ export class TransactionsComponent implements OnInit { ngOnInit() { this.budgetId = Number.parseInt(this.route.snapshot.paramMap.get('budgetId')); this.categoryId = Number.parseInt(this.route.snapshot.queryParamMap.get('categoryId')); - this.app.backEnabled = true; - this.app.title = 'Transactions'; + this.app.setBackEnabled(true); + this.app.setTitle('Transactions') } } diff --git a/src/app/users/login/login.component.ts b/src/app/users/login/login.component.ts index 495a1ce..33bef40 100644 --- a/src/app/users/login/login.component.ts +++ b/src/app/users/login/login.component.ts @@ -22,8 +22,8 @@ export class LoginComponent implements OnInit { ) { } ngOnInit() { - this.app.title = 'Login'; - this.app.backEnabled = true; + this.app.setTitle('Login') + this.app.setBackEnabled(true); } login(): void { diff --git a/src/app/users/register/register.component.ts b/src/app/users/register/register.component.ts index 8a09ea0..4f2e231 100644 --- a/src/app/users/register/register.component.ts +++ b/src/app/users/register/register.component.ts @@ -23,8 +23,8 @@ export class RegisterComponent implements OnInit { ) { } ngOnInit() { - this.app.title = 'Register'; - this.app.backEnabled = true; + this.app.setTitle('Register') + this.app.setBackEnabled(true); } register(): void {