Browse Source

FIX | Fix sort bug (#6)

Co-authored-by: Vlad <vlad960706@gmail.com>
Reviewed-on: #6
Co-authored-by: Vlad Narizhnyi <vlad960706@gmail.com>
Co-committed-by: Vlad Narizhnyi <vlad960706@gmail.com>
pull/7/head
Vlad Narizhnyi 10 months ago committed by Vitalik Yatsenko
parent
commit
9c7dfe4459
  1. 36
      src/module/common/questions-dares-list/questions-dares-list.ts
  2. 1
      src/module/common/typing/enums/storage-key.enum.ts
  3. 46
      src/module/game/hooks/get-current-truth-dares.hook.tsx
  4. 2
      src/module/game/hooks/use-set-steps-by-package.tsx
  5. 2
      src/module/packages/config/packages-list.config.tsx
  6. 10
      src/store/slices/custom-package.slice.ts
  7. 29
      src/store/slices/game-items.slice.ts

36
src/module/common/questions-dares-list/questions-dares-list.ts

@ -257,8 +257,8 @@ export const light = [ @@ -257,8 +257,8 @@ export const light = [
{
id: 2,
isDare: true,
en: 'Одягни на вуха носки і сиди так 3 раунда.',
ua: 'Put socks on your ears and sit like that for 3 rounds.',
ua: 'Одягни на вуха носки і сиди так 3 раунда.',
en: 'Put socks on your ears and sit like that for 3 rounds.',
},
{
id: 3,
@ -275,8 +275,8 @@ export const light = [ @@ -275,8 +275,8 @@ export const light = [
{
id: 5,
isDare: false,
en: 'Найекстремальніше, що ти робив(ла), щоб комусь сподобатись?',
ua: "What's the most extreme thing you've done to please someone?",
ua: 'Найекстремальніше, що ти робив(ла), щоб комусь сподобатись?',
en: "What's the most extreme thing you've done to please someone?",
},
{
id: 6,
@ -288,7 +288,7 @@ export const light = [ @@ -288,7 +288,7 @@ export const light = [
id: 7,
isDare: false,
en: 'If you could be invisible for a day, what would you do?',
ua: 'Якщо б ви могли бути невидимими на один день, Що б ти зробив(ла), якб?',
ua: 'Якщо б ви могли бути невидимими на один день, Що б ти зробив(ла)?',
},
{
id: 8,
@ -347,8 +347,8 @@ export const light = [ @@ -347,8 +347,8 @@ export const light = [
{
id: 17,
isDare: false,
en: 'What do you often look at on the Internet?',
ua: 'Про що ти часто дивишся в інтернеті?',
en: 'Tell the first impression when you saw the person on the left of you',
ua: 'Розкажи перше враження, коли ти побачив(ла) людину ліворуч віж тебе',
},
{
id: 18,
@ -371,8 +371,8 @@ export const light = [ @@ -371,8 +371,8 @@ export const light = [
{
id: 21,
isDare: false,
en: 'Tell the funniest story about how you threw up.',
ua: 'Розкажи про якусь ситуацію, яку ти бачив на власні очі.',
en: 'Tell me about some trashy situation that you saw with your own eyes.',
ua: 'Розкажи про якусь трешову ситуацію, яку ти бачив на власні очі.',
},
{
id: 22,
@ -407,8 +407,8 @@ export const light = [ @@ -407,8 +407,8 @@ export const light = [
{
id: 27,
isDare: false,
en: 'Have you ever followed someone?',
ua: 'Ти колись слідкував за кимось?',
en: 'Have you ever followed someone live?',
ua: 'Ти колись слідкував за кимось вживу?',
},
{
id: 28,
@ -420,7 +420,7 @@ export const light = [ @@ -420,7 +420,7 @@ export const light = [
id: 27,
isDare: false,
en: 'Tell about the channel that you immediately open when something new appears there.',
ua: 'Розкажи про канал, який ти одразу відкриваєш, коли там з являється щось нове.',
ua: "Розкажи про канал, який ти одразу відкриваєш, коли там з'являється щось нове.",
},
{
id: 28,
@ -431,8 +431,8 @@ export const light = [ @@ -431,8 +431,8 @@ export const light = [
{
id: 29,
isDare: false,
en: 'Tell about the channel that you immediately open when something new appears there.',
ua: 'Розкажи про канал, який ти одразу відкриваєш, коли там з являється щось нове.',
en: 'What act do you feel ashamed of?',
ua: 'За який вчинок ти відчуваєш сором?',
},
{
id: 30,
@ -455,8 +455,8 @@ export const light = [ @@ -455,8 +455,8 @@ export const light = [
{
id: 33,
isDare: false,
en: 'Have you ever been dumped by a person you liked?',
ua: 'Тебе колись кидала людина, яка тобі подобалась?',
en: 'What act do you feel proud of?',
ua: 'За який вчинок ти відчуваєш гордість?',
},
{
id: 34,
@ -572,8 +572,8 @@ export const crazy = [ @@ -572,8 +572,8 @@ export const crazy = [
{
id: 12,
isDare: false,
en: 'Є людина, яку ти ненавидиш, але вона про це не знає?',
ua: "Is there a person you hate, but they don't know it?",
ua: 'Є людина, яку ти ненавидиш, але вона про це не знає?',
en: "Is there a person you hate, but they don't know it?",
},
{
id: 13,

1
src/module/common/typing/enums/storage-key.enum.ts

@ -5,6 +5,7 @@ export enum StorageKey { @@ -5,6 +5,7 @@ export enum StorageKey {
Products = 'Products',
CustomPackage = 'CustomPackage',
ShuffleCustomPackage = 'ShuffleCustomPackage',
ShufflePackage = 'ShufflePackage',
Players = 'Players',
LimitForCrazy = 'limit',
SavedSteps = 'SavedSteps',

46
src/module/game/hooks/get-current-truth-dares.hook.tsx

@ -19,7 +19,6 @@ import { @@ -19,7 +19,6 @@ import {
import { useTranslation } from 'react-i18next'
import { useDispatch, useSelector } from 'react-redux'
import { RootState } from '~store/store'
import firestore from '@react-native-firebase/firestore'
import _ from 'lodash'
interface UseTruthOrDareProps {
@ -52,7 +51,7 @@ export const useGetCurrentTruthOrDare = ({ @@ -52,7 +51,7 @@ export const useGetCurrentTruthOrDare = ({
}
const getGameItemsByCustomPackage = () => {
if (_.isEmpty(customPackageShuffle.questions))
if (_.isEmpty(customPackageShuffle[customType]))
return customPackage[customType]
return customPackageShuffle[customType]
@ -69,18 +68,20 @@ export const useGetCurrentTruthOrDare = ({ @@ -69,18 +68,20 @@ export const useGetCurrentTruthOrDare = ({
const packageTruthsOrDares = getGameItemsByPackage()
const currentItem = getCurrentItem()
console.log('currentItem', currentItem)
console.log('customTruthsOrDares', customTruthsOrDares)
const shuffleAndSavePackage = async () => {
const shufflePackages = _.shuffle(packageTruthsOrDares)
await firestore()
.collection('content')
.doc(packageType)
.update(shufflePackages)
const savedShuffle = await storageService.get(StorageKey.ShufflePackage)
const shuffleItems = _.shuffle(savedShuffle[packageType])
const newShuffle = {
...savedShuffle,
[packageType]: shuffleItems,
}
await storageService.set(StorageKey.ShufflePackage, newShuffle)
dispatch(resetStepsByTruthOrDare(choiceType))
dispatch(shufflePackage(packageType))
dispatch(shufflePackage({ packageType, shuffleItems }))
}
const shuffleAndSaveCustomPackage = async () => {
@ -88,18 +89,33 @@ export const useGetCurrentTruthOrDare = ({ @@ -88,18 +89,33 @@ export const useGetCurrentTruthOrDare = ({
const shuffleCustom = _.shuffle(customTruthsOrDares)
dispatch(shuffleCustomPackage({ customType, shuffleCustom }))
dispatch(resetStepsByTruthOrDare(choiceType))
const savedShuffleCustom = await storageService.get(
StorageKey.ShuffleCustomPackage,
)
if (!savedShuffleCustom?.[customType]) {
const newShuffled = {
...customPackage,
[customType]: shuffleCustom,
}
dispatch(shuffleCustomPackage(newShuffled))
return await storageService.set(
StorageKey.ShuffleCustomPackage,
newShuffled,
)
}
const newShuffled = {
...savedShuffleCustom,
[customType]: shuffleCustom,
}
await storageService.set(StorageKey.ShuffleCustomPackage, newShuffled)
dispatch(shuffleCustomPackage(newShuffled))
dispatch(resetStepsByTruthOrDare(choiceType))
}
const checkIsNeedShuffle = () => {
@ -120,7 +136,7 @@ export const useGetCurrentTruthOrDare = ({ @@ -120,7 +136,7 @@ export const useGetCurrentTruthOrDare = ({
useEffect(() => {
checkIsNeedShuffle()
}, [currentStep])
}, [currentStep, customTruthsOrDares])
return currentItem
}

2
src/module/game/hooks/use-set-steps-by-package.tsx

@ -11,8 +11,6 @@ export const useSetStepsByPackage = (packageType: PackageType) => { @@ -11,8 +11,6 @@ export const useSetStepsByPackage = (packageType: PackageType) => {
const stepsByPackage = lastSteps?.[packageType]
console.log('stepsByPackage', stepsByPackage)
if (!stepsByPackage) return dispatch(resetSteps())
dispatch(setStep(stepsByPackage))

2
src/module/packages/config/packages-list.config.tsx

@ -27,7 +27,7 @@ export const packageListConfig = [ @@ -27,7 +27,7 @@ export const packageListConfig = [
/>
),
description: {
ua: 'Challenge your friends or your significant other and see how far they can go!',
ua: 'Веселі та несподівані завдання гарантовано розсмішять та відкриють нові факти з життя учасників!',
en: 'Fun and unexpected tasks are guaranteed to make you laugh and discover new facts from the life of the participants.',
},
},

10
src/store/slices/custom-package.slice.ts

@ -49,15 +49,9 @@ export const customPackageSlice = createSlice({ @@ -49,15 +49,9 @@ export const customPackageSlice = createSlice({
reducers: {
shuffleCustomPackage: (
state,
action: PayloadAction<{
shuffleCustom: string[]
customType: CustomType
}>,
action: PayloadAction<ICustomPackage>,
) => {
const shuffleItems = action.payload.shuffleCustom
const customType = action.payload.customType
state.shuffleCustom[customType] = shuffleItems
state.shuffleCustom = action.payload
},
addCustomItem: (
state,

29
src/store/slices/game-items.slice.ts

@ -1,6 +1,11 @@ @@ -1,6 +1,11 @@
import { PayloadAction, createAsyncThunk, createSlice } from '@reduxjs/toolkit'
import firestore from '@react-native-firebase/firestore'
import { GameItem, PackageType } from '../../module/common'
import {
GameItem,
PackageType,
StorageKey,
storageService,
} from '../../module/common'
import { RootState } from '../store'
import _ from 'lodash'
@ -34,7 +39,14 @@ export const getGameItemsFromFirestore = createAsyncThunk( @@ -34,7 +39,14 @@ export const getGameItemsFromFirestore = createAsyncThunk(
return acc
}, {})
return allPackages
const saved = await storageService.get(StorageKey.ShufflePackage)
if (!saved) {
await storageService.set(StorageKey.ShufflePackage, allPackages)
return allPackages
}
return saved
},
)
@ -42,15 +54,22 @@ export const gameItemsSlice = createSlice({ @@ -42,15 +54,22 @@ export const gameItemsSlice = createSlice({
name: 'gameItems',
initialState,
reducers: {
shufflePackage: (state, action: PayloadAction<PackageType>) => {
const packageType = action.payload
state[packageType] = _.shuffle(state[packageType])
shufflePackage: (
state,
action: PayloadAction<{
packageType: PackageType
shuffleItems: GameItem[]
}>,
) => {
const packageType = action.payload.packageType
state[packageType] = action.payload.shuffleItems
},
},
extraReducers(builder) {
builder
.addCase(getGameItemsFromFirestore.fulfilled, (state, action) => {
const allPackages = action.payload
state.under18 = allPackages[PackageType.Under18]
state.light = allPackages[PackageType.Light]
state.crazy = allPackages[PackageType.Crazy]

Loading…
Cancel
Save