From 3fd8e5a06a353b38b73d8544880a71cfee976980 Mon Sep 17 00:00:00 2001 From: Onur Date: Sat, 24 Feb 2024 18:01:08 +0300 Subject: [PATCH] chore: miscellaneous updates (#70) --- src/app/layout.js | 3 +-- src/app/workspace/page.js | 4 +++- src/components/bookmark-card.js | 13 +++++++------ src/components/bookmark-list.jsx | 6 +++--- src/components/drawer.js | 10 +++++++--- src/components/side-menu.js | 32 +++++++++++++++----------------- src/hooks/useKeyPress.js | 2 +- 7 files changed, 37 insertions(+), 33 deletions(-) diff --git a/src/app/layout.js b/src/app/layout.js index d6fc5d01..d29d2282 100644 --- a/src/app/layout.js +++ b/src/app/layout.js @@ -90,6 +90,5 @@ export const viewport = { themeColor: 'white', colorScheme: 'only light', width: 'device-width', - initialScale: 1, - maximumScale: 1 + initialScale: 1 } diff --git a/src/app/workspace/page.js b/src/app/workspace/page.js index e7082e49..f9f2266b 100644 --- a/src/app/workspace/page.js +++ b/src/app/workspace/page.js @@ -16,7 +16,7 @@ export default async function Workspace() {
-
+
diff --git a/src/components/bookmark-card.js b/src/components/bookmark-card.js index 862cf62c..4d6ba4a7 100644 --- a/src/components/bookmark-card.js +++ b/src/components/bookmark-card.js @@ -3,7 +3,7 @@ import { Link2Icon } from 'lucide-react' import { TweetCard } from '@/components/tweet-card/tweet-card' import { TWEETS_COLLECTION_ID } from '@/lib/constants' -export const BookmarkCard = ({ bookmark }) => { +export const BookmarkCard = ({ bookmark, order }) => { if (bookmark.link && bookmark.collectionId === TWEETS_COLLECTION_ID) { const match = bookmark.link.match(/\/status\/(\d+)/) ?? [] const tweetId = match[1] @@ -17,15 +17,16 @@ export const BookmarkCard = ({ bookmark }) => { href={bookmark.link} target="_blank" rel="noopener noreferrer" + data-bookmark-order={order} > {bookmark.title} { e.target.onerror = null e.target.src = '/assets/fallback.webp' @@ -33,8 +34,8 @@ export const BookmarkCard = ({ bookmark }) => { />
-

{bookmark.title}

- +

{bookmark.title}

+ {bookmark.domain} diff --git a/src/components/bookmark-list.jsx b/src/components/bookmark-list.jsx index 29186930..3ac6d027 100644 --- a/src/components/bookmark-list.jsx +++ b/src/components/bookmark-list.jsx @@ -60,7 +60,7 @@ export const BookmarkList = ({ initialData, id }) => { key={`bookmark_${bookmarkIndex}`} className={cn('grid gap-4', isTweetCollection ? 'h-fit' : 'place-content-start')} > - +
) })} @@ -72,8 +72,8 @@ export const BookmarkList = ({ initialData, id }) => { key={`chunk_${chunkIndex}`} className={cn('grid gap-4', isTweetCollection ? 'h-fit' : 'place-content-start')} > - {chunk.map((bookmark) => { - return + {chunk.map((bookmark, bookmarkIndex) => { + return })}
) diff --git a/src/components/drawer.js b/src/components/drawer.js index 34cb3b4c..2261241f 100644 --- a/src/components/drawer.js +++ b/src/components/drawer.js @@ -15,9 +15,13 @@ export function MobileDrawer() { -
-
- +
+
+
+
+
+ +
diff --git a/src/components/side-menu.js b/src/components/side-menu.js index 047420f6..5330e4c8 100644 --- a/src/components/side-menu.js +++ b/src/components/side-menu.js @@ -1,5 +1,5 @@ 'use client' -import { useRouter } from 'next/navigation' +import { useRouter, usePathname } from 'next/navigation' import Link from 'next/link' import { RadioIcon } from 'lucide-react' @@ -8,26 +8,24 @@ import { Button } from '@/components/ui/button.jsx' import { useKeyPress } from '@/hooks/useKeyPress' import { cn } from '@/lib/utils' +const keyCodePathnameMapping = { + Digit1: '/', + Digit2: '/writing', + Digit3: '/journey', + Digit4: '/stack', + Digit5: '/workspace', + Digit6: '/bookmarks' +} + export const SideMenu = ({ children, title, href, isInner }) => { const router = useRouter() - useKeyPress(onKeyPress, ['Digit1', 'Digit2', 'Digit3', 'Digit4', 'Digit5', 'Digit6']) + const pathname = usePathname() + useKeyPress(onKeyPress, Object.keys(keyCodePathnameMapping)) function onKeyPress(event) { - event.preventDefault() - - if (event.code === 'Digit1') { - router.push('/') - } else if (event.code === 'Digit2') { - router.push('/writing') - } else if (event.code === 'Digit3') { - router.push('/journey') - } else if (event.code === 'Digit4') { - router.push('/stack') - } else if (event.code === 'Digit5') { - router.push('/workspace') - } else if (event.code === 'Digit6') { - router.push('/bookmarks') - } + const key = event.code + const targetPathname = keyCodePathnameMapping[key] + if (targetPathname && targetPathname !== pathname) router.push(targetPathname) } const isWritingHref = href === '/writing' diff --git a/src/hooks/useKeyPress.js b/src/hooks/useKeyPress.js index 74a639d1..70790efb 100644 --- a/src/hooks/useKeyPress.js +++ b/src/hooks/useKeyPress.js @@ -8,7 +8,7 @@ export function useKeyPress(callback, keyCodes) { } } - window.addEventListener('keydown', handler) + window.addEventListener('keydown', handler, { passive: true }) return () => { window.removeEventListener('keydown', handler) }