From 1de436c589810c24003321b714299c881e91b6f5 Mon Sep 17 00:00:00 2001
From: AkiraFukushima
Date: Wed, 28 Nov 2018 22:39:46 +0900
Subject: [PATCH] refs #750 Switch focus between Home and Toot Detail using
shortcut keys
---
.../TimelineSpace/Contents/Home.vue | 19 +++-
.../Contents/SideBar/TootDetail.vue | 91 +++++++++++++++++--
src/renderer/components/event.js | 3 +
src/renderer/components/molecules/Toot.vue | 8 +-
4 files changed, 110 insertions(+), 11 deletions(-)
create mode 100644 src/renderer/components/event.js
diff --git a/src/renderer/components/TimelineSpace/Contents/Home.vue b/src/renderer/components/TimelineSpace/Contents/Home.vue
index 9f5b89ec..49a308ec 100644
--- a/src/renderer/components/TimelineSpace/Contents/Home.vue
+++ b/src/renderer/components/TimelineSpace/Contents/Home.vue
@@ -14,6 +14,7 @@
v-on:delete="deleteToot"
@focusNext="focusNext"
@focusPrev="focusPrev"
+ @focusRight="focusSidebar"
@selectToot="focusToot(message)"
>
@@ -33,6 +34,7 @@ import { mapState, mapGetters } from 'vuex'
import Toot from '~/src/renderer/components/molecules/Toot'
import scrollTop from '../../utils/scroll'
import reloadable from '~/src/renderer/components/mixins/reloadable'
+import { Event } from '~/src/renderer/components/event'
export default {
name: 'home',
@@ -40,7 +42,8 @@ export default {
mixins: [reloadable],
data () {
return {
- focusedId: null
+ focusedId: null,
+ backupFocusedId: null
}
},
computed: {
@@ -85,12 +88,23 @@ export default {
mounted () {
this.$store.commit('TimelineSpace/SideMenu/changeUnreadHomeTimeline', false)
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 () {
if (this.$store.state.TimelineSpace.SideMenu.unreadHomeTimeline && this.heading) {
this.$store.commit('TimelineSpace/SideMenu/changeUnreadHomeTimeline', false)
}
},
+ beforeDestroy () {
+ Event.$off('focus-timeline')
+ },
destroyed () {
this.$store.commit('TimelineSpace/Contents/Home/changeHeading', true)
this.$store.commit('TimelineSpace/Contents/Home/mergeTimeline')
@@ -178,6 +192,9 @@ export default {
focusToot (message) {
this.focusedId = message.uri + message.id
},
+ focusSidebar () {
+ Event.$emit('focus-sidebar')
+ },
handleKey (event) {
switch (event.srcKey) {
case 'next':
diff --git a/src/renderer/components/TimelineSpace/Contents/SideBar/TootDetail.vue b/src/renderer/components/TimelineSpace/Contents/SideBar/TootDetail.vue
index 09b7dce2..a5b4cecd 100644
--- a/src/renderer/components/TimelineSpace/Contents/SideBar/TootDetail.vue
+++ b/src/renderer/components/TimelineSpace/Contents/SideBar/TootDetail.vue
@@ -1,39 +1,91 @@