dark theme is stored in user settings now

master
Max 5 years ago
parent 33fe3ae788
commit 0a87c3431f

@ -58,7 +58,7 @@
</div> </div>
</nav> </nav>
<div id="menu-button-box"> <div id="menu-button-box">
<span class="mat-button" [hidden]="!loggedIn" fxShow="true" fxHide.lt-md="true" routerLink={{profileUrl}}>Hello, {{user.username}}</span> <span class="mat-button" *ngIf="loggedIn" fxShow="true" fxHide.lt-md="true" routerLink={{profileUrl}}>Hello, {{user.username}}</span>
<button mat-icon-button [matMenuTriggerFor]="requestMenu" [disabled]="!loggedIn" id="menu-button"> <button mat-icon-button [matMenuTriggerFor]="requestMenu" [disabled]="!loggedIn" id="menu-button">
<mat-icon [matBadge]="user.receivedRequests.length" [matBadgeHidden]="!(user.receivedRequests.length > 0)" matBadgeColor="accent">notifications</mat-icon> <mat-icon [matBadge]="user.receivedRequests.length" [matBadgeHidden]="!(user.receivedRequests.length > 0)" matBadgeColor="accent">notifications</mat-icon>
</button> </button>
@ -84,7 +84,8 @@
<mat-slide-toggle <mat-slide-toggle
color="primary" color="primary"
class="theme-button" class="theme-button"
(change)="toggleTheme()"> (change)="toggleTheme()"
[checked]="darkModeButtonChecked">
dark mode dark mode
</mat-slide-toggle> </mat-slide-toggle>
</button> </button>

@ -5,6 +5,7 @@ import { map, shareReplay } from 'rxjs/operators';
import { DatasharingService } from '../../services/datasharing.service'; import { DatasharingService } from '../../services/datasharing.service';
import { SelfService } from '../../services/selfservice/self.service'; import { SelfService } from '../../services/selfservice/self.service';
import { RequestService } from '../../services/request/request.service'; import { RequestService } from '../../services/request/request.service';
import { SettingsService } from '../../services/settings/settings.service';
import { environment } from 'src/environments/environment'; import { environment } from 'src/environments/environment';
import { Levellist } from 'src/app/models/levellist'; import { Levellist } from 'src/app/models/levellist';
import { Http } from '@angular/http'; import { Http } from '@angular/http';
@ -23,6 +24,7 @@ export class MainNavigationComponent implements OnInit {
public overlayContainer: OverlayContainer, public overlayContainer: OverlayContainer,
private data: DatasharingService, private data: DatasharingService,
private selfservice: SelfService, private selfservice: SelfService,
private settingsService: SettingsService,
private requestservice: RequestService, private requestservice: RequestService,
private breakpointObserver: BreakpointObserver, private breakpointObserver: BreakpointObserver,
private http: Http, private router: Router private http: Http, private router: Router
@ -38,6 +40,7 @@ export class MainNavigationComponent implements OnInit {
points: number; points: number;
profileUrl = '/profile/1'; profileUrl = '/profile/1';
darkModeButtonChecked = false;
lighttheme = true; lighttheme = true;
overlay; overlay;
@ -69,6 +72,10 @@ export class MainNavigationComponent implements OnInit {
this.level = this.levellist.getLevelName(user.level); this.level = this.levellist.getLevelName(user.level);
this.points = user.points; this.points = user.points;
this.profileUrl = '/profile/' + this.userId; this.profileUrl = '/profile/' + this.userId;
if (this.user.darkmode === true && this.lighttheme) {
this.toggleTheme();
this.darkModeButtonChecked = true;
}
this.updateLinks(); this.updateLinks();
}); });
} }
@ -78,15 +85,31 @@ export class MainNavigationComponent implements OnInit {
this.overlay.classList.remove('dark-theme'); this.overlay.classList.remove('dark-theme');
this.overlay.classList.add('light-theme'); this.overlay.classList.add('light-theme');
this.onSetTheme('light-theme'); this.onSetTheme('light-theme');
this.lighttheme = true;
this.setDarkModeActive(false);
} else if (this.overlay.classList.contains('light-theme')) { } else if (this.overlay.classList.contains('light-theme')) {
this.overlay.classList.remove('light-theme'); this.overlay.classList.remove('light-theme');
this.overlay.classList.add('dark-theme'); this.overlay.classList.add('dark-theme');
this.onSetTheme('dark-theme'); this.onSetTheme('dark-theme');
this.lighttheme = false;
this.setDarkModeActive(true);
} else { } else {
this.overlay.classList.add('dark-theme'); this.overlay.classList.add('dark-theme');
this.onSetTheme('dark-theme'); this.onSetTheme('dark-theme');
this.lighttheme = false;
this.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() { updateLinks() {
this.navLinksLoggedIn = [ this.navLinksLoggedIn = [
{ path: '', label: 'Home' }, { path: '', label: 'Home' },

@ -10,7 +10,6 @@
width: 100% width: 100%
margin-top: 0.5em margin-top: 0.5em
cursor: pointer cursor: pointer
.mat-card-subtitle .mat-card-subtitle
margin: 0 margin: 0

@ -11,6 +11,8 @@ export class User {
level: number; level: number;
profilePicture: string; profilePicture: string;
darkmode = false;
friends: FriendInfo[] = new Array(); friends: FriendInfo[] = new Array();
groupIDs: number[]; groupIDs: number[];
chatIDs: number[]; chatIDs: number[];

@ -61,7 +61,9 @@ export class LoginService {
friendRequest.senderHandle = request.sender.handle; friendRequest.senderHandle = request.sender.handle;
user.receivedRequests.push(friendRequest); user.receivedRequests.push(friendRequest);
} }
console.log(user.friends); if (JSON.parse(response.data.login.settings).darkmode === 'true') {
user.darkmode = true;
}
this.data.changeUserInfo(user); this.data.changeUserInfo(user);
} }
@ -87,7 +89,8 @@ export class LoginService {
}, },
chats{ chats{
id id
} },
settings
} }
}` }`
, variables: { , variables: {

@ -64,6 +64,9 @@ export class RegisterService {
friendRequest.senderHandle = request.sender.handle; friendRequest.senderHandle = request.sender.handle;
user.receivedRequests.push(friendRequest); user.receivedRequests.push(friendRequest);
} }
if (JSON.parse(response.data.login.settings).darkmode === 'true') {
user.darkmode = true;
}
this.data.changeUserInfo(user); this.data.changeUserInfo(user);
} }
@ -84,7 +87,8 @@ export class RegisterService {
level level
}, },
groups{id}, groups{id},
chats{id} chats{id},
settings
} }
}`, variables: { }`, variables: {
email: registration.email, email: registration.email,

@ -69,6 +69,9 @@ export class SelfService {
friendRequest.senderHandle = request.sender.handle; friendRequest.senderHandle = request.sender.handle;
user.receivedRequests.push(friendRequest); user.receivedRequests.push(friendRequest);
} }
if (JSON.parse(response.data.login.settings).darkmode === 'true') {
user.darkmode = true;
}
this.data.changeUserInfo(user); this.data.changeUserInfo(user);
} }
public fakeLogin() { public fakeLogin() {
@ -114,7 +117,8 @@ export class SelfService {
}, },
chats{ chats{
id id
} },
settings
} }
}`, variables: { }`, variables: {
}}; }};

@ -0,0 +1,12 @@
import { TestBed } from '@angular/core/testing';
import { SettingsService } from './settings.service';
describe('SettingsService', () => {
beforeEach(() => TestBed.configureTestingModule({}));
it('should be created', () => {
const service: SettingsService = TestBed.get(SettingsService);
expect(service).toBeTruthy();
});
});

@ -0,0 +1,25 @@
import {Injectable} from '@angular/core';
import {Http} from '@angular/http';
import { User } from 'src/app/models/user';
@Injectable({
providedIn: 'root'
})
export class SettingsService {
users: Array<User>;
constructor(private http: Http) {
}
public buildJsonDarkMode(setting_: string): any {
const body = {
query: `mutation($setting: String!) {
setUserSettings(settings: $setting)
}`
, variables: {
setting: setting_
}
};
return body;
}
}
Loading…
Cancel
Save