Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keyboard navigation #2671

Merged
merged 1 commit into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@

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

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

View workflow job for this annotation

GitHub Actions / eslint

Unexpected console statement

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

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

View workflow job for this annotation

GitHub Actions / eslint

Unexpected console statement

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

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

View workflow job for this annotation

GitHub Actions / eslint

Unexpected console statement

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

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

View workflow job for this annotation

GitHub Actions / eslint

Unexpected console statement

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

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

View workflow job for this annotation

GitHub Actions / eslint

Unexpected console statement

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

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

View workflow job for this annotation

GitHub Actions / eslint

Unexpected console statement

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
Loading