diff --git a/src/components/Splash/SplashRoot.tsx b/src/components/Splash/SplashRoot.tsx index 7007fba8b5cdd528ad29f1f1f23b610c3360c53f..2d4beee979d4ef811dae8db345185eb4418cee90 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 31371b6ad14c2c701338dfef6305a898ceabbcc4..34663d137ac8e337939e362ec4697c72409c0bd3 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 6ed42b01f95085f03bf93bf78e6657b48de52a4b..a685f415500e36444281374b20cffb3ffefaf819 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