|
|
|
@ -12,11 +12,17 @@ import {
@@ -12,11 +12,17 @@ import {
|
|
|
|
|
StorageKey, |
|
|
|
|
appEvents, |
|
|
|
|
storageService, |
|
|
|
|
ChoiceType, |
|
|
|
|
} from '../../common' |
|
|
|
|
import { nextStep, onNextPlayer, selectStep } from '../../../store/slices' |
|
|
|
|
import { |
|
|
|
|
addCustomItem, |
|
|
|
|
nextStep, |
|
|
|
|
onNextPlayer, |
|
|
|
|
selectStep, |
|
|
|
|
} from '../../../store/slices' |
|
|
|
|
import { TruthOrDareView } from '../components' |
|
|
|
|
import { useAnimationIconsButton } from '../animations' |
|
|
|
|
import { getCurrentTruthOrDare } from '../helper' |
|
|
|
|
import { useGetCurrentTruthOrDare } from '../hooks' |
|
|
|
|
import { PlayerName } from '../components/player-name.component' |
|
|
|
|
import { packageNameConfig } from '../config' |
|
|
|
|
import { useTranslation } from 'react-i18next' |
|
|
|
@ -26,7 +32,7 @@ interface IRouteParams {
@@ -26,7 +32,7 @@ interface IRouteParams {
|
|
|
|
|
packageType?: PackageType |
|
|
|
|
customType?: CustomType |
|
|
|
|
currentPlayer?: string |
|
|
|
|
isTruth?: boolean |
|
|
|
|
choiceType?: ChoiceType |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export const TruthOrDareScreen: React.FC = () => { |
|
|
|
@ -36,19 +42,50 @@ export const TruthOrDareScreen: React.FC = () => {
@@ -36,19 +42,50 @@ export const TruthOrDareScreen: React.FC = () => {
|
|
|
|
|
const { params } = useRoute() |
|
|
|
|
const currentStep = useSelector(selectStep) |
|
|
|
|
const { animRotate, animScale } = useAnimationIconsButton() |
|
|
|
|
const { packageType, isTruth, customType }: IRouteParams = params |
|
|
|
|
const { packageType, choiceType, customType }: IRouteParams = params |
|
|
|
|
|
|
|
|
|
const { currentItem, animStyle } = getCurrentTruthOrDare({ |
|
|
|
|
isTruth, |
|
|
|
|
const currentItem = useGetCurrentTruthOrDare({ |
|
|
|
|
choiceType, |
|
|
|
|
customType, |
|
|
|
|
packageType, |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
const onNextTruthOrDare = async () => { |
|
|
|
|
nav.navigate(UserRouteKey.Game, { packageType, isCustom: customType }) |
|
|
|
|
const onNextTruthOrDare = () => { |
|
|
|
|
nav.navigate(UserRouteKey.Game, { packageType }) |
|
|
|
|
dispatch(onNextPlayer()) |
|
|
|
|
dispatch(nextStep(isTruth)) |
|
|
|
|
await saveLastStep() |
|
|
|
|
dispatch(nextStep(choiceType)) |
|
|
|
|
saveLastStep() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const onAddGameItemToCustomPackage = () => { |
|
|
|
|
const customType = |
|
|
|
|
choiceType === ChoiceType.Truth |
|
|
|
|
? CustomType.Questions |
|
|
|
|
: CustomType.Dares |
|
|
|
|
|
|
|
|
|
dispatch(addCustomItem({ customType, value: currentItem })) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const onPressAddPlus = () => { |
|
|
|
|
const subtitleByChoice = |
|
|
|
|
choiceType === ChoiceType.Truth |
|
|
|
|
? t('customPack.addCustomTruth') |
|
|
|
|
: t('customPack.addCustomDare') |
|
|
|
|
|
|
|
|
|
appEvents.emit('confirm', { |
|
|
|
|
title: t('customPack.label'), |
|
|
|
|
subtitle: subtitleByChoice, |
|
|
|
|
cancelBtnText: 'No', |
|
|
|
|
confirmBtnText: 'Yes', |
|
|
|
|
buttons: [ |
|
|
|
|
{ |
|
|
|
|
onPress: () => null, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
onPress: onAddGameItemToCustomPackage, |
|
|
|
|
}, |
|
|
|
|
], |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const saveLastStep = async () => { |
|
|
|
@ -56,12 +93,12 @@ export const TruthOrDareScreen: React.FC = () => {
@@ -56,12 +93,12 @@ export const TruthOrDareScreen: React.FC = () => {
|
|
|
|
|
StorageKey.SavedSteps, |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
const key = isTruth ? 'stepTruth' : 'stepDare' |
|
|
|
|
const key = choiceType === ChoiceType.Truth ? 'stepTruth' : 'stepDare' |
|
|
|
|
|
|
|
|
|
const updateSteps = { ...currentStep, [key]: currentStep[key] + 1 } |
|
|
|
|
|
|
|
|
|
const stepsByCurrentPackage = { |
|
|
|
|
[packageType || 'custom']: updateSteps, |
|
|
|
|
[packageType]: updateSteps, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const saveStepsByPackage = { |
|
|
|
@ -69,13 +106,17 @@ export const TruthOrDareScreen: React.FC = () => {
@@ -69,13 +106,17 @@ export const TruthOrDareScreen: React.FC = () => {
|
|
|
|
|
...stepsByCurrentPackage, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
await storageService.set(StorageKey.SavedSteps, saveStepsByPackage) |
|
|
|
|
storageService.set(StorageKey.SavedSteps, saveStepsByPackage) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const getLimitForCrazy = async () => { |
|
|
|
|
const handleLimitCrazy = async () => { |
|
|
|
|
const isPurchasedCrazy = await storageService.get(StorageKey.Purchases) |
|
|
|
|
|
|
|
|
|
if (isPurchasedCrazy) return |
|
|
|
|
|
|
|
|
|
const limit = await storageService.get(StorageKey.LimitForCrazy) |
|
|
|
|
|
|
|
|
|
if (!limit) return await storageService.set(StorageKey.LimitForCrazy, 1) |
|
|
|
|
if (!limit) return storageService.set(StorageKey.LimitForCrazy, 1) |
|
|
|
|
|
|
|
|
|
if (limit >= 5) { |
|
|
|
|
return appEvents.emit('confirm', { |
|
|
|
@ -93,15 +134,15 @@ export const TruthOrDareScreen: React.FC = () => {
@@ -93,15 +134,15 @@ export const TruthOrDareScreen: React.FC = () => {
|
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
await storageService.set(StorageKey.LimitForCrazy, limit + 1) |
|
|
|
|
storageService.set(StorageKey.LimitForCrazy, limit + 1) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
if (packageType === PackageType.Crazy) getLimitForCrazy() |
|
|
|
|
}, []) |
|
|
|
|
if (packageType === PackageType.Crazy) handleLimitCrazy() |
|
|
|
|
}, [currentItem]) |
|
|
|
|
|
|
|
|
|
const onNextSameItem = () => { |
|
|
|
|
dispatch(nextStep(isTruth)) |
|
|
|
|
dispatch(nextStep(choiceType)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
@ -110,16 +151,13 @@ export const TruthOrDareScreen: React.FC = () => {
@@ -110,16 +151,13 @@ export const TruthOrDareScreen: React.FC = () => {
|
|
|
|
|
<Header |
|
|
|
|
gamer |
|
|
|
|
onPressLeft={onNextTruthOrDare} |
|
|
|
|
title={ |
|
|
|
|
packageNameConfig?.[packageType]?.[i18n.language] || |
|
|
|
|
t('customPack.label') |
|
|
|
|
} |
|
|
|
|
title={packageNameConfig?.[packageType]?.[i18n.language]} |
|
|
|
|
/> |
|
|
|
|
}> |
|
|
|
|
<View style={{ flex: 1 }}> |
|
|
|
|
<PlayerName /> |
|
|
|
|
|
|
|
|
|
<TruthOrDareView item={currentItem} animStyle={animStyle} /> |
|
|
|
|
<TruthOrDareView item={currentItem} /> |
|
|
|
|
|
|
|
|
|
<View style={styles.buttons}> |
|
|
|
|
<ButtonWithIcon |
|
|
|
@ -137,6 +175,14 @@ export const TruthOrDareScreen: React.FC = () => {
@@ -137,6 +175,14 @@ export const TruthOrDareScreen: React.FC = () => {
|
|
|
|
|
animation={animScale.func} |
|
|
|
|
animStyle={animScale.style} |
|
|
|
|
/> |
|
|
|
|
|
|
|
|
|
<ButtonWithIcon |
|
|
|
|
styleBtn={{ width: 101 }} |
|
|
|
|
iconName="add-plus" |
|
|
|
|
onPress={onPressAddPlus} |
|
|
|
|
animation={animScale.func} |
|
|
|
|
animStyle={animScale.style} |
|
|
|
|
/> |
|
|
|
|
</View> |
|
|
|
|
</View> |
|
|
|
|
</ScreenLayout> |
|
|
|
|