Skip to content

Commit

Permalink
all: smoother challenge validation (fixes #7822) (#7824)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <[email protected]>
  • Loading branch information
Mutugiii and dogi authored Nov 21, 2024
1 parent 1c7b955 commit 544d562
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "planet",
"license": "AGPL-3.0",
"version": "0.15.57",
"version": "0.15.58",
"myplanet": {
"latest": "v0.21.2",
"min": "v0.20.2"
Expand Down
4 changes: 2 additions & 2 deletions src/app/shared/dialogs/dialogs-announcement.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<mat-icon color="primary">
{{ getStatus('hasPost') ? 'check_circle' : 'radio_button_unchecked' }}
</mat-icon>
<span>Comparte tu opinión en Nuestras Voces. <br><span>{{getStatus('amountEarned')}} de 5 Voces diarias</span> </span>
<span>Comparte tu opinión en Nuestras Voces. <br><span>{{getStatus('userPosts')}} de 5 Voces diarias</span> </span>
<a *ngIf="getStatus('joinedCourse') && getStatus('surveyComplete') && !getStatus('hasPost'); else dailyVoices" mat-button mat-raised-button color="primary" type="button" (click)="chatNShare()">
Chatea y comparte
</a>
Expand All @@ -58,7 +58,7 @@
<div
*ngFor="let dot of [0, 1, 2, 3, 4]; let i = index"
class="dot"
[ngClass]="{ completed: i < getStatus('amountEarned') }"
[ngClass]="{ completed: i < getStatus('userPosts') }"
></div>
</div>
</ng-template>
Expand Down
15 changes: 9 additions & 6 deletions src/app/shared/dialogs/dialogs-announcement.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export class DialogsAnnouncementComponent implements OnInit, OnDestroy {
startDate = new Date(2024, 9, 31);
endDate = new Date(2024, 11, 1);
isLoading = true;
submissionValue = 5;
goal = 500;

constructor(
public dialogRef: MatDialogRef<DialogsAnnouncementComponent>,
Expand Down Expand Up @@ -195,7 +197,7 @@ export class DialogsAnnouncementComponent implements OnInit, OnDestroy {
if (!this.groupSummary.some(m => m.name === member.name)) {
this.groupSummary.push({
...member,
amountEarned: userAmount
userPosts: userAmount
});
}
}
Expand All @@ -204,7 +206,7 @@ export class DialogsAnnouncementComponent implements OnInit, OnDestroy {
// Individual stats
this.userStatusService.updateStatus('surveyComplete', this.hasCompletedSurvey(this.currentUserName));
this.userStatusService.updateStatus('hasPost', this.hasSubmittedVoice(news, this.currentUserName) > 0);
this.userStatusService.updateStatus('amountEarned', this.hasSubmittedVoice(news, this.currentUserName));
this.userStatusService.updateStatus('userPosts', this.hasSubmittedVoice(news, this.currentUserName));
this.enrolledMembers.some(member => {
if (member.name === this.currentUserName) {
this.userStatusService.updateStatus('joinedCourse', this.hasEnrolledCourse(member));
Expand All @@ -216,16 +218,17 @@ export class DialogsAnnouncementComponent implements OnInit, OnDestroy {
}

getTotalMoneyEarned(): number {
return this.groupSummary.reduce((total, member) => {
const amount = Number(member.amountEarned);
const totalEarned = this.groupSummary.reduce((total, member) => {
const amount = Number(member.userPosts * this.submissionValue);
return total + (isNaN(amount) ? 0 : amount);
}, 0);

return Math.min(totalEarned, this.goal);
}

getGoalPercentage(): number {
const goal = 500;
const totalMoneyEarned = this.getTotalMoneyEarned();
return (totalMoneyEarned / goal) * 100;
return (totalMoneyEarned / this.goal) * 100;
}

getStatus(key: string) {
Expand Down
4 changes: 2 additions & 2 deletions src/app/shared/user-challenge-status.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class UserChallengeStatusService {
joinedCourse: false,
surveyComplete: false,
hasPost: false,
amountEarned: 0
userPosts: 0
};

updateStatus(key: string, value: boolean | number) {
Expand All @@ -35,7 +35,7 @@ export class UserChallengeStatusService {
joinedCourse: false,
surveyComplete: false,
hasPost: false,
amountEarned: 0
userPosts: 0
};
}
}

0 comments on commit 544d562

Please sign in to comment.