70 lines
2.4 KiB
TypeScript
70 lines
2.4 KiB
TypeScript
import {Component, inject, OnInit, signal} from '@angular/core';
|
|
import {IonicModule, ToastController} from "@ionic/angular";
|
|
import {addIcons} from "ionicons";
|
|
import {personOutline, addOutline, logOutOutline, settingsOutline, chevronForwardOutline, swapHorizontalOutline} from "ionicons/icons";
|
|
import {TitlePartComponent} from "../../components/title-part/title-part.component";
|
|
import {ChallengeCardComponent} from "../../components/challenge-card/challenge-card.component";
|
|
import {GetRandomChallengeDto, GetUserDetailsDto, RandomchallengesService, UsersService} from "../../services/api";
|
|
import {firstValueFrom} from "rxjs";
|
|
|
|
addIcons({
|
|
'profile': personOutline,
|
|
'add': addOutline,
|
|
'settings': settingsOutline,
|
|
'logout': logOutOutline,
|
|
'chevron': chevronForwardOutline,
|
|
'swap': swapHorizontalOutline,
|
|
});
|
|
|
|
@Component({
|
|
selector: 'app-home',
|
|
templateUrl: './home.component.html',
|
|
styleUrls: ['./home.component.scss'],
|
|
imports: [
|
|
IonicModule,
|
|
TitlePartComponent,
|
|
ChallengeCardComponent
|
|
]
|
|
})
|
|
export class HomeComponent implements OnInit {
|
|
private randomChallengeService = inject(RandomchallengesService)
|
|
private toastCtrl = inject(ToastController);
|
|
private usersService = inject(UsersService)
|
|
|
|
randomChallenge = signal<GetRandomChallengeDto>({});
|
|
user = signal<GetUserDetailsDto>({})
|
|
|
|
isModalOpen = false;
|
|
options = [1, 2, 3, 4, 5];
|
|
|
|
async ngOnInit() {
|
|
try {
|
|
const randomChallenge = await firstValueFrom(this.randomChallengeService.generateRandomChallengeEndpoint());
|
|
this.randomChallenge.set(randomChallenge);
|
|
} catch {
|
|
const toast = await this.toastCtrl.create({
|
|
message: 'Impossible de générer un défi aléatoire',
|
|
duration: 2000,
|
|
color: 'danger'
|
|
});
|
|
await toast.present();
|
|
}
|
|
}
|
|
|
|
async setOpen(isOpen: boolean) {
|
|
if (isOpen) {
|
|
try {
|
|
const userInfo = await firstValueFrom(this.usersService.getUserDetailsEndpoint());
|
|
this.user.set(userInfo);
|
|
} catch (e) {
|
|
const toast = await this.toastCtrl.create({
|
|
message: 'Impossible de charger les données du joueur',
|
|
duration: 2000,
|
|
color: 'danger'
|
|
});
|
|
await toast.present();
|
|
}
|
|
}
|
|
this.isModalOpen = isOpen;
|
|
}
|
|
} |