(event: KeyboardEvent)
| 112 | useKeyboard( |
| 113 | { |
| 114 | onKeyUp(event: KeyboardEvent) { |
| 115 | const element = document.activeElement; |
| 116 | if (element && element.id) { |
| 117 | return false; |
| 118 | } |
| 119 | if (!currentUser) { |
| 120 | return false; |
| 121 | } |
| 122 | function scrollToBottomThread(threadId: string) { |
| 123 | const node = document.getElementById(threadId); |
| 124 | const layout = document.getElementById('sidebar-layout-left'); |
| 125 | const footer = document.getElementById('chat-layout-footer'); |
| 126 | if (node && layout && footer) { |
| 127 | node.scrollIntoView({ block: 'end' }); |
| 128 | const offset = footer.clientHeight; |
| 129 | layout.scrollTop = layout.scrollTop + offset; |
| 130 | } |
| 131 | } |
| 132 | function selectPreviousThread() { |
| 133 | const index = threads.findIndex( |
| 134 | (thread) => thread.id === currentThreadId |
| 135 | ); |
| 136 | if (index > 0) { |
| 137 | const threadId = threads[index - 1].id; |
| 138 | setCurrentThreadId(threadId); |
| 139 | scrollToBottomThread(threadId); |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | function selectNextThread() { |
| 144 | const index = threads.findIndex( |
| 145 | (thread) => thread.id === currentThreadId |
| 146 | ); |
| 147 | if (index < threads.length - 1) { |
| 148 | const threadId = threads[index + 1].id; |
| 149 | setCurrentThreadId(threadId); |
| 150 | scrollToBottomThread(threadId); |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | if (currentThreadId && (event.key === 'ArrowUp' || event.key === 'k')) { |
| 155 | selectPreviousThread(); |
| 156 | } else if ( |
| 157 | currentThreadId && |
| 158 | (event.key === 'ArrowDown' || event.key === 'j') |
| 159 | ) { |
| 160 | selectNextThread(); |
| 161 | } else if ( |
| 162 | SHORTCUTS_ENABLED && |
| 163 | currentThreadId && |
| 164 | event.shiftKey && |
| 165 | event.key === 'E' |
| 166 | ) { |
| 167 | markUserThreadStatuses(currentThreadId, { |
| 168 | muted: false, |
| 169 | read: false, |
| 170 | reminder: false, |
| 171 | }); |
no test coverage detected