From 5bdaeb2eb2ca03e890cbcf83b4e2317bf842f7ff Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 30 Dec 2019 00:53:06 +0100 Subject: [PATCH] fixed another darkmode bug, settingsservice does the http now --- .../main-navigation.component.ts | 19 +++++-------------- src/app/services/settings/settings.service.ts | 10 ++++++++++ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/app/components/main-navigation/main-navigation.component.ts b/src/app/components/main-navigation/main-navigation.component.ts index b6ca072..9eb5f52 100644 --- a/src/app/components/main-navigation/main-navigation.component.ts +++ b/src/app/components/main-navigation/main-navigation.component.ts @@ -3,7 +3,6 @@ import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout'; import { Observable } from 'rxjs'; import { map, shareReplay } from 'rxjs/operators'; import { DatasharingService } from '../../services/datasharing.service'; -import { SelfService } from '../../services/selfservice/self.service'; import { RequestService } from '../../services/request/request.service'; import { SettingsService } from '../../services/settings/settings.service'; import { environment } from 'src/environments/environment'; @@ -23,7 +22,6 @@ export class MainNavigationComponent implements OnInit { constructor( public overlayContainer: OverlayContainer, private data: DatasharingService, - private selfservice: SelfService, private settingsService: SettingsService, private requestservice: RequestService, private breakpointObserver: BreakpointObserver, @@ -75,6 +73,8 @@ export class MainNavigationComponent implements OnInit { if (this.user.darkmode === true && this.lighttheme) { this.toggleTheme(); this.darkModeButtonChecked = true; + } else if (!this.user.darkmode && !this.lighttheme) { + this.settingsService.setDarkModeActive(true); } this.updateLinks(); }); @@ -86,30 +86,21 @@ export class MainNavigationComponent implements OnInit { this.overlay.classList.add('light-theme'); this.onSetTheme('light-theme'); this.lighttheme = true; - this.setDarkModeActive(false); + this.settingsService.setDarkModeActive(false); } else if (this.overlay.classList.contains('light-theme')) { this.overlay.classList.remove('light-theme'); this.overlay.classList.add('dark-theme'); this.onSetTheme('dark-theme'); this.lighttheme = false; - this.setDarkModeActive(true); + this.settingsService.setDarkModeActive(true); } else { this.overlay.classList.add('dark-theme'); this.onSetTheme('dark-theme'); this.lighttheme = false; - this.setDarkModeActive(true); + this.settingsService.setDarkModeActive(true); } } - setDarkModeActive(active: boolean) { - const url = environment.graphQLUrl; - const headers = new Headers(); - headers.set('Content-Type', 'application/json'); - const body = this.settingsService.buildJsonDarkMode('darkmode: ' + '\'' + active + '\''); - this.http.post(url, body).subscribe(response => { - console.log(response.text()); }); - } - updateLinks() { this.navLinksLoggedIn = [ { path: '', label: 'Home' }, diff --git a/src/app/services/settings/settings.service.ts b/src/app/services/settings/settings.service.ts index 8dfb168..8ee9373 100644 --- a/src/app/services/settings/settings.service.ts +++ b/src/app/services/settings/settings.service.ts @@ -1,6 +1,7 @@ import {Injectable} from '@angular/core'; import {Http} from '@angular/http'; import { User } from 'src/app/models/user'; +import { environment } from 'src/environments/environment'; @Injectable({ providedIn: 'root' @@ -11,6 +12,15 @@ export class SettingsService { constructor(private http: Http) { } + setDarkModeActive(active: boolean) { + const url = environment.graphQLUrl; + const headers = new Headers(); + headers.set('Content-Type', 'application/json'); + const body = this.buildJsonDarkMode('darkmode: ' + '\'' + active + '\''); + this.http.post(url, body).subscribe(response => { + console.log(response.text()); }); + } + public buildJsonDarkMode(setting_: string): any { const body = { query: `mutation($setting: String!) {