From 88c83152d688cea25cb77ea81b0507ccd37f1543 Mon Sep 17 00:00:00 2001 From: Yoan VALLET <ext.sopra.yvallet@grandlyon.com> Date: Thu, 4 Mar 2021 12:37:29 +0100 Subject: [PATCH] fix notification for actions --- src/components/Splash/SplashRoot.tsx | 9 +++++++-- src/services/action.service.ts | 14 ++++++++------ src/store/challenge/challenge.actions.ts | 4 ++-- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/components/Splash/SplashRoot.tsx b/src/components/Splash/SplashRoot.tsx index 7007fba8b..2d4beee97 100644 --- a/src/components/Splash/SplashRoot.tsx +++ b/src/components/Splash/SplashRoot.tsx @@ -11,6 +11,7 @@ import { updateProfile } from 'store/profile/profile.actions' import { setUserChallengeList, setChallengeConsumption, + updateUserChallengeList, } from 'store/challenge/challenge.actions' import { setSelectedDate } from 'store/chart/chart.actions' import InitializationService from 'services/initialization.service' @@ -26,6 +27,7 @@ import { import { DateTime } from 'luxon' import { UserActionState } from 'enum/userAction.enum' import ActionService from 'services/action.service' +import { UserChallenge } from 'models' interface SplashRootProps { fadeTimer?: number @@ -166,10 +168,13 @@ const SplashRoot = ({ UserActionState.ONGOING ) { const actionService = new ActionService(client) - const isActionDone: boolean = await actionService.isActionDone( + const updatedUserChallenge: UserChallenge | null = await actionService.isActionDone( filteredCurrentOngoingChallenge[0] ) - dispatch(toogleChallengeNotification(isActionDone)) + if (updatedUserChallenge) { + dispatch(updateUserChallengeList(updatedUserChallenge)) + dispatch(toogleChallengeNotification(true)) + } } const filteredCurrentDuelChallenge = userChallengeList.filter( challenge => challenge.state === UserChallengeState.DUEL diff --git a/src/services/action.service.ts b/src/services/action.service.ts index 31371b6ad..34663d137 100644 --- a/src/services/action.service.ts +++ b/src/services/action.service.ts @@ -244,9 +244,11 @@ export default class ActionService { /** * isActionDone - Set Action state to notification if progress > actionDuration * @param {UserChallenge} currentChallenge - * @returns {Promise<boolean>} + * @returns {Promise<UserChallenge | null>} */ - public async isActionDone(currentChallenge: UserChallenge): Promise<boolean> { + public async isActionDone( + currentChallenge: UserChallenge + ): Promise<UserChallenge | null> { if ( currentChallenge.action.startDate && currentChallenge.action.ecogesture @@ -257,12 +259,12 @@ export default class ActionService { const progressInHours = -startDate.diffNow('hours').hours if (progressInHours > durationInHours) { const challengeService = new ChallengeService(this._client) - await challengeService.updateUserChallenge( + const userChallenge: UserChallenge = await challengeService.updateUserChallenge( currentChallenge, UserChallengeUpdateFlag.ACTION_NOTIFICATION ) - return true - } else return false - } else return false + return userChallenge + } else return null + } else return null } } diff --git a/src/store/challenge/challenge.actions.ts b/src/store/challenge/challenge.actions.ts index 6ed42b01f..a685f4155 100644 --- a/src/store/challenge/challenge.actions.ts +++ b/src/store/challenge/challenge.actions.ts @@ -10,7 +10,7 @@ interface SetUserChallengeList { payload?: UserChallenge[] } -interface UserChallengeUpdateFlag { +interface UpdateUserChallengeList { type: typeof UPDATE_USER_CHALLENGE_LIST payload?: UserChallenge } @@ -27,7 +27,7 @@ interface SetChallengeConsumption { export type ChallengeActionTypes = | SetUserChallengeList - | UserChallengeUpdateFlag + | UpdateUserChallengeList | UnlockNextUserChallenge | SetChallengeConsumption -- GitLab