Merge pull request #3329 from h3poteto/iss-3300/image-viewer

refs #3300 Handle shortcut keys in ImageViewer
This commit is contained in:
AkiraFukushima 2022-05-03 11:24:34 +09:00 committed by GitHub
commit 0affc59f68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 0 deletions

View File

@ -23,6 +23,7 @@
<script lang="ts"> <script lang="ts">
import { defineComponent, computed } from 'vue' import { defineComponent, computed } from 'vue'
import { useMagicKeys, whenever } from '@vueuse/core'
import { useStore } from '@/store' import { useStore } from '@/store'
import { ACTION_TYPES } from '@/store/TimelineSpace/Modals/ImageViewer' import { ACTION_TYPES } from '@/store/TimelineSpace/Modals/ImageViewer'
import Media from './ImageViewer/Media.vue' import Media from './ImageViewer/Media.vue'
@ -35,6 +36,7 @@ export default defineComponent({
setup() { setup() {
const space = 'TimelineSpace/Modals/ImageViewer' const space = 'TimelineSpace/Modals/ImageViewer'
const store = useStore() const store = useStore()
const { left, right, Escape } = useMagicKeys()
const modalOpen = computed(() => store.state.TimelineSpace.Modals.ImageViewer.modalOpen) const modalOpen = computed(() => store.state.TimelineSpace.Modals.ImageViewer.modalOpen)
const imageURL = computed(() => store.getters[`${space}/imageURL`]) const imageURL = computed(() => store.getters[`${space}/imageURL`])
@ -42,6 +44,16 @@ export default defineComponent({
const showLeft = computed(() => store.getters[`${space}/showLeft`]) const showLeft = computed(() => store.getters[`${space}/showLeft`])
const showRight = computed(() => store.getters[`${space}/showRight`]) const showRight = computed(() => store.getters[`${space}/showRight`])
whenever(left, () => {
decrementIndex()
})
whenever(right, () => {
incrementIndex()
})
whenever(Escape, () => {
close()
})
const close = () => { const close = () => {
store.dispatch(`${space}/${ACTION_TYPES.CLOSE_MODAL}`) store.dispatch(`${space}/${ACTION_TYPES.CLOSE_MODAL}`)
} }