Skip to content

Commit c66d858

Browse files
committed
♻️ refactoring
1 parent fb38c96 commit c66d858

File tree

5 files changed

+70
-44
lines changed

5 files changed

+70
-44
lines changed
Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,62 @@
11
import { Component, OnInit } from '@angular/core';
22

3+
import { SeoService } from '@app/shared/services/seo.service';
4+
35
@Component({
46
selector: 'admin-root',
57
template: '<router-outlet></router-outlet>',
68
})
79
export class AppComponent implements OnInit {
810
mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
911

12+
public constructor(private seoService: SeoService) {}
13+
14+
ngOnInit(): void {
15+
document.documentElement.setAttribute('data-theme', this.updateTheme());
16+
17+
new MutationObserver(([{ oldValue }]) => {
18+
let newValue = document.documentElement.getAttribute('data-theme')!;
19+
if (newValue !== oldValue) {
20+
try {
21+
window.localStorage.setItem('theme', newValue);
22+
} catch {}
23+
this.updateThemeWithoutTransitions(newValue);
24+
}
25+
}).observe(document.documentElement, {
26+
attributeFilter: ['data-theme'],
27+
attributeOldValue: true,
28+
});
29+
}
30+
1031
updateTheme(savedTheme: string | null = null): string {
11-
let theme = 'system'
32+
let theme = 'system';
1233
try {
1334
if (!savedTheme) {
14-
savedTheme = window.localStorage.getItem('theme')
35+
savedTheme = window.localStorage.getItem('theme');
1536
}
1637
if (savedTheme === 'dark') {
17-
theme = 'dark'
18-
document.documentElement.classList.add('dark')
38+
theme = 'dark';
39+
document.documentElement.classList.add('dark');
1940
} else if (savedTheme === 'light') {
20-
theme = 'light'
21-
document.documentElement.classList.remove('dark')
41+
theme = 'light';
42+
document.documentElement.classList.remove('dark');
2243
} else if (this.mediaQuery.matches) {
23-
document.documentElement.classList.add('dark')
44+
document.documentElement.classList.add('dark');
2445
} else {
25-
document.documentElement.classList.remove('dark')
46+
document.documentElement.classList.remove('dark');
2647
}
2748
} catch {
28-
theme = 'light'
29-
document.documentElement.classList.remove('dark')
49+
theme = 'light';
50+
document.documentElement.classList.remove('dark');
3051
}
31-
return theme
52+
return theme;
3253
}
3354

3455
updateThemeWithoutTransitions(savedTheme: string | null = null): void {
35-
this.updateTheme(savedTheme)
36-
document.documentElement.classList.add('[&_*]:!transition-none')
56+
this.updateTheme(savedTheme);
57+
document.documentElement.classList.add('[&_*]:!transition-none');
3758
window.setTimeout(() => {
38-
document.documentElement.classList.remove('[&_*]:!transition-none')
39-
}, 0)
40-
}
41-
42-
ngOnInit(): void {
43-
document.documentElement.setAttribute('data-theme', this.updateTheme())
44-
45-
new MutationObserver(([{ oldValue }]) => {
46-
let newValue = document.documentElement.getAttribute('data-theme')!
47-
if (newValue !== oldValue) {
48-
try {
49-
window.localStorage.setItem('theme', newValue)
50-
} catch {}
51-
this.updateThemeWithoutTransitions(newValue)
52-
}
53-
}).observe(document.documentElement, { attributeFilter: ['data-theme'], attributeOldValue: true })
59+
document.documentElement.classList.remove('[&_*]:!transition-none');
60+
}, 0);
5461
}
5562
}

src/app/modules/authentication/pages/forgot-password/forgot-password.component.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { Component } from '@angular/core';
1+
import { Component, OnInit } from '@angular/core';
22
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
3+
import { Meta, Title } from '@angular/platform-browser';
34
import { Store } from '@ngrx/store';
45
import { Observable } from 'rxjs';
56

7+
import { environment } from 'environments/environment';
68
import { forgotPasswordAction } from '../../store/auth.actions';
79
import {
810
selectError,
@@ -13,8 +15,8 @@ import {
1315
@Component({
1416
templateUrl: './forgot-password.component.html',
1517
})
16-
export class ForgotPasswordComponent {
17-
public form: FormGroup = this.formBuilder.group({
18+
export class ForgotPasswordComponent implements OnInit {
19+
public form: FormGroup = this.fb.group({
1820
email: ['', [Validators.required, Validators.email]],
1921
});
2022

@@ -24,7 +26,28 @@ export class ForgotPasswordComponent {
2426

2527
public loading$: Observable<boolean> = this.store.select(selectLoading);
2628

27-
constructor(private formBuilder: FormBuilder, private store: Store) {}
29+
constructor(
30+
private fb: FormBuilder,
31+
private store: Store,
32+
private meta: Meta,
33+
private title: Title
34+
) {}
35+
36+
ngOnInit(): void {
37+
this.title.setTitle($localize`Mot de passe oublié | Admin CPanel`);
38+
this.meta.updateTag({
39+
property: 'og:url',
40+
content: environment.baseUrl + '/forgot-password',
41+
});
42+
this.meta.updateTag({
43+
property: 'og:title',
44+
content: $localize`Mot de passe oublié | Admin CPanel`,
45+
});
46+
this.meta.updateTag({
47+
property: 'og:description',
48+
content: $localize`Réinitialisez votre mot de passe`,
49+
});
50+
}
2851

2952
public submit() {
3053
if (this.form.valid) {

src/app/modules/authentication/pages/login/login.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ <h2 class="mt-6 text-3xl font-semibold text-slate-900 dark:text-white" i18n>Conn
3636

3737
<div class="flex items-center justify-between">
3838
<label for="remember-me" class="flex items-center cursor-pointer">
39-
<input id="remember-me" name="remember-me" type="checkbox" class="w-4 h-4 rounded text-primary-600 border-slate-300 focus:ring-primary-500">
39+
<input id="remember-me" name="remember-me" type="checkbox" class="w-4 h-4 bg-white rounded text-primary-600 border-slate-300 focus:ring-primary-500 dark:bg-gray-800 dark:border-slate-700 dark:focus:ring-offset-gray-800">
4040
<span class="block ml-2 text-sm text-slate-700 dark:text-slate-300" i18n>Se souvenir de moi</span>
4141
</label>
4242

src/app/modules/authentication/pages/login/login.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
templateUrl: './login.component.html',
1515
})
1616
export class LoginComponent {
17-
public form: FormGroup = this.formBuilder.group({
17+
public form: FormGroup = this.fb.group({
1818
email: ['', [Validators.required, Validators.email]],
1919
password: ['', Validators.required],
2020
});
@@ -25,7 +25,7 @@ export class LoginComponent {
2525

2626
public loading$: Observable<boolean> = this.store.select(selectLoading);
2727

28-
constructor(private formBuilder: FormBuilder, private store: Store) {}
28+
constructor(private fb: FormBuilder, private store: Store) {}
2929

3030
public submit() {
3131
if (this.form.valid) {
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component } from '@angular/core';
2+
import { Title } from '@angular/platform-browser';
23

34
@Component({
45
templateUrl: './dashboard.component.html',
56
})
6-
export class DashboardComponent implements OnInit {
7-
8-
constructor() { }
9-
10-
ngOnInit(): void {
11-
}
12-
7+
export class DashboardComponent {
8+
constructor(private title: Title) {}
139
}

0 commit comments

Comments
 (0)