From f46f4530a6234a79c927f2cff5e82234cd9dfe94 Mon Sep 17 00:00:00 2001 From: Ren Amamiya <123083837+reyamir@users.noreply.github.com> Date: Sun, 7 May 2023 09:12:32 +0700 Subject: [PATCH] add note wrapper --- src/app/daily/pages/index.page.tsx | 2 +- src/app/note/components/base.tsx | 25 ++++++------------- src/app/note/components/content.tsx | 2 +- src/app/note/components/quote.tsx | 18 +++++--------- src/app/note/components/quoteRepost.tsx | 11 ++++----- src/app/note/components/replies/form.tsx | 2 +- src/app/note/components/replies/item.tsx | 2 +- src/app/note/components/replies/list.tsx | 6 ++--- src/app/note/components/wrapper.tsx | 26 ++++++++++++++++++++ src/app/note/pages/index.page.tsx | 31 ++++++------------------ 10 files changed, 58 insertions(+), 67 deletions(-) create mode 100644 src/app/note/components/wrapper.tsx diff --git a/src/app/daily/pages/index.page.tsx b/src/app/daily/pages/index.page.tsx index ed0fcaf1..c6c3201a 100644 --- a/src/app/daily/pages/index.page.tsx +++ b/src/app/daily/pages/index.page.tsx @@ -1,5 +1,5 @@ import { Header } from '@lume/app/daily/components/header'; -import NoteBase from '@lume/app/note/components/base'; +import { NoteBase } from '@lume/app/note/components/base'; import { NoteQuoteRepost } from '@lume/app/note/components/quoteRepost'; import { getNotes } from '@lume/utils/storage'; diff --git a/src/app/note/components/base.tsx b/src/app/note/components/base.tsx index 1a9738de..8be72505 100644 --- a/src/app/note/components/base.tsx +++ b/src/app/note/components/base.tsx @@ -2,28 +2,17 @@ import { NoteContent } from '@lume/app/note/components/content'; import NoteMetadata from '@lume/app/note/components/metadata'; import { NoteParent } from '@lume/app/note/components/parent'; import { NoteDefaultUser } from '@lume/app/note/components/user/default'; +import { NoteWrapper } from '@lume/app/note/components/wrapper'; import { noteParser } from '@lume/utils/parser'; -import { navigate } from 'vite-plugin-ssr/client/router'; - -export default function NoteBase({ event }: { event: any }) { +export const NoteBase = ({ event }: { event: any }) => { const content = noteParser(event); - - const openNote = (e) => { - const selection = window.getSelection(); - if (selection.toString().length === 0) { - navigate(`/app/note?id=${event.parent_id}`); - } else { - e.stopPropagation(); - } - }; + const href = event.parent_id ? `/app/note?id=${event.parent_id}` : `/app/note?id=${event.event_id}`; return ( -
openNote(e)} className="h-min w-full select-text px-3 py-1.5"> +
- {event.parent_id && event.parent_id !== event.event_id && ( - - )} + {event.parent_id && event.parent_id !== event.event_id && }
@@ -32,6 +21,6 @@ export default function NoteBase({ event }: { event: any }) {
-
+ ); -} +}; diff --git a/src/app/note/components/content.tsx b/src/app/note/components/content.tsx index 0d0ce400..cc9d41c7 100644 --- a/src/app/note/components/content.tsx +++ b/src/app/note/components/content.tsx @@ -12,7 +12,7 @@ export const NoteContent = ({ content }: { content: any }) => { , h6: ({ ...props }) => , diff --git a/src/app/note/components/quote.tsx b/src/app/note/components/quote.tsx index c89db377..0dba0e5c 100644 --- a/src/app/note/components/quote.tsx +++ b/src/app/note/components/quote.tsx @@ -1,5 +1,6 @@ import { NoteContent } from '@lume/app/note/components/content'; import { NoteDefaultUser } from '@lume/app/note/components/user/default'; +import { NoteWrapper } from '@lume/app/note/components/wrapper'; import { RelayContext } from '@lume/shared/relayProvider'; import { READONLY_RELAYS } from '@lume/stores/constants'; import { noteParser } from '@lume/utils/parser'; @@ -7,7 +8,6 @@ import { noteParser } from '@lume/utils/parser'; import { memo, useContext } from 'react'; import Skeleton from 'react-loading-skeleton'; import useSWRSubscription from 'swr/subscription'; -import { navigate } from 'vite-plugin-ssr/client/router'; export const NoteQuote = memo(function NoteQuote({ id }: { id: string }) { const pool: any = useContext(RelayContext); @@ -37,17 +37,11 @@ export const NoteQuote = memo(function NoteQuote({ id }: { id: string }) { const content = !error && data ? noteParser(data) : null; - const openNote = (e) => { - const selection = window.getSelection(); - if (selection.toString().length === 0) { - navigate(`/app/note?id=${id}`); - } else { - e.stopPropagation(); - } - }; - return ( -
openNote(e)} className="mb-2 mt-3 flex flex-col rounded-lg border border-zinc-800 p-2 py-3"> + {data ? ( <> @@ -58,6 +52,6 @@ export const NoteQuote = memo(function NoteQuote({ id }: { id: string }) { ) : ( )} -
+ ); }); diff --git a/src/app/note/components/quoteRepost.tsx b/src/app/note/components/quoteRepost.tsx index 07547684..60ce463e 100644 --- a/src/app/note/components/quoteRepost.tsx +++ b/src/app/note/components/quoteRepost.tsx @@ -1,14 +1,13 @@ import { RootNote } from '@lume/app/note/components/rootNote'; import { NoteRepostUser } from '@lume/app/note/components/user/repost'; +import { NoteWrapper } from '@lume/app/note/components/wrapper'; import { getQuoteID } from '@lume/utils/transform'; -import { memo } from 'react'; - -export const NoteQuoteRepost = memo(function NoteQuoteRepost({ event }: { event: any }) { +export const NoteQuoteRepost = ({ event }: { event: any }) => { const rootID = getQuoteID(event.tags); return ( -
+
@@ -16,6 +15,6 @@ export const NoteQuoteRepost = memo(function NoteQuoteRepost({ event }: { event:
-
+ ); -}); +}; diff --git a/src/app/note/components/replies/form.tsx b/src/app/note/components/replies/form.tsx index 3c406208..6079f5c5 100644 --- a/src/app/note/components/replies/form.tsx +++ b/src/app/note/components/replies/form.tsx @@ -36,7 +36,7 @@ export default function NoteReplyForm({ id }: { id: string }) { }; return ( -
+
{account?.pubkey} diff --git a/src/app/note/components/replies/item.tsx b/src/app/note/components/replies/item.tsx index 56b02bc8..532d7510 100644 --- a/src/app/note/components/replies/item.tsx +++ b/src/app/note/components/replies/item.tsx @@ -6,7 +6,7 @@ export default function Reply({ data }: { data: any }) { const content = noteParser(data); return ( -
+
diff --git a/src/app/note/components/replies/list.tsx b/src/app/note/components/replies/list.tsx index 1e7b132d..6bd25681 100644 --- a/src/app/note/components/replies/list.tsx +++ b/src/app/note/components/replies/list.tsx @@ -42,13 +42,13 @@ export default function RepliesList({ id }: { id: string }) { {error &&
failed to load
} {!data ? ( -
+
-
+
-
+
) : ( diff --git a/src/app/note/components/wrapper.tsx b/src/app/note/components/wrapper.tsx new file mode 100644 index 00000000..bdd0cb19 --- /dev/null +++ b/src/app/note/components/wrapper.tsx @@ -0,0 +1,26 @@ +import { navigate } from 'vite-plugin-ssr/client/router'; + +export const NoteWrapper = ({ + children, + href, + className, +}: { + children: React.ReactNode; + href: string; + className: string; +}) => { + const openThread = (event: any, href: string) => { + const selection = window.getSelection(); + if (selection.toString().length === 0) { + navigate(href, { keepScrollPosition: true }); + } else { + event.stopPropagation(); + } + }; + + return ( +
openThread(event, href)} className={className}> + {children} +
+ ); +}; diff --git a/src/app/note/pages/index.page.tsx b/src/app/note/pages/index.page.tsx index f68c003a..853d292b 100644 --- a/src/app/note/pages/index.page.tsx +++ b/src/app/note/pages/index.page.tsx @@ -1,6 +1,5 @@ +import { NoteContent } from '@lume/app/note/components/content'; import NoteMetadata from '@lume/app/note/components/metadata'; -import ImagePreview from '@lume/app/note/components/preview/image'; -import VideoPreview from '@lume/app/note/components/preview/video'; import RepliesList from '@lume/app/note/components/replies/list'; import { NoteDefaultUser } from '@lume/app/note/components/user/default'; import { RelayContext } from '@lume/shared/relayProvider'; @@ -67,31 +66,15 @@ export function Page() {
) : ( - <> -
-
- -
-
- {content ? content.parsed : ''} -
- {Array.isArray(content.images) && content.images.length ? ( - - ) : ( - <> - )} - {Array.isArray(content.videos) && content.videos.length ? ( - - ) : ( - <> - )} -
-
-
e.stopPropagation()} className="mt-5 border-t border-zinc-800 px-5 py-5"> +
+
+ +
+
- +
)}