MCPcopy Create free account
hub / github.com/dailydotdev/apps / onKeyDown

Function onKeyDown

packages/shared/src/components/BookmarkFeedLayout.tsx:601–635  ·  view source on GitHub ↗
(event: KeyboardEvent<HTMLElement>, post: Post)

Source from the content-addressed store, hash-verified

599 };
600
601 const onKeyDown = (event: KeyboardEvent<HTMLElement>, post: Post) => {
602 if (event.metaKey || event.ctrlKey || event.altKey) {
603 return;
604 }
605
606 const index = posts.indexOf(post);
607
608 if (event.key === 'ArrowDown' || event.key === 'j') {
609 event.preventDefault();
610 select(posts[Math.min(index + 1, posts.length - 1)]);
611 return;
612 }
613
614 if (event.key === 'ArrowUp' || event.key === 'k') {
615 event.preventDefault();
616 select(posts[Math.max(index - 1, 0)]);
617 return;
618 }
619
620 if (event.key === 'Enter') {
621 event.preventDefault();
622 router.push(getPostPath(post));
623 return;
624 }
625
626 if (event.key === 'Delete') {
627 event.preventDefault();
628 const next = posts[index + 1] ?? posts[index - 1];
629 removeBookmark(post);
630 if (next) {
631 // The row is focused once the list has re-rendered without the post.
632 setTimeout(() => focusRow(next.id));
633 }
634 }
635 };
636
637 const { plusEntryBookmark } = usePlusEntry();
638

Callers 1

BookmarkFeedLayoutFunction · 0.70

Calls 5

getPostPathFunction · 0.90
removeBookmarkFunction · 0.85
pushMethod · 0.80
selectFunction · 0.70
focusRowFunction · 0.70

Tested by

no test coverage detected