Added functions to send and see proof before valid participation from random challenge

This commit is contained in:
2026-04-12 19:06:52 +01:00
parent 4d5380b40c
commit 6ab77fe800
59 changed files with 1067 additions and 1650 deletions
@@ -1,16 +1,74 @@
import {Component, input} from '@angular/core';
import {IonicModule} from "@ionic/angular";
import {Component, inject, input, signal, viewChild} from '@angular/core';
import {IonicModule, ToastController} from "@ionic/angular";
import {GetRandomChallengeDto, RandomchallengesService} from "../../services/api";
import {firstValueFrom} from "rxjs";
import {TooltipComponent} from "../tooltip/tooltip.component";
import {ProofFormComponent} from "../proof-form/proof-form.component";
import {SignOnFormComponent} from "../sign-on-form/sign-on-form.component";
@Component({
selector: 'app-challenge-card',
templateUrl: './challenge-card.component.html',
styleUrls: ['./challenge-card.component.scss'],
imports: [
IonicModule
IonicModule,
TooltipComponent,
ProofFormComponent
]
})
export class ChallengeCardComponent {
private randomChallengesService = inject(RandomchallengesService);
private toastCtrl = inject(ToastController);
action = input.required<string>();
tag = input.required<string>();
color = input.required<string>();
data = input.required<GetRandomChallengeDto>();
selectedChallenge = signal<GetRandomChallengeDto>(null);
proof = viewChild<ProofFormComponent>('proofForm');
isModalOpen = false;
async setOpen(isOpen: boolean, randomChallengeId: number) {
if (isOpen) {
try {
const userInfo = await firstValueFrom(this.randomChallengesService.getRandomChallengeEndpoint(randomChallengeId));
this.selectedChallenge.set(userInfo);
this.isModalOpen = isOpen;
} catch {
const toast = await this.toastCtrl.create({
message: 'Impossible de charger les données du défi',
duration: 2000,
color: 'danger'
});
await toast.present();
}
}
}
async sendProof(randomChallengeId: number) {
const file = this.proof().proofForm.value.proof;
try {
await firstValueFrom(this.randomChallengesService.patchProofEndpoint(randomChallengeId, file));
this.isModalOpen = false;
const toast = await this.toastCtrl.create({
message: 'La preuve de ta réussite a bien été déposée',
duration: 2000,
color: 'success'
});
await toast.present();
} catch(err) {
const toast = await this.toastCtrl.create({
message: 'Impossible de déposer ta preuve',
duration: 2000,
color: 'danger'
});
await toast.present();
console.log(err)
}
}
}