Skip to content

Commit c725e98

Browse files
committed
feat(travel): add verification autofocus
1 parent 6087b50 commit c725e98

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed
+2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<script setup lang="ts">
22
import StepButton from "./StepButton.vue"
33
import Encounters from "./Encounters.vue"
4+
import Verification from "./Verification.vue"
45
</script>
56

67
<template>
78
<StepButton />
89
<Encounters />
10+
<Verification />
911
</template>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<script setup lang="ts">
2+
import { Checkbox } from "@/components"
3+
import { useTravelStore } from "../store"
4+
import { storeToRefs } from "pinia"
5+
import { watch } from "vue"
6+
import { wrapAnchorWithButton } from "@/utils"
7+
8+
const travelStore = useTravelStore()
9+
const { shouldAutoFocusVerification, lastStepResponse } = storeToRefs(travelStore)
10+
11+
watch(lastStepResponse, (val) => {
12+
if (!shouldAutoFocusVerification.value) return
13+
if (!val?.text?.includes("verification")) return
14+
15+
/** let dom hydrate */
16+
setTimeout(() => {
17+
const verificationAnchor = document.querySelector<HTMLAnchorElement>(".travel-content a")
18+
if (!verificationAnchor) return
19+
20+
verificationAnchor.removeAttribute("target")
21+
wrapAnchorWithButton(verificationAnchor).focus()
22+
})
23+
})
24+
</script>
25+
26+
<template>
27+
<Checkbox v-model="shouldAutoFocusVerification">
28+
<template #default> Autofocus verification button </template>
29+
<template #subtitle> Will open in this tab </template>
30+
</Checkbox>
31+
</template>

src/views/Travel/store.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const useTravelStore = defineStore(
77
const shouldAutoFocusStep = ref(false)
88
const shouldPersistCooldown = ref(false)
99
const shouldAutoFocusEncounters = ref(false)
10-
// const shouldAutoFocusVerification = ref(false)
10+
const shouldAutoFocusVerification = ref(false)
1111

1212
const lastStepResponse = ref<null | TravelResponse>(null)
1313
const cooldownTimestamp = ref<null | string>(null)
@@ -29,7 +29,7 @@ export const useTravelStore = defineStore(
2929
shouldAutoFocusStep,
3030
shouldPersistCooldown,
3131
shouldAutoFocusEncounters,
32-
// shouldAutoFocusVerification,
32+
shouldAutoFocusVerification,
3333
cooldownTimestamp,
3434
cooldownTimeLeft,
3535
lastStepResponse,

0 commit comments

Comments
 (0)