refs #543 Fix focus logic in favourite

This commit is contained in:
AkiraFukushima 2018-08-22 12:38:18 +09:00
parent cb8dfd51c9
commit 545efb9d44
2 changed files with 19 additions and 17 deletions

View File

@ -2,16 +2,16 @@
<div id="favourites">
<div v-shortkey="{linux: ['ctrl', 'r'], mac: ['meta', 'r']}" @shortkey="reload()">
</div>
<div class="fav" v-for="(message, index) in favourites" v-bind:key="message.id">
<div class="fav" v-for="message in favourites" v-bind:key="message.id">
<toot
:message="message"
:filter="filter"
:focused="index === focusedIndex"
:focused="message.uri === focusedId"
v-on:update="updateToot"
v-on:delete="deleteToot"
@focusNext="focusNext"
@focusPrev="focusPrev"
@selectToot="focusToot(index)"
@selectToot="focusToot(message)"
>
</toot>
</div>
@ -35,7 +35,7 @@ export default {
data () {
return {
heading: true,
focusedIndex: null
focusedId: null
}
},
computed: {
@ -81,7 +81,7 @@ export default {
}
},
focusedIndex: function (newState, oldState) {
if (newState >= 0 && this.heading) {
if (newState && this.heading) {
this.heading = false
} else if (newState === null && !this.heading) {
this.heading = true
@ -147,24 +147,26 @@ export default {
document.getElementById('scrollable'),
0
)
this.focusedIndex = null
this.focusedId = null
},
focusNext () {
if (this.focusedIndex === null) {
this.focusedIndex = 0
} else if (this.focusedIndex < this.favourites.length) {
this.focusedIndex++
const currentIndex = this.favourites.findIndex(toot => this.focusedId === toot.uri)
if (currentIndex === -1) {
this.focusedId = this.favourites[0].uri
} else if (currentIndex < this.favourites.length) {
this.focusedId = this.favourites[currentIndex + 1].uri
}
},
focusPrev () {
if (this.focusedIndex === 0) {
this.focusedIndex = null
} else if (this.focusedIndex > 0) {
this.focusedIndex--
const currentIndex = this.favourites.findIndex(toot => this.focusedId === toot.uri)
if (currentIndex === 0) {
this.focusedId = null
} else if (currentIndex > 0) {
this.focusedId = this.favourites[currentIndex - 1].uri
}
},
focusToot (index) {
this.focusedIndex = index
focusToot (message) {
this.focusedId = message.id
}
}
}

View File

@ -4,7 +4,7 @@
<div v-shortkey="{linux: ['ctrl', 'r'], mac: ['meta', 'r']}" @shortkey="reload()">
</div>
<transition-group name="timeline" tag="div">
<div class="home-timeline" v-for="(message, index) in timeline" :key="message.uri">
<div class="home-timeline" v-for="message in timeline" :key="message.uri">
<toot
:message="message"
:filter="filter"