Skip to content

Commit 2c4f37d

Browse files
committed
Cleaner code for visual settings #18
* Added new constants for the fonts: `MAX_FONT_SIZE`, `DEFAULT_FONT_SIZE` and `BASE_FONT_SIZE` in fonts.ts * Font sizes are now calculated with a simple formula based on user font size * Deleted commented code in header.component.html
1 parent ecd68ff commit 2c4f37d

File tree

7 files changed

+19
-25
lines changed

7 files changed

+19
-25
lines changed

.idea/runConfigurations/everything.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/src/app/app.component.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<app-header [ngStyle]="setFont()"></app-header>
2-
<div class="content" [ngStyle]="setFont()">
1+
<app-header [ngStyle]="setStyle()"></app-header>
2+
<div class="content" [ngStyle]="setStyle()">
33
<router-outlet></router-outlet>
44
</div>

frontend/src/app/app.component.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component } from "@angular/core";
22
import { UserService } from "../services/user.service";
3-
import fonts from "../fonts";
3+
import { BASE_FONT_SIZE, DEFAULT_FONT_SIZE } from "../fonts";
44

55
@Component({
66
selector: "app-root",
@@ -10,25 +10,26 @@ import fonts from "../fonts";
1010
export class AppComponent
1111
{
1212
title = "starter-quiz";
13-
fontSizes = ['22px', '25px', '28px'];
1413
public fontSize: string;
1514
public font: string;
1615
constructor(private userService: UserService)
1716
{
1817
}
1918

19+
toPixels(n: number): string {
20+
return n*3+BASE_FONT_SIZE+'px';
21+
}
22+
2023
ngOnInit(){
2124
this.userService.currentUser
2225
.subscribe(user =>
2326
{
24-
this.fontSize = this.fontSizes[user?.fontSize ?? 1];
27+
this.fontSize = this.toPixels(user?.fontSize ?? DEFAULT_FONT_SIZE);
2528
this.font = user?.font ?? "Arial";
26-
27-
document.querySelector('html').style.fontSize = this.fontSize;
2829
});
2930
}
3031

31-
setFont() {
32-
return {'font-family': this.font};
32+
setStyle() {
33+
return {'font-family': this.font, 'font-size': this.fontSize};
3334
}
3435
}

frontend/src/app/header/header.component.html

-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<div class="header d-flex justify-content-between " *ngIf="user != null">
22

3-
43
<div class="epsilon p-2">
54
<button class="btn btn-xs btn-green" (click)="accueil()">
65
<i class="bi-house"></i>
@@ -15,15 +14,6 @@
1514
</div>
1615

1716
<div class="epsilon ml-auto p-2 d-flex align-items-center">
18-
<!-- Changer la taille de police-->
19-
<!-- <button class="btn btn-xs btn-green ml-3" (click)="changeFont(true)">-->
20-
<!-- <i class="bi-plus"></i>-->
21-
<!-- <span>Augmenter</span>-->
22-
<!-- </button>-->
23-
<!-- <button class="btn btn-xs btn-green" (click)="changeFont(false)">-->
24-
<!-- <i class="bi-dash"></i>-->
25-
<!-- <span>Diminuer</span>-->
26-
<!-- </button>-->
2717
<button class="btn btn-xs btn-green" (click)="toggleParams()">
2818
<i class="bi-file-earmark-font"></i>
2919
<span>Taille et Police</span>

frontend/src/app/header/header.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { UserService } from "../../services/user.service";
33
import { User } from "../../models/user.model";
44
import { Router } from "@angular/router";
55
import { FormControl } from "@angular/forms";
6-
import fonts from "../../fonts";
6+
import {fonts} from "../../fonts";
77

88

99
@Component({

frontend/src/fonts.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
export default ["Arial", "Noto Sans JP"];
1+
export let fonts = ["Arial", "Noto Sans JP"];
2+
export let MAX_FONT_SIZE = 6;
3+
export let DEFAULT_FONT_SIZE = 1;
4+
export let BASE_FONT_SIZE = 22;

frontend/src/services/user.service.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { User } from "../models/user.model";
44
import { HttpClient } from "@angular/common/http";
55
import { map } from "rxjs/operators";
66
import { Observable } from "rxjs/Rx";
7-
import fonts from "../fonts";
7+
import { DEFAULT_FONT_SIZE, fonts, MAX_FONT_SIZE } from "../fonts";
88

99
@Injectable({
1010
providedIn: "root"
@@ -110,15 +110,15 @@ export class UserService
110110

111111
if (p)
112112
{
113-
if (this.user.fontSize >= 2)
113+
if (this.user.fontSize >= MAX_FONT_SIZE)
114114
{
115115
return;
116116
}
117117
this.user.fontSize++;
118118
}
119119
else
120120
{
121-
if (this.user.fontSize <= 0)
121+
if (this.user.fontSize <= DEFAULT_FONT_SIZE)
122122
{
123123
return;
124124
}

0 commit comments

Comments
 (0)