Merge pull request #756 from h3poteto/iss-750

closes #750 Switch focus between Timelines and Account Profile using shortcut keys
This commit is contained in:
AkiraFukushima 2018-11-30 00:54:19 +09:00 committed by GitHub
commit ed4ad74dbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 84 additions and 10 deletions

View File

@ -1,10 +1,35 @@
<template> <template>
<div id="account_timeline"> <div id="account_timeline">
<template v-for="message in pinnedToots"> <template v-for="message in pinnedToots">
<toot :message="message" :key="message.id" v-on:update="updateToot" v-on:delete="deleteToot" :pinned="true"></toot> <toot
:message="message"
:key="message.id"
:focused="message.uri + message.id === focusedId"
:pinned="true"
:overlaid="modalOpened"
v-on:update="updateToot"
v-on:delete="deleteToot"
@focusNext="focusNext"
@focusPrev="focusPrev"
@focusLeft="focusTimeline"
@selectToot="focusToot(message)"
>
</toot>
</template> </template>
<template v-for="message in timeline"> <template v-for="message in timeline">
<toot :message="message" :key="message.id" v-on:update="updateToot" v-on:delete="deleteToot"></toot> <toot
:message="message"
:key="message.id"
: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>
</template> </template>
<div class="loading-card" v-loading="lazyLoading" :element-loading-background="backgroundColor"> <div class="loading-card" v-loading="lazyLoading" :element-loading-background="backgroundColor">
</div> </div>
@ -12,20 +37,31 @@
</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: 'timeline', name: 'timeline',
props: [ 'account' ], props: [ 'account' ],
components: { Toot }, components: { Toot },
data () {
return {
focusedId: null
}
},
computed: { computed: {
...mapState({ ...mapState('TimelineSpace/Contents/SideBar/AccountProfile/Timeline', {
timeline: state => state.TimelineSpace.Contents.SideBar.AccountProfile.Timeline.timeline, timeline: state => state.timeline,
pinnedToots: state => state.TimelineSpace.Contents.SideBar.AccountProfile.Timeline.pinnedToots, pinnedToots: state => state.pinnedToots,
lazyLoading: state => state.TimelineSpace.Contents.SideBar.AccountProfile.Timeline.lazyLoading, lazyLoading: state => state.lazyLoading
backgroundColor: state => state.App.theme.background_color }),
}) ...mapState('App', {
backgroundColor: state => state.theme.background_color
}),
...mapGetters('TimelineSpace/Modals', [
'modalOpened'
])
}, },
created () { created () {
this.load() this.load()
@ -33,6 +69,16 @@ export default {
mounted () { mounted () {
this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/Timeline/clearTimeline') this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/Timeline/clearTimeline')
document.getElementById('sidebar_scrollable').addEventListener('scroll', this.onScroll) document.getElementById('sidebar_scrollable').addEventListener('scroll', this.onScroll)
Event.$on('focus-sidebar', () => {
this.focusedId = 0
this.$nextTick(function () {
this.focusedId = this.timeline[0].uri + this.timeline[0].id
})
})
},
beforeDestroy () {
Event.$emit('focus-timeline')
Event.$off('focus-sidebar')
}, },
destroyed () { destroyed () {
if (document.getElementById('sidebar_scrollable') !== undefined && document.getElementById('sidebar_scrollable') !== null) { if (document.getElementById('sidebar_scrollable') !== undefined && document.getElementById('sidebar_scrollable') !== null) {
@ -77,6 +123,27 @@ export default {
}, },
deleteToot (message) { deleteToot (message) {
this.$store.commit('TimelineSpace/Contents/SideBar/AccountProfile/Timeline/deleteToot', message) this.$store.commit('TimelineSpace/Contents/SideBar/AccountProfile/Timeline/deleteToot', 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')
} }
} }
} }

View File

@ -71,6 +71,8 @@ export default {
}, },
created () { created () {
this.load() this.load()
},
mounted () {
Event.$on('focus-sidebar', () => { Event.$on('focus-sidebar', () => {
this.focusedId = 0 this.focusedId = 0
this.$nextTick(function () { this.$nextTick(function () {
@ -84,6 +86,7 @@ export default {
} }
}, },
beforeDestroy () { beforeDestroy () {
Event.$emit('focus-timeline')
Event.$off('focus-sidebar') Event.$off('focus-sidebar')
}, },
methods: { methods: {

View File

@ -17,6 +17,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')"
> >
</follow> </follow>

View File

@ -2,7 +2,7 @@
<div <div
class="follow" class="follow"
tabIndex="0" tabIndex="0"
v-shortkey="shortcutEnabled ? {next: ['j'], prev: ['k'], profile: ['p']} : {}" v-shortkey="shortcutEnabled ? {next: ['j'], prev: ['k'], right: ['l'], profile: ['p']} : {}"
@shortkey="handleStatusControl" @shortkey="handleStatusControl"
ref="status" ref="status"
@click="$emit('select')" @click="$emit('select')"
@ -91,6 +91,9 @@ export default {
case 'prev': case 'prev':
this.$emit('focusPrev') this.$emit('focusPrev')
break break
case 'right':
this.$emit('focusRight')
break
case 'profile': case 'profile':
this.openUser(this.message.account) this.openUser(this.message.account)
break break