Skip to content

Commit

Permalink
chore: clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
selimdoyranli committed Mar 1, 2024
1 parent d5243cd commit 01e96d4
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 18 deletions.
16 changes: 3 additions & 13 deletions components/Header/AppHeader/AppHeader.component.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@

// How To Play Dialog
HowToPlayDialog(:cancel-button-text="$t('general.close')" :isOpen="dialog.howToPlay.isOpen" @closed="dialog.howToPlay.isOpen = false")
// Stats Dialog
DailyModeStatsDialog(:isOpen="dialog.stats.mode.daily.isOpen" @closed="dialog.stats.mode.daily.isOpen = false")
// Menu Dialog
MenuDialog(
:isOpen="dialog.menu.isOpen"
Expand Down Expand Up @@ -62,7 +60,6 @@ import { PlayerAvatar } from '@/components/Avatar'
import { AppLogo } from '@/components/Logo'
import { AppIcon } from '@/components/Icon'
import {
DailyModeStatsDialog,
HowToPlayDialog,
MenuDialog,
HowToCalculateStatsDialog,
Expand All @@ -77,7 +74,6 @@ export default defineComponent({
PlayerAvatar,
AppLogo,
AppIcon,
DailyModeStatsDialog,
HowToPlayDialog,
MenuDialog,
HowToCalculateStatsDialog,
Expand All @@ -96,13 +92,6 @@ export default defineComponent({
const { openLeaveDialog } = useDialog()
const dialog = reactive({
stats: {
mode: {
daily: {
isOpen: false
}
}
},
howToPlay: {
isOpen: false
},
Expand All @@ -126,12 +115,13 @@ export default defineComponent({
}
})
const dailyDialog = computed(() => store.getters['daily/dialog'])
const unlimitedDialog = computed(() => store.getters['unlimited/dialog'])
const creatorDialog = computed(() => store.getters['unlimited/dialog'])
const creatorDialog = computed(() => store.getters['creator/dialog'])
const toggleStatsDialog = () => {
if (activeGameMode.value === gameModeKeyEnum.DAILY) {
dialog.stats.mode.daily.isOpen = !dialog.stats.mode.daily.isOpen
store.commit('daily/SET_IS_OPEN_STATS_DIALOG', !dailyDialog.value.stats.isOpen)
}
if (activeGameMode.value === gameModeKeyEnum.UNLIMITED) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,17 @@
// How To Play Dialog
HowToPlayDialog(v-if="!isGameOver" :isOpen="dialog.howToPlay.isOpen" @closed="startGame")
// Stats Dialog
DailyModeStatsDialog(:isOpen="dialog.stats.isOpen")
DailyModeStatsDialog(
:cancelButtonText="$t('general.close')"
:isOpen="dailyDialog.stats.isOpen"
@onCancel="$store.commit('daily/SET_IS_OPEN_STATS_DIALOG', false)"
)
// Interstital Ad Dialog
InterstitialAdDialog(:cancelButtonText="$t('gameScene.skipAdShowScore')" :isOpen="dialog.interstitialAd.isOpen")
</template>

<script>
import { defineComponent, useStore, useFetch, ref, onMounted, onUnmounted } from '@nuxtjs/composition-api'
import { defineComponent, useStore, useFetch, ref, onMounted, onUnmounted, computed } from '@nuxtjs/composition-api'
import { ANSWER_CHAR_LENGTH } from '@/system/constant'
import { useGameScene } from '@/hooks'
import { Button, Field, Empty, CountDown } from 'vant'
Expand Down Expand Up @@ -136,6 +140,8 @@ export default defineComponent({
checkUnsupportedHeight
} = useGameScene()
const dailyDialog = computed(() => store.getters['daily/dialog'])
const day = new Date().toLocaleDateString('tr').slice(0, 10)
const storedDay = persistStore && persistStore.daily.currentDate
Expand Down Expand Up @@ -210,6 +216,7 @@ export default defineComponent({
questions,
answer,
dialog,
dailyDialog,
countdown,
countdownTimerRef,
alphabetItemClasses,
Expand Down
8 changes: 5 additions & 3 deletions hooks/useGameScene.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,10 +460,12 @@ export default () => {

countdownTimerRef.value.pause()

if (activeGameMode.value === gameModeKeyEnum.UNLIMITED || activeGameMode.value === gameModeKeyEnum.CREATOR) {
if (
activeGameMode.value === gameModeKeyEnum.DAILY ||
activeGameMode.value === gameModeKeyEnum.UNLIMITED ||
activeGameMode.value === gameModeKeyEnum.CREATOR
) {
store.commit(`${activeGameMode.value}/SET_IS_OPEN_STATS_DIALOG`, true)
} else {
dialog.stats.isOpen = true
}

// Post Stats
Expand Down
4 changes: 4 additions & 0 deletions store/daily/getters.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@ export default {

passedAnswers(state) {
return state.alphabet.items.filter(item => item.isPassed)
},

dialog(state) {
return state.dialog
}
}
8 changes: 8 additions & 0 deletions store/daily/mutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export default {
state.alphabet.activeIndex = index
},

UPDATE_COUNTDOWN_REMAIN_TIME(state, remainTime) {
state.countdown.remainTime = remainTime
},

UPDATE_COUNTDOWN_TIMER(state, ms) {
state.countdown.time = ms
},
Expand All @@ -33,5 +37,9 @@ export default {
item.isWrong = false
item.isCorrect = false
})
},

SET_IS_OPEN_STATS_DIALOG(state, isOpen) {
state.dialog.stats.isOpen = isOpen
}
}
5 changes: 5 additions & 0 deletions store/daily/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,5 +168,10 @@ export default () => ({
countdown: {
time: GAME_TIME_LIMIT,
remainTime: {}
},
dialog: {
stats: {
isOpen: false
}
}
})
4 changes: 4 additions & 0 deletions store/unlimited/mutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export default {
state.alphabet.activeIndex = index
},

UPDATE_COUNTDOWN_REMAIN_TIME(state, remainTime) {
state.countdown.remainTime = remainTime
},

UPDATE_COUNTDOWN_TIMER(state, ms) {
state.countdown.time = ms
},
Expand Down

0 comments on commit 01e96d4

Please sign in to comment.