refs #750 Switch focus between Home and Toot Detail using shortcut keys
This commit is contained in:
parent
d9e0065c4e
commit
1de436c589
@ -14,6 +14,7 @@
|
|||||||
v-on:delete="deleteToot"
|
v-on:delete="deleteToot"
|
||||||
@focusNext="focusNext"
|
@focusNext="focusNext"
|
||||||
@focusPrev="focusPrev"
|
@focusPrev="focusPrev"
|
||||||
|
@focusRight="focusSidebar"
|
||||||
@selectToot="focusToot(message)"
|
@selectToot="focusToot(message)"
|
||||||
>
|
>
|
||||||
</toot>
|
</toot>
|
||||||
@ -33,6 +34,7 @@ import { mapState, mapGetters } from 'vuex'
|
|||||||
import Toot from '~/src/renderer/components/molecules/Toot'
|
import Toot from '~/src/renderer/components/molecules/Toot'
|
||||||
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: 'home',
|
name: 'home',
|
||||||
@ -40,7 +42,8 @@ export default {
|
|||||||
mixins: [reloadable],
|
mixins: [reloadable],
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
focusedId: null
|
focusedId: null,
|
||||||
|
backupFocusedId: null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -85,12 +88,23 @@ export default {
|
|||||||
mounted () {
|
mounted () {
|
||||||
this.$store.commit('TimelineSpace/SideMenu/changeUnreadHomeTimeline', false)
|
this.$store.commit('TimelineSpace/SideMenu/changeUnreadHomeTimeline', false)
|
||||||
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.unreadHomeTimeline && this.heading) {
|
if (this.$store.state.TimelineSpace.SideMenu.unreadHomeTimeline && this.heading) {
|
||||||
this.$store.commit('TimelineSpace/SideMenu/changeUnreadHomeTimeline', false)
|
this.$store.commit('TimelineSpace/SideMenu/changeUnreadHomeTimeline', false)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
beforeDestroy () {
|
||||||
|
Event.$off('focus-timeline')
|
||||||
|
},
|
||||||
destroyed () {
|
destroyed () {
|
||||||
this.$store.commit('TimelineSpace/Contents/Home/changeHeading', true)
|
this.$store.commit('TimelineSpace/Contents/Home/changeHeading', true)
|
||||||
this.$store.commit('TimelineSpace/Contents/Home/mergeTimeline')
|
this.$store.commit('TimelineSpace/Contents/Home/mergeTimeline')
|
||||||
@ -178,6 +192,9 @@ export default {
|
|||||||
focusToot (message) {
|
focusToot (message) {
|
||||||
this.focusedId = message.uri + message.id
|
this.focusedId = message.uri + message.id
|
||||||
},
|
},
|
||||||
|
focusSidebar () {
|
||||||
|
Event.$emit('focus-sidebar')
|
||||||
|
},
|
||||||
handleKey (event) {
|
handleKey (event) {
|
||||||
switch (event.srcKey) {
|
switch (event.srcKey) {
|
||||||
case 'next':
|
case 'next':
|
||||||
|
@ -1,39 +1,91 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="toot-detail" ref="detail">
|
<div class="toot-detail" ref="detail">
|
||||||
<div class="toot-ancestors" v-for="(message, index) in ancestors" v-bind:key="'ancestors-' + index">
|
<div class="toot-ancestors" v-for="(message, index) in ancestors" v-bind:key="'ancestors-' + index">
|
||||||
<toot :message="message" v-on:update="updateAncestorsToot" v-on:delete="deleteAncestorsToot"></toot>
|
<toot
|
||||||
|
:message="message"
|
||||||
|
:focused="message.uri + message.id === focusedId"
|
||||||
|
:overlaid="modalOpened"
|
||||||
|
v-on:update="updateAncestorsToot"
|
||||||
|
v-on:delete="deleteAncestorsToot"
|
||||||
|
@focusNext="focusNext"
|
||||||
|
@focusPrev="focusPrev"
|
||||||
|
@focusLeft="focusTimeline"
|
||||||
|
@selectToot="focusToot(message)"
|
||||||
|
>
|
||||||
|
</toot>
|
||||||
</div>
|
</div>
|
||||||
<div class="original-toot" ref="original">
|
<div class="original-toot" ref="original">
|
||||||
<toot :message="message" v-on:update="updateToot" v-on:delete="deleteToot"></toot>
|
<toot
|
||||||
|
:message="message"
|
||||||
|
:focused="message.uri + message.id === focusedId"
|
||||||
|
:overlaid="modalOpened"
|
||||||
|
v-on:update="updateToot"
|
||||||
|
v-on:delete="deleteToot"
|
||||||
|
@focusNext="focusNext"
|
||||||
|
@focusPrev="focusPrev"
|
||||||
|
@focusLeft="focusTimeline"
|
||||||
|
@selectToot="focusToot(message)"
|
||||||
|
>
|
||||||
|
</toot>
|
||||||
</div>
|
</div>
|
||||||
<div class="toot-descendants" v-for="(message, index) in descendants" v-bind:key="'descendants' + index">
|
<div class="toot-descendants" v-for="(message, index) in descendants" v-bind:key="'descendants' + index">
|
||||||
<toot :message="message" v-on:update="updateDescendantsToot" v-on:delete="deleteDescendantsToot"></toot>
|
<toot
|
||||||
|
:message="message"
|
||||||
|
:focused="message.uri + message.id === focusedId"
|
||||||
|
:overlaid="modalOpened"
|
||||||
|
v-on:update="updateDescendantsToot"
|
||||||
|
v-on:delete="deleteDescendantsToot"
|
||||||
|
@focusNext="focusNext"
|
||||||
|
@focusPrev="focusPrev"
|
||||||
|
@focusLeft="focusTimeline"
|
||||||
|
@selectToot="focusToot(message)"
|
||||||
|
>
|
||||||
|
</toot>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { mapState } from 'vuex'
|
import { mapState, mapGetters } from 'vuex'
|
||||||
import Toot from '~/src/renderer/components/molecules/Toot'
|
import Toot from '~/src/renderer/components/molecules/Toot'
|
||||||
|
import { Event } from '~/src/renderer/components/event'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'toot-detail',
|
name: 'toot-detail',
|
||||||
components: { Toot },
|
components: { Toot },
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
focusedId: null
|
||||||
|
}
|
||||||
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapState({
|
...mapState('TimelineSpace/Contents/SideBar/TootDetail', {
|
||||||
message: state => state.TimelineSpace.Contents.SideBar.TootDetail.message,
|
message: state => state.message,
|
||||||
ancestors: state => state.TimelineSpace.Contents.SideBar.TootDetail.ancestors,
|
ancestors: state => state.ancestors,
|
||||||
descendants: state => state.TimelineSpace.Contents.SideBar.TootDetail.descendants
|
descendants: state => state.descendants,
|
||||||
})
|
timeline: state => state.ancestors.concat([state.message]).concat(state.descendants)
|
||||||
|
}),
|
||||||
|
...mapGetters('TimelineSpace/Modals', [
|
||||||
|
'modalOpened'
|
||||||
|
])
|
||||||
},
|
},
|
||||||
created () {
|
created () {
|
||||||
this.load()
|
this.load()
|
||||||
|
Event.$on('focus-sidebar', () => {
|
||||||
|
this.focusedId = 0
|
||||||
|
this.$nextTick(function () {
|
||||||
|
this.focusedId = this.timeline[0].uri + this.timeline[0].id
|
||||||
|
})
|
||||||
|
})
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
message: function () {
|
message: function () {
|
||||||
this.load()
|
this.load()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
beforeDestroy () {
|
||||||
|
Event.$off('focus-sidebar')
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
load () {
|
load () {
|
||||||
this.$store.dispatch('TimelineSpace/Contents/SideBar/TootDetail/fetchToot', this.message)
|
this.$store.dispatch('TimelineSpace/Contents/SideBar/TootDetail/fetchToot', this.message)
|
||||||
@ -65,6 +117,27 @@ export default {
|
|||||||
},
|
},
|
||||||
deleteDescendantsToot (message) {
|
deleteDescendantsToot (message) {
|
||||||
this.$store.commit('TimelineSpace/Contents/SideBar/TootDetail/deleteDescendantsToot', message)
|
this.$store.commit('TimelineSpace/Contents/SideBar/TootDetail/deleteDescendantsToot', message)
|
||||||
|
},
|
||||||
|
focusNext () {
|
||||||
|
const currentIndex = this.timeline.findIndex(toot => this.focusedId === toot.uri + toot.id)
|
||||||
|
if (currentIndex === -1) {
|
||||||
|
this.focusedId = this.timeline[0].uri + this.timeline[0].id
|
||||||
|
} else if (currentIndex < this.timeline.length - 1) {
|
||||||
|
this.focusedId = this.timeline[currentIndex + 1].uri + this.timeline[currentIndex + 1].id
|
||||||
|
}
|
||||||
|
},
|
||||||
|
focusPrev () {
|
||||||
|
const currentIndex = this.timeline.findIndex(toot => this.focusedId === toot.uri + toot.id)
|
||||||
|
if (currentIndex > 0) {
|
||||||
|
this.focusedId = this.timeline[currentIndex - 1].uri + this.timeline[currentIndex - 1].id
|
||||||
|
}
|
||||||
|
},
|
||||||
|
focusToot (message) {
|
||||||
|
this.focusedId = message.uri + message.id
|
||||||
|
},
|
||||||
|
focusTimeline () {
|
||||||
|
this.focusedId = 0
|
||||||
|
Event.$emit('focus-timeline')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
3
src/renderer/components/event.js
Normal file
3
src/renderer/components/event.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import Vue from 'vue'
|
||||||
|
|
||||||
|
export const Event = new Vue()
|
@ -2,7 +2,7 @@
|
|||||||
<div
|
<div
|
||||||
class="status"
|
class="status"
|
||||||
tabIndex="0"
|
tabIndex="0"
|
||||||
v-shortkey="shortcutEnabled ? {next: ['j'], prev: ['k'], reply: ['r'], boost: ['b'], fav: ['f'], open: ['o'], profile: ['p'], image: ['i'], cw: ['x']} : {}"
|
v-shortkey="shortcutEnabled ? {next: ['j'], prev: ['k'], right: ['l'], left: ['h'], reply: ['r'], boost: ['b'], fav: ['f'], open: ['o'], profile: ['p'], image: ['i'], cw: ['x']} : {}"
|
||||||
@shortkey="handleTootControl"
|
@shortkey="handleTootControl"
|
||||||
ref="status"
|
ref="status"
|
||||||
@click="$emit('selectToot')"
|
@click="$emit('selectToot')"
|
||||||
@ -452,6 +452,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 'reply':
|
case 'reply':
|
||||||
this.openReply(this.message)
|
this.openReply(this.message)
|
||||||
break
|
break
|
||||||
|
Loading…
x
Reference in New Issue
Block a user