From 53aa13c8aa090159daf03a98aca2372054d09c2d Mon Sep 17 00:00:00 2001 From: Ren Amamiya <123083837+reyamir@users.noreply.github.com> Date: Mon, 18 Sep 2023 09:50:15 +0700 Subject: [PATCH] clean up messy code --- src/app/auth/complete.tsx | 3 +- src/app/auth/components/user.tsx | 54 ----- src/app/auth/components/userImport.tsx | 38 ---- src/app/auth/components/userRelay.tsx | 36 ---- src/app/auth/import/step-3.tsx | 5 +- src/app/auth/onboarding/step-1.tsx | 9 +- src/app/auth/onboarding/step-3.tsx | 5 +- src/app/auth/reset.tsx | 14 +- src/app/auth/unlock.tsx | 5 +- src/app/chats/components/messages/item.tsx | 2 +- src/app/chats/components/modal.tsx | 11 +- src/app/chats/components/unknowns.tsx | 5 +- src/app/notes/article.tsx | 32 +-- src/app/notes/text.tsx | 4 +- .../notifications/components/simpleNote.tsx | 2 +- src/app/nwc/index.tsx | 18 +- src/index.css | 2 +- src/shared/nip05.tsx | 5 +- src/shared/notes/actions/more.tsx | 2 +- src/shared/notes/index.ts | 3 - src/shared/notes/kinds/repost.tsx | 79 ++++--- src/shared/notes/mentions/note.tsx | 2 +- src/shared/notes/metadata.tsx | 4 +- src/shared/notes/replies/list.tsx | 4 +- src/shared/notes/users/mini.tsx | 19 -- src/shared/notes/users/repost.tsx | 28 --- src/shared/notes/users/thread.tsx | 34 ---- src/shared/user.tsx | 192 +++++++++++++----- src/shared/widgets/local/thread.tsx | 4 +- src/shared/widgets/tmp/feeds.tsx | 5 +- src/utils/hooks/useEvent.ts | 3 +- 31 files changed, 256 insertions(+), 373 deletions(-) delete mode 100644 src/app/auth/components/user.tsx delete mode 100644 src/app/auth/components/userImport.tsx delete mode 100644 src/app/auth/components/userRelay.tsx delete mode 100644 src/shared/notes/users/mini.tsx delete mode 100644 src/shared/notes/users/repost.tsx delete mode 100644 src/shared/notes/users/thread.tsx diff --git a/src/app/auth/complete.tsx b/src/app/auth/complete.tsx index 5a3a3291..740697df 100644 --- a/src/app/auth/complete.tsx +++ b/src/app/auth/complete.tsx @@ -3,7 +3,7 @@ import { useNavigate } from 'react-router-dom'; export function CompleteScreen() { const navigate = useNavigate(); - const [count, setCount] = useState(3); + const [count, setCount] = useState(5); useEffect(() => { let counter: NodeJS.Timeout; @@ -26,7 +26,6 @@ export function CompleteScreen() {

You're ready, redirecting in {count} - ...

Thank you for using Lume. Lume doesn't use telemetry. If you encounter any diff --git a/src/app/auth/components/user.tsx b/src/app/auth/components/user.tsx deleted file mode 100644 index bfded070..00000000 --- a/src/app/auth/components/user.tsx +++ /dev/null @@ -1,54 +0,0 @@ -import { Link } from 'react-router-dom'; - -import { WorldIcon } from '@shared/icons'; -import { Image } from '@shared/image'; - -import { useProfile } from '@utils/hooks/useProfile'; - -export function User({ pubkey, fallback }: { pubkey: string; fallback?: string }) { - const { status, user } = useProfile(pubkey, fallback); - - if (status === 'loading') { - return ( -

-
-
- - -
-
- ); - } - - return ( -
- {pubkey} -
-
-

- {user?.name || user?.display_name} -

-

- {user?.about || user?.bio || 'No bio'} -

-
-
- {user?.website ? ( - - -

{user.website}

- - ) : null} -
-
-
- ); -} diff --git a/src/app/auth/components/userImport.tsx b/src/app/auth/components/userImport.tsx deleted file mode 100644 index 8801f8fe..00000000 --- a/src/app/auth/components/userImport.tsx +++ /dev/null @@ -1,38 +0,0 @@ -import { Image } from '@shared/image'; - -import { useProfile } from '@utils/hooks/useProfile'; -import { displayNpub } from '@utils/shortenKey'; - -export function UserImport({ pubkey }: { pubkey: string }) { - const { status, user } = useProfile(pubkey); - - if (status === 'loading') { - return ( -
-
-
- - -
-
- ); - } - - return ( -
- {pubkey} -
-

- {user?.name || user?.display_name} -

-

- {user?.nip05 || user?.username || displayNpub(pubkey, 16)} -

-
-
- ); -} diff --git a/src/app/auth/components/userRelay.tsx b/src/app/auth/components/userRelay.tsx deleted file mode 100644 index 83bc4b15..00000000 --- a/src/app/auth/components/userRelay.tsx +++ /dev/null @@ -1,36 +0,0 @@ -import { Image } from '@shared/image'; - -import { useProfile } from '@utils/hooks/useProfile'; -import { displayNpub } from '@utils/shortenKey'; - -export function UserRelay({ pubkey }: { pubkey: string }) { - const { status, user } = useProfile(pubkey); - - if (status === 'loading') { - return ( -
-
-
- - -
-
- ); - } - - return ( -
- Use by -
- {pubkey} - - {user?.name || user?.display_name || displayNpub(pubkey, 16)} - -
-
- ); -} diff --git a/src/app/auth/import/step-3.tsx b/src/app/auth/import/step-3.tsx index 4a2b0b81..96c9a26d 100644 --- a/src/app/auth/import/step-3.tsx +++ b/src/app/auth/import/step-3.tsx @@ -1,11 +1,10 @@ import { useEffect, useState } from 'react'; import { useNavigate } from 'react-router-dom'; -import { UserImport } from '@app/auth/components/userImport'; - import { useStorage } from '@libs/storage/provider'; import { ArrowRightCircleIcon, LoaderIcon } from '@shared/icons'; +import { User } from '@shared/user'; import { useOnboarding } from '@stores/onboarding'; import { WidgetKinds } from '@stores/widgets'; @@ -60,7 +59,7 @@ export function ImportStep3Screen() {
- +
) : ( -
-
- -
{renderKind(data)}
-
- - + <> +
+
+ +
{renderKind(data)}
+
+ + +
-
+
+ + +
+ )} -
- - -
diff --git a/src/app/notes/text.tsx b/src/app/notes/text.tsx index 897c1696..c3a36f46 100644 --- a/src/app/notes/text.tsx +++ b/src/app/notes/text.tsx @@ -15,11 +15,11 @@ import { NoteReplyForm, NoteStats, TextNote, - ThreadUser, UnknownNote, } from '@shared/notes'; import { RepliesList } from '@shared/notes/replies/list'; import { NoteSkeleton } from '@shared/notes/skeleton'; +import { User } from '@shared/user'; import { useEvent } from '@utils/hooks/useEvent'; @@ -106,7 +106,7 @@ export function TextNoteScreen() { ) : (
- +
{renderKind(data)}
diff --git a/src/app/notifications/components/simpleNote.tsx b/src/app/notifications/components/simpleNote.tsx index badb01d4..963ef47d 100644 --- a/src/app/notifications/components/simpleNote.tsx +++ b/src/app/notifications/components/simpleNote.tsx @@ -48,7 +48,7 @@ export const SimpleNote = memo(function SimpleNote({ id }: { id: string }) { tabIndex={0} className="mb-2 mt-3 cursor-default rounded-lg bg-white/10 px-3 py-3 backdrop-blur-xl" > - +

{data.content.length > 200 diff --git a/src/app/nwc/index.tsx b/src/app/nwc/index.tsx index 44924c48..cd16b9d6 100644 --- a/src/app/nwc/index.tsx +++ b/src/app/nwc/index.tsx @@ -27,13 +27,13 @@ export function NWCScreen() {

Nostr Wallet Connect (Beta)

-

+

Sending tips easily via Bitcoin Lightning.

{!walletConnectURL ? ( -
+
@@ -61,12 +61,12 @@ export function NWCScreen() { )}
-
Introduction
-

+

Introduction
+

Nostr Wallet Connect (NWC) is a way for applications like Nostr clients to access a remote Lightning wallet through a standardized protocol.

-

+

To learn more about the details have a look at{' '}

-
About tipping
-

+

About tipping
+

Also known as Zap in other Nostr client.

-

+

Lume doesn't take any commission or platform fees when you tip someone.

-

Lume doesn't hold your Bitcoin

+

Lume doesn't hold your Bitcoin

diff --git a/src/index.css b/src/index.css index 0b0f480c..dc3515a7 100644 --- a/src/index.css +++ b/src/index.css @@ -12,7 +12,7 @@ } .markdown { - @apply prose prose-white max-w-none select-text hyphens-auto text-white prose-p:mb-0 prose-p:mt-0 prose-p:break-words prose-p:[word-break:break-word] prose-p:last:mb-0 prose-a:break-words prose-a:break-all prose-a:font-normal hover:prose-a:text-fuchsia-500 prose-blockquote:mb-1 prose-blockquote:mt-1 prose-blockquote:border-l-[2px] prose-blockquote:border-fuchsia-500 prose-blockquote:pl-2 prose-pre:whitespace-pre-wrap prose-pre:break-words prose-pre:break-all prose-ol:m-0 prose-ol:mb-1 prose-ul:mb-1 prose-ul:mt-1 prose-img:mb-2 prose-img:mt-3 prose-hr:mx-0 prose-hr:my-2; + @apply prose prose-white max-w-none select-text hyphens-auto text-white prose-p:mb-0 prose-p:mt-0 prose-p:break-words prose-p:[word-break:break-word] prose-p:last:mb-0 prose-a:break-words prose-a:break-all prose-a:font-normal hover:prose-a:text-fuchsia-500 prose-blockquote:mb-1 prose-blockquote:mt-1 prose-blockquote:border-l-[2px] prose-blockquote:border-fuchsia-500 prose-blockquote:pl-2 prose-pre:whitespace-pre-wrap prose-pre:break-words prose-pre:break-all prose-pre:bg-white/10 prose-ol:m-0 prose-ol:mb-1 prose-ul:mb-1 prose-ul:mt-1 prose-img:mb-2 prose-img:mt-3 prose-hr:mx-0 prose-hr:my-2; } .ProseMirror p.is-empty::before { diff --git a/src/shared/nip05.tsx b/src/shared/nip05.tsx index 60c41efc..a26c0c68 100644 --- a/src/shared/nip05.tsx +++ b/src/shared/nip05.tsx @@ -1,5 +1,6 @@ import { useQuery } from '@tanstack/react-query'; import { fetch } from '@tauri-apps/api/http'; +import { memo } from 'react'; import { twMerge } from 'tailwind-merge'; import { UnverifiedIcon, VerifiedIcon } from '@shared/icons'; @@ -10,7 +11,7 @@ interface NIP05 { }; } -export function NIP05({ +export const NIP05 = memo(function NIP05({ pubkey, nip05, className, @@ -71,4 +72,4 @@ export function NIP05({
); -} +}); diff --git a/src/shared/notes/actions/more.tsx b/src/shared/notes/actions/more.tsx index e17d8f93..2f2f05e3 100644 --- a/src/shared/notes/actions/more.tsx +++ b/src/shared/notes/actions/more.tsx @@ -44,7 +44,7 @@ export function MoreActions({ id, pubkey }: { id: string; pubkey: string }) { - + +
+
+ {user?.display_name || user?.name || displayNpub(pubkey, 16)} +
+ · + {createdAt} +
+
+ ); + } + + if (variant === 'large') { + return ( +
+ {pubkey} +
+
+

+ {user?.name || user?.display_name} +

+

+ {user?.about || user?.bio || 'No bio'} +

+
+
+ {user?.website ? ( + + +

{user.website}

+ + ) : null} +
+
+
+ ); + } + + if (variant === 'simple') { + return ( +
+ {pubkey} +
+

+ {user?.name || user?.display_name} +

+

+ {user?.nip05 || user?.username || displayNpub(pubkey, 16)} +

+
+
+ ); + } + + if (variant === 'repost') { + return ( +
+ {pubkey} +
+
+ {user?.display_name || user?.name || displayNpub(pubkey, 16)} +
+ reposted + · + {createdAt} +
+
+ ); + } + + if (variant === 'thread') { + return ( +
+ {pubkey} +
+
+ {user?.display_name || user?.name} +
+
+ {createdAt} + · + {displayNpub(pubkey, 16)} +
+
); } return ( -
+
-
-
+
+
{user?.display_name || user?.name || displayNpub(pubkey, 16)}
· @@ -139,4 +235,4 @@ export function User({ ); -} +}); diff --git a/src/shared/widgets/local/thread.tsx b/src/shared/widgets/local/thread.tsx index 6087e129..1d754610 100644 --- a/src/shared/widgets/local/thread.tsx +++ b/src/shared/widgets/local/thread.tsx @@ -10,12 +10,12 @@ import { NoteReplyForm, NoteStats, TextNote, - ThreadUser, UnknownNote, } from '@shared/notes'; import { RepliesList } from '@shared/notes/replies/list'; import { NoteSkeleton } from '@shared/notes/skeleton'; import { TitleBar } from '@shared/titleBar'; +import { User } from '@shared/user'; import { useEvent } from '@utils/hooks/useEvent'; import { Widget } from '@utils/types'; @@ -53,7 +53,7 @@ export function LocalThreadWidget({ params }: { params: Widget }) { ) : (
- +
{renderKind(data)}
toggleGroup(item)} className="inline-flex transform items-center justify-between px-4 py-2 hover:bg-white/20" > - + {groups.includes(item) && (
diff --git a/src/utils/hooks/useEvent.ts b/src/utils/hooks/useEvent.ts index d88102dd..77b706e2 100644 --- a/src/utils/hooks/useEvent.ts +++ b/src/utils/hooks/useEvent.ts @@ -25,6 +25,7 @@ export function useEvent( authors: [naddr.pubkey], }); const rEvent = [...rEvents].slice(-1)[0]; + if (!rEvent) return Promise.reject(new Error('event not found')); return rEvent; } @@ -40,7 +41,7 @@ export function useEvent( // get event from relay if event in db not present const event = await ndk.fetchEvent(id); - if (!event) throw new Error(`Event not found: ${id}`); + if (!event) return Promise.reject(new Error('event not found')); const rawEvent = toRawEvent(event); await db.createEvent(rawEvent);