refs #543 Fix focus logic in public

This commit is contained in:
AkiraFukushima 2018-08-22 12:53:01 +09:00
parent 6cbda0a94a
commit 9e17d42cac
3 changed files with 21 additions and 19 deletions

View File

@ -80,7 +80,7 @@ export default {
}) })
} }
}, },
focusedIndex: function (newState, oldState) { focusedId: function (newState, oldState) {
if (newState && this.heading) { if (newState && this.heading) {
this.heading = false this.heading = false
} else if (newState === null && !this.heading) { } else if (newState === null && !this.heading) {

View File

@ -78,7 +78,7 @@ export default {
}) })
} }
}, },
focusedIndex: function (newState, oldState) { focusedId: function (newState, oldState) {
if (newState && this.heading) { if (newState && this.heading) {
this.$store.commit('TimelineSpace/Contents/Local/changeHeading', false) this.$store.commit('TimelineSpace/Contents/Local/changeHeading', false)
} else if (newState === null && !this.heading) { } else if (newState === null && !this.heading) {

View File

@ -4,16 +4,16 @@
<div v-shortkey="{linux: ['ctrl', 'r'], mac: ['meta', 'r']}" @shortkey="reload()"> <div v-shortkey="{linux: ['ctrl', 'r'], mac: ['meta', 'r']}" @shortkey="reload()">
</div> </div>
<transition-group name="timeline" tag="div"> <transition-group name="timeline" tag="div">
<div class="public-timeline" v-for="(message, index) in timeline" :key="message.uri"> <div class="public-timeline" v-for="message in timeline" :key="message.uri">
<toot <toot
:message="message" :message="message"
:filter="filter" :filter="filter"
:focused="index === focusedIndex" :focused="message.uri === focusedId"
v-on:update="updateToot" v-on:update="updateToot"
v-on:delete="deleteToot" v-on:delete="deleteToot"
@focusNext="focusNext" @focusNext="focusNext"
@focusPrev="focusPrev" @focusPrev="focusPrev"
@selectToot="focusToot(index)" @selectToot="focusToot(message)"
> >
</toot> </toot>
</div> </div>
@ -37,7 +37,7 @@ export default {
components: { Toot }, components: { Toot },
data () { data () {
return { return {
focusedIndex: null focusedId: null
} }
}, },
computed: { computed: {
@ -81,8 +81,8 @@ export default {
}) })
} }
}, },
focusedIndex: function (newState, oldState) { focusedId: function (newState, oldState) {
if (newState >= 0 && this.heading) { if (newState && this.heading) {
this.$store.commit('TimelineSpace/Contents/Public/changeHeading', false) this.$store.commit('TimelineSpace/Contents/Public/changeHeading', false)
} else if (newState === null && !this.heading) { } else if (newState === null && !this.heading) {
this.$store.commit('TimelineSpace/Contents/Public/changeHeading', true) this.$store.commit('TimelineSpace/Contents/Public/changeHeading', true)
@ -174,24 +174,26 @@ export default {
document.getElementById('scrollable'), document.getElementById('scrollable'),
0 0
) )
this.focusedIndex = null this.focusedId = null
}, },
focusNext () { focusNext () {
if (this.focusedIndex === null) { const currentIndex = this.timeline.findIndex(toot => this.focusedId === toot.uri)
this.focusedIndex = 0 if (currentIndex === -1) {
} else if (this.focusedIndex < this.timeline.length) { this.focusedId = this.timeline[0].uri
this.focusedIndex++ } else if (currentIndex < this.timeline.length) {
this.focusedId = this.timeline[currentIndex + 1].uri
} }
}, },
focusPrev () { focusPrev () {
if (this.focusedIndex === 0) { const currentIndex = this.timeline.findIndex(toot => this.focusedId === toot.uri)
this.focusedIndex = null if (currentIndex === 0) {
} else if (this.focusedIndex > 0) { this.focusedId = null
this.focusedIndex-- } else if (currentIndex > 0) {
this.focusedId = this.timeline[currentIndex - 1].uri
} }
}, },
focusToot (index) { focusToot (message) {
this.focusedIndex = index this.focusedId = message.uri
} }
} }
} }