Skip to content

feat(reader): add mark-read and mark-unread shortcuts #16

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

Merged
merged 1 commit into from
Nov 17, 2023
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
4 changes: 3 additions & 1 deletion src/i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
"k": "Previous item",
"o": "Open item",
"u": "Close item",
"v": "Open item in browser"
"v": "Open item in browser",
"shifti": "Mark as read",
"shiftu": "Mark as unread"
}
}
},
Expand Down
4 changes: 3 additions & 1 deletion src/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
"k": "上一条",
"o": "打开条目",
"u": "关闭条目",
"v": "浏览器中打开"
"v": "浏览器中打开",
"shifti": "标记为已读",
"shiftu": "标记为未读"
}
}
},
Expand Down
21 changes: 19 additions & 2 deletions src/ui/apps/reader/keyboard-shortcuts-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ function KeyboardShortcutsPanel() {
keys: ['v'],
text: intl.get('reader.keyboard.keys.v'),
},
{
keys: ['shift', 'i'],
connector: '+',
text: intl.get('reader.keyboard.keys.shifti'),
},
{
keys: ['shift', 'u'],
text: intl.get('reader.keyboard.keys.shiftu'),
connector: '+',
},
].map((item) => {
const keys = item.keys.map((k, index, v) => (
<span
Expand All @@ -87,15 +97,22 @@ function KeyboardShortcutsPanel() {
>
{k}
</span>
{index !== v.length - 1 ? <span> then </span> : null}
{index !== v.length - 1 ? (
<span>
{' '}
{item.connector ?? 'then'}
{' '}
</span>
) : null}
</span>
))

return (
<div
key={item.keys.join('')}
>
<span
className="inline-block w-14 text-right"
className="inline-block w-16 text-right"
>
{keys}
</span>
Expand Down
2 changes: 2 additions & 0 deletions src/ui/apps/reader/use-keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ iregister(['v'], () => {
iregister(['x'], () => readerStore.toggleSelected())
iregister(['*', 'a'], () => readerStore.selectAll())
iregister(['*', 'n'], () => readerStore.deselectAll())
iregister(['shift', 'i'], () => readerStore.markRead())
iregister(['shift', 'u'], () => readerStore.markUnread())

iregister(['g', 's'], () => readerStore.changeTab('starred'))
iregister(['g', 'a'], () => readerStore.changeTab('all'))
Expand Down
9 changes: 7 additions & 2 deletions src/ui/store/reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,16 @@ export class ReaderStore {
articleService.markRead(articles.map((v) => v.id!), status)
}

markRead(id: number | number []) {
private getSelectedIds() {
const articles = this.opened ? [this.activeArticle] : this.articles.filter((v) => v.selected)
return articles.map((v) => v.id!)
}

markRead(id: number | number [] = this.getSelectedIds()) {
this.markReadStatus(id, 1)
}

markUnread(id: number | number []) {
markUnread(id: number | number [] = this.getSelectedIds()) {
this.markReadStatus(id, 0)
}

Expand Down