refs #750 Switch focus between Notification and Toot Detail using shortcut keys

This commit is contained in:
AkiraFukushima 2018-11-28 23:12:16 +09:00
parent 8e1f376749
commit c707c314ba
5 changed files with 35 additions and 2 deletions

View File

@ -12,6 +12,7 @@
:overlaid="modalOpened" :overlaid="modalOpened"
@focusNext="focusNext" @focusNext="focusNext"
@focusPrev="focusPrev" @focusPrev="focusPrev"
@focusRight="focusSidebar"
@selectNotification="focusNotification(message)" @selectNotification="focusNotification(message)"
> >
</notification> </notification>
@ -31,6 +32,7 @@ import { mapState, mapGetters } from 'vuex'
import Notification from '~/src/renderer/components/molecules/Notification' import Notification from '~/src/renderer/components/molecules/Notification'
import scrollTop from '../../utils/scroll' import scrollTop from '../../utils/scroll'
import reloadable from '~/src/renderer/components/mixins/reloadable' import reloadable from '~/src/renderer/components/mixins/reloadable'
import { Event } from '~/src/renderer/components/event'
export default { export default {
name: 'notifications', name: 'notifications',
@ -71,12 +73,24 @@ export default {
this.$store.commit('TimelineSpace/SideMenu/changeUnreadNotifications', false) this.$store.commit('TimelineSpace/SideMenu/changeUnreadNotifications', false)
this.$store.dispatch('TimelineSpace/Contents/Notifications/resetBadge') this.$store.dispatch('TimelineSpace/Contents/Notifications/resetBadge')
document.getElementById('scrollable').addEventListener('scroll', this.onScroll) document.getElementById('scrollable').addEventListener('scroll', this.onScroll)
Event.$on('focus-timeline', () => {
// If focusedId does not change, we have to refresh focusedId because Toot component watch change events.
const previousFocusedId = this.focusedId
this.focusedId = 0
this.$nextTick(function () {
this.focusedId = previousFocusedId
})
})
}, },
beforeUpdate () { beforeUpdate () {
if (this.$store.state.TimelineSpace.SideMenu.unreadNotifications) { if (this.$store.state.TimelineSpace.SideMenu.unreadNotifications) {
this.$store.commit('TimelineSpace/SideMenu/changeUnreadNotifications', false) this.$store.commit('TimelineSpace/SideMenu/changeUnreadNotifications', false)
} }
}, },
beforeDestroy () {
Event.$off('focus-timeline')
},
destroyed () { destroyed () {
this.$store.commit('TimelineSpace/Contents/Notifications/changeHeading', true) this.$store.commit('TimelineSpace/Contents/Notifications/changeHeading', true)
this.$store.commit('TimelineSpace/Contents/Notifications/mergeNotifications') this.$store.commit('TimelineSpace/Contents/Notifications/mergeNotifications')
@ -160,6 +174,9 @@ export default {
focusNotification (notification) { focusNotification (notification) {
this.focusedId = notification.id this.focusedId = notification.id
}, },
focusSidebar () {
Event.$emit('focus-sidebar')
},
handleKey (event) { handleKey (event) {
switch (event.srcKey) { switch (event.srcKey) {
case 'next': case 'next':

View File

@ -7,6 +7,7 @@
:overlaid="overlaid" :overlaid="overlaid"
@focusNext="$emit('focusNext')" @focusNext="$emit('focusNext')"
@focusPrev="$emit('focusPrev')" @focusPrev="$emit('focusPrev')"
@focusRight="$emit('focusRight')"
@select="$emit('selectNotification')" @select="$emit('selectNotification')"
> >
</favourite> </favourite>
@ -26,6 +27,7 @@
:overlaid="overlaid" :overlaid="overlaid"
@focusNext="$emit('focusNext')" @focusNext="$emit('focusNext')"
@focusPrev="$emit('focusPrev')" @focusPrev="$emit('focusPrev')"
@focusRight="$emit('focusRight')"
@select="$emit('selectNotification')" @select="$emit('selectNotification')"
> >
</mention> </mention>
@ -36,6 +38,7 @@
:overlaid="overlaid" :overlaid="overlaid"
@focusNext="$emit('focusNext')" @focusNext="$emit('focusNext')"
@focusPrev="$emit('focusPrev')" @focusPrev="$emit('focusPrev')"
@focusRight="$emit('focusRight')"
@select="$emit('selectNotification')" @select="$emit('selectNotification')"
> >
</reblog> </reblog>

View File

@ -2,7 +2,7 @@
<div <div
class="status" class="status"
tabIndex="0" tabIndex="0"
v-shortkey="shortcutEnabled ? {next: ['j'], prev: ['k'], open: ['o'], profile: ['p']} : {}" v-shortkey="shortcutEnabled ? {next: ['j'], prev: ['k'], right: ['l'], left: ['h'], open: ['o'], profile: ['p']} : {}"
@shortkey="handleStatusControl" @shortkey="handleStatusControl"
ref="status" ref="status"
@click="$emit('select')" @click="$emit('select')"
@ -230,6 +230,12 @@ export default {
case 'prev': case 'prev':
this.$emit('focusPrev') this.$emit('focusPrev')
break break
case 'right':
this.$emit('focusRight')
break
case 'left':
this.$emit('focusLeft')
break
case 'open': case 'open':
this.openDetail(this.message.status) this.openDetail(this.message.status)
break break

View File

@ -8,6 +8,7 @@
v-on:update="updateToot" v-on:update="updateToot"
@focusNext="$emit('focusNext')" @focusNext="$emit('focusNext')"
@focusPrev="$emit('focusPrev')" @focusPrev="$emit('focusPrev')"
@focusRight="$emit('focusRight')"
@selectToot="$emit('select')" @selectToot="$emit('select')"
> >
</toot> </toot>

View File

@ -2,7 +2,7 @@
<div <div
class="status" class="status"
tabIndex="0" tabIndex="0"
v-shortkey="shortcutEnabled ? {next: ['j'], prev: ['k'], open: ['o'], profile: ['p']} : {}" v-shortkey="shortcutEnabled ? {next: ['j'], prev: ['k'], right: ['l'], left: ['h'], open: ['o'], profile: ['p']} : {}"
@shortkey="handleStatusControl" @shortkey="handleStatusControl"
ref="status" ref="status"
@click="$emit('select')" @click="$emit('select')"
@ -228,6 +228,12 @@ export default {
case 'prev': case 'prev':
this.$emit('focusPrev') this.$emit('focusPrev')
break break
case 'right':
this.$emit('focusRight')
break
case 'left':
this.$emit('focusLeft')
break
case 'open': case 'open':
this.openDetail(this.message.status) this.openDetail(this.message.status)
break break