Skip to content

Commit

Permalink
add: j/k shortcuts
Browse files Browse the repository at this point in the history
add: make first attempt to jump to previous and next feed item

fix: linter errors

fix: use correct feed items

fix: use filterSortedItems()

add: trigger click event programmatically to benefit from item handling
inside FeedItemRow component

add: use a proper item if none is selected

fix: remove not needed MUTATIONS import

add: attempt to scroll to clicked item

doc: add changelog text

Signed-off-by: Patrizio Bekerle <[email protected]>
  • Loading branch information
pbek authored and Grotax committed Jun 2, 2024
1 parent 9ff0f77 commit ea71ace
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ You can also check [on GitHub](https://github.com/nextcloud/news/releases), the
## [25.x.x]
### Changed
- added alternative development environment (#2670)
- Implement `j` and `k` keyboards shortcuts for navigating through feed items (#2671)

### Fixed

Expand Down
39 changes: 39 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"lodash": "^4.17.21",
"vue": "^2.7.16",
"vue-router": "^3.5.3",
"vue-shortkey": "^3.1.7",
"vuex": "^3.6.2"
},
"browserslist": [
Expand Down
60 changes: 59 additions & 1 deletion src/components/feed-display/FeedItemDisplayList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,20 @@
</template>
</NcActionButton>
</NcActions>
<button v-shortkey="['k']" class="hidden" @shortkey="jumpToPreviousItem">
Prev
</button>
<button v-shortkey="['j']" class="hidden" @shortkey="jumpToNextItem">
Next
</button>
</div>
<div class="feed-item-display-container">
<VirtualScroll :reached-end="reachedEnd"
:fetch-key="fetchKey"
@load-more="fetchMore()">
<template v-if="items && items.length > 0">
<template v-for="item in filterSortedItems()">
<FeedItemRow :key="item.id" :item="item" />
<FeedItemRow :key="item.id" :ref="'feedItemRow' + item.id" :item="item" />
</template>
</template>
</VirtualScroll>
Expand Down Expand Up @@ -124,6 +130,9 @@ export default Vue.extend({
cfg() {
return _.defaults({ ...this.config }, DEFAULT_DISPLAY_LIST_CONFIG)
},
selectedItem() {
return this.$store.getters.selected
},
},
mounted() {
this.mounted = true
Expand Down Expand Up @@ -175,6 +184,55 @@ export default Vue.extend({
return response.sort(this.sort)
},
// Trigger the click event programmatically to benefit from the item handling inside the FeedItemRow component
clickItem(item: FeedItem) {
const refName = 'feedItemRow' + item.id
const ref = this.$refs[refName]
// Make linter happy
const componentInstance = Array.isArray(ref) && ref.length && ref.length > 0 ? ref[0] : undefined
const element = componentInstance ? componentInstance.$el : undefined
if (element) {
element.click()
// TODO: This doesn't seem to do a lot in the VirtualScroll component
element.scrollIntoView(true)
// this.$nextTick(() => element.scrollIntoView())
}
},
currentIndex(items: FeedItem[]): number {
return this.selectedItem ? items.findIndex((item: FeedItem) => item.id === this.selectedItem.id) || 0 : -1
},
// TODO: Make jumpToPreviousItem() highlight the current item
jumpToPreviousItem() {
console.log('Previous item')

Check warning on line 208 in src/components/feed-display/FeedItemDisplayList.vue

View workflow job for this annotation

GitHub Actions / eslint node

Unexpected console statement
const items = this.filterSortedItems()
let currentIndex = this.currentIndex(items)
console.log('currentIndex', currentIndex)

Check warning on line 211 in src/components/feed-display/FeedItemDisplayList.vue

View workflow job for this annotation

GitHub Actions / eslint node

Unexpected console statement
// Prepare to jump to the first item, if none was selected
if (currentIndex === -1) {
currentIndex = 1
}
// Jump to the previous item
if (currentIndex > 0) {
const previousItem = items[currentIndex - 1]
console.log('previousItem', previousItem)

Check warning on line 219 in src/components/feed-display/FeedItemDisplayList.vue

View workflow job for this annotation

GitHub Actions / eslint node

Unexpected console statement
this.clickItem(previousItem)
}
},
// TODO: Make jumpToNextItem() highlight the current item
jumpToNextItem() {
console.log('Next item')

Check warning on line 225 in src/components/feed-display/FeedItemDisplayList.vue

View workflow job for this annotation

GitHub Actions / eslint node

Unexpected console statement
const items = this.filterSortedItems()
const currentIndex = this.currentIndex(items)
console.log('currentIndex', currentIndex)

Check warning on line 228 in src/components/feed-display/FeedItemDisplayList.vue

View workflow job for this annotation

GitHub Actions / eslint node

Unexpected console statement
// Jump to the first item, if none was selected, otherwise jump to the next item
if (currentIndex === -1 || (currentIndex < items.length - 1)) {
const nextItem = items[currentIndex + 1]
console.log('nextItem', nextItem)

Check warning on line 232 in src/components/feed-display/FeedItemDisplayList.vue

View workflow job for this annotation

GitHub Actions / eslint node

Unexpected console statement
this.clickItem(nextItem)
}
},
},
})
</script>
Expand Down
1 change: 1 addition & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Vue.prototype.OCA = OCA

Vue.use(Vuex)
Vue.use(VueRouter)
Vue.use(require('vue-shortkey'))

Vue.directive('tooltip', Tooltip)

Expand Down

0 comments on commit ea71ace

Please sign in to comment.