Skip to content
Snippets Groups Projects
Commit 88c83152 authored by Yoan VALLET's avatar Yoan VALLET
Browse files

fix notification for actions

parent 83628dd4
Branches
Tags
1 merge request!285Fix/action notifications
......@@ -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
......
......@@ -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
}
}
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment