refs #3300 Enable shortcut to move focus on statuses in Public

This commit is contained in:
AkiraFukushima 2022-08-12 21:50:59 +09:00
parent 5411f5209f
commit f6b05a6284
No known key found for this signature in database
GPG Key ID: B6E51BAC4DE1A957
1 changed files with 22 additions and 5 deletions

View File

@ -11,8 +11,6 @@
:filters="filters"
v-on:update="updateToot"
v-on:delete="deleteToot"
@focusNext="focusNext"
@focusPrev="focusPrev"
@focusRight="focusSidebar"
@selectToot="focusToot(item)"
@sizeChanged="sizeChanged"
@ -31,6 +29,7 @@
<script lang="ts">
import { computed, defineComponent, onBeforeUnmount, onBeforeUpdate, onMounted, onUnmounted, ref, watch } from 'vue'
import { useMagicKeys, whenever, and } from '@vueuse/core'
import moment from 'moment'
import { ElMessage } from 'element-plus'
import { Entity } from 'megalodon'
@ -56,6 +55,7 @@ export default defineComponent({
const route = useRoute()
const i18n = useI18next()
const { reloadable } = useReloadable(store, route, i18n)
const { j, k } = useMagicKeys()
const focusedId = ref<string | null>(null)
const scrollPosition = ref<ScrollPosition | null>(null)
@ -71,9 +71,10 @@ export default defineComponent({
const openSideBar = computed(() => store.state.TimelineSpace.Contents.SideBar.openSideBar)
const startReload = computed(() => store.state.TimelineSpace.HeaderMenu.reload)
const unreadNotification = computed(() => store.state.TimelineSpace.timelineSetting.unreadNotification)
const modalOpened = computed(() => store.getters[`TimelineSpace/Modals/modalOpened`])
const modalOpened = computed<boolean>(() => store.getters[`TimelineSpace/Modals/modalOpened`])
const filters = computed(() => store.getters[`${space}/filters`])
const currentFocusedIndex = computed(() => timeline.value.findIndex(toot => focusedId.value === toot.uri + toot.id))
const shortcutEnabled = computed(() => !modalOpened.value)
onMounted(async () => {
store.commit(`TimelineSpace/SideMenu/${SIDE_MENU_MUTATION.CHANGE_UNREAD_PUBLIC_TIMELINE}`, false)
@ -137,6 +138,24 @@ export default defineComponent({
}
})
watch(focusedId, (newVal, _oldVal) => {
if (newVal && heading.value) {
store.commit(`${space}/${MUTATION_TYPES.CHANGE_HEADING}`, false)
} else if (newVal === null && !heading.value) {
store.commit(`${space}/${MUTATION_TYPES.CHANGE_HEADING}`, true)
}
})
whenever(and(j, shortcutEnabled), () => {
if (focusedId.value === null) {
focusedId.value = timeline.value[0].uri + timeline.value[0].id
} else {
focusNext()
}
})
whenever(and(k, shortcutEnabled), () => {
focusPrev()
})
const initialize = async () => {
await store.dispatch(`${space}/${ACTION_TYPES.FETCH_PUBLIC_TIMELINE}`).catch(_ => {
ElMessage({
@ -250,8 +269,6 @@ export default defineComponent({
filters,
updateToot,
deleteToot,
focusNext,
focusPrev,
focusSidebar,
focusToot,
sizeChanged,