Skip to content

Commit 6087b50

Browse files
committed
refactor(travel): split autofocus
1 parent a49baad commit 6087b50

File tree

6 files changed

+56
-35
lines changed

6 files changed

+56
-35
lines changed
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script setup lang="ts">
2+
import StepButton from "./StepButton.vue"
3+
import Encounters from "./Encounters.vue"
4+
</script>
5+
6+
<template>
7+
<StepButton />
8+
<Encounters />
9+
</template>

src/views/Travel/AutoFocus.vue src/views/Travel/AutoFocus/Encounters.vue

+4-29
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
<script setup lang="ts">
22
import { Checkbox } from "@/components"
3-
4-
import { watch } from "vue"
5-
import { useTravelStore } from "./store"
3+
import { useTravelStore } from "../store"
64
import { storeToRefs } from "pinia"
7-
import { focusOnButtonEnable, wrapAnchorWithButton } from "@/utils"
5+
import { watch } from "vue"
6+
import { wrapAnchorWithButton } from "@/utils"
87
98
const travelStore = useTravelStore()
10-
const { shouldAutoFocusStep, shouldAutoFocusEncounters, lastStepResponse } = storeToRefs(travelStore)
11-
12-
/** Encounter auto focus */
9+
const { shouldAutoFocusEncounters, lastStepResponse } = storeToRefs(travelStore)
1310
1411
watch(lastStepResponse, async (response) => {
1512
if (!response) return
@@ -31,31 +28,9 @@ watch(lastStepResponse, async (response) => {
3128
}
3229
})
3330
})
34-
35-
/** Travel button auto focus */
36-
37-
const travelButton = document.querySelector<HTMLButtonElement>(".px-4.py-4 button")
38-
const observer = travelButton && focusOnButtonEnable(travelButton)
39-
40-
watch(
41-
shouldAutoFocusStep,
42-
(val) => {
43-
if (!observer) return
44-
45-
if (val) observer.connect()
46-
else observer.disconnect()
47-
},
48-
{
49-
immediate: true,
50-
}
51-
)
5231
</script>
5332

5433
<template>
55-
<Checkbox v-model="shouldAutoFocusStep">
56-
<template #default> Autofocus step button </template>
57-
<template #subtitle> Just hit space/enter! </template>
58-
</Checkbox>
5934
<Checkbox v-model="shouldAutoFocusEncounters">
6035
<template #default> Autofocus encounters </template>
6136
<template #subtitle> Hit space/enter to attack/gather </template>
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<script setup lang="ts">
2+
import { Checkbox } from "@/components"
3+
import { useTravelStore } from "../store"
4+
import { storeToRefs } from "pinia"
5+
import { focusOnButtonEnable } from "@/utils"
6+
import { watch } from "vue"
7+
8+
const travelStore = useTravelStore()
9+
const { shouldAutoFocusStep } = storeToRefs(travelStore)
10+
11+
const travelButton = document.querySelector<HTMLButtonElement>(".px-4.py-4 button")
12+
const observer = travelButton && focusOnButtonEnable(travelButton)
13+
14+
watch(
15+
shouldAutoFocusStep,
16+
(val) => {
17+
if (!observer) return
18+
19+
if (val) observer.connect()
20+
else observer.disconnect()
21+
},
22+
{
23+
immediate: true,
24+
}
25+
)
26+
</script>
27+
28+
<template>
29+
<Checkbox v-model="shouldAutoFocusStep">
30+
<template #default> Autofocus step button </template>
31+
<template #subtitle> Just hit space/enter! </template>
32+
</Checkbox>
33+
</template>

src/views/Travel/AutoFocus/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as AutoFocus } from "./AutoFocus.vue"

src/views/Travel/Travel.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Controls } from "@/components"
33
44
import DataBridge from "./DataBridge.vue"
55
import StepButton from "./StepButton.vue"
6-
import AutoFocus from "./AutoFocus.vue"
6+
import { AutoFocus } from "./AutoFocus"
77
</script>
88

99
<template>

src/views/Travel/store.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import { computed, onMounted, ref } from "vue"
44
export const useTravelStore = defineStore(
55
"travel",
66
() => {
7-
const lastStepResponse = ref<null | TravelResponse>(null)
8-
const cooldownTimestamp = ref<null | string>(null)
97
const shouldAutoFocusStep = ref(false)
108
const shouldPersistCooldown = ref(false)
119
const shouldAutoFocusEncounters = ref(false)
10+
// const shouldAutoFocusVerification = ref(false)
11+
12+
const lastStepResponse = ref<null | TravelResponse>(null)
13+
const cooldownTimestamp = ref<null | string>(null)
1214

1315
const cooldownTimeLeft = computed(() => {
1416
if (!cooldownTimestamp.value) return 0
@@ -24,12 +26,13 @@ export const useTravelStore = defineStore(
2426
})
2527

2628
return {
27-
cooldownTimestamp,
28-
cooldownTimeLeft,
29-
lastStepResponse,
3029
shouldAutoFocusStep,
3130
shouldPersistCooldown,
3231
shouldAutoFocusEncounters,
32+
// shouldAutoFocusVerification,
33+
cooldownTimestamp,
34+
cooldownTimeLeft,
35+
lastStepResponse,
3336
}
3437
},
3538
{

0 commit comments

Comments
 (0)