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' ...@@ -11,6 +11,7 @@ import { updateProfile } from 'store/profile/profile.actions'
import { import {
setUserChallengeList, setUserChallengeList,
setChallengeConsumption, setChallengeConsumption,
updateUserChallengeList,
} from 'store/challenge/challenge.actions' } from 'store/challenge/challenge.actions'
import { setSelectedDate } from 'store/chart/chart.actions' import { setSelectedDate } from 'store/chart/chart.actions'
import InitializationService from 'services/initialization.service' import InitializationService from 'services/initialization.service'
...@@ -26,6 +27,7 @@ import { ...@@ -26,6 +27,7 @@ import {
import { DateTime } from 'luxon' import { DateTime } from 'luxon'
import { UserActionState } from 'enum/userAction.enum' import { UserActionState } from 'enum/userAction.enum'
import ActionService from 'services/action.service' import ActionService from 'services/action.service'
import { UserChallenge } from 'models'
interface SplashRootProps { interface SplashRootProps {
fadeTimer?: number fadeTimer?: number
...@@ -166,10 +168,13 @@ const SplashRoot = ({ ...@@ -166,10 +168,13 @@ const SplashRoot = ({
UserActionState.ONGOING UserActionState.ONGOING
) { ) {
const actionService = new ActionService(client) const actionService = new ActionService(client)
const isActionDone: boolean = await actionService.isActionDone( const updatedUserChallenge: UserChallenge | null = await actionService.isActionDone(
filteredCurrentOngoingChallenge[0] filteredCurrentOngoingChallenge[0]
) )
dispatch(toogleChallengeNotification(isActionDone)) if (updatedUserChallenge) {
dispatch(updateUserChallengeList(updatedUserChallenge))
dispatch(toogleChallengeNotification(true))
}
} }
const filteredCurrentDuelChallenge = userChallengeList.filter( const filteredCurrentDuelChallenge = userChallengeList.filter(
challenge => challenge.state === UserChallengeState.DUEL challenge => challenge.state === UserChallengeState.DUEL
......
...@@ -244,9 +244,11 @@ export default class ActionService { ...@@ -244,9 +244,11 @@ export default class ActionService {
/** /**
* isActionDone - Set Action state to notification if progress > actionDuration * isActionDone - Set Action state to notification if progress > actionDuration
* @param {UserChallenge} currentChallenge * @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 ( if (
currentChallenge.action.startDate && currentChallenge.action.startDate &&
currentChallenge.action.ecogesture currentChallenge.action.ecogesture
...@@ -257,12 +259,12 @@ export default class ActionService { ...@@ -257,12 +259,12 @@ export default class ActionService {
const progressInHours = -startDate.diffNow('hours').hours const progressInHours = -startDate.diffNow('hours').hours
if (progressInHours > durationInHours) { if (progressInHours > durationInHours) {
const challengeService = new ChallengeService(this._client) const challengeService = new ChallengeService(this._client)
await challengeService.updateUserChallenge( const userChallenge: UserChallenge = await challengeService.updateUserChallenge(
currentChallenge, currentChallenge,
UserChallengeUpdateFlag.ACTION_NOTIFICATION UserChallengeUpdateFlag.ACTION_NOTIFICATION
) )
return true return userChallenge
} else return false } else return null
} else return false } else return null
} }
} }
...@@ -10,7 +10,7 @@ interface SetUserChallengeList { ...@@ -10,7 +10,7 @@ interface SetUserChallengeList {
payload?: UserChallenge[] payload?: UserChallenge[]
} }
interface UserChallengeUpdateFlag { interface UpdateUserChallengeList {
type: typeof UPDATE_USER_CHALLENGE_LIST type: typeof UPDATE_USER_CHALLENGE_LIST
payload?: UserChallenge payload?: UserChallenge
} }
...@@ -27,7 +27,7 @@ interface SetChallengeConsumption { ...@@ -27,7 +27,7 @@ interface SetChallengeConsumption {
export type ChallengeActionTypes = export type ChallengeActionTypes =
| SetUserChallengeList | SetUserChallengeList
| UserChallengeUpdateFlag | UpdateUserChallengeList
| UnlockNextUserChallenge | UnlockNextUserChallenge
| SetChallengeConsumption | SetChallengeConsumption
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment