From 5c2bfa0ea3584353cec5cc4a87e798189e1b23fe Mon Sep 17 00:00:00 2001 From: Ren Amamiya <123083837+reyamir@users.noreply.github.com> Date: Tue, 19 Sep 2023 11:15:35 +0700 Subject: [PATCH] improve notification --- src/app/notifications/index.tsx | 11 ++++++++--- src/app/nwc/components/alby.tsx | 2 +- src/app/nwc/components/other.tsx | 2 +- src/app/nwc/index.tsx | 29 +++++++++++++++++++++++++++- src/shared/accounts/active.tsx | 7 +++---- src/shared/navigation.tsx | 22 +++++++++++---------- src/shared/notes/kinds/repost.tsx | 8 ++++---- src/shared/notes/preview/video.tsx | 7 +++++++ src/shared/user.tsx | 31 ++++++++++++++++-------------- src/stores/activities.ts | 2 +- src/utils/hooks/useNostr.ts | 8 ++------ 11 files changed, 84 insertions(+), 45 deletions(-) diff --git a/src/app/notifications/index.tsx b/src/app/notifications/index.tsx index 155dfa91..47cdaea3 100644 --- a/src/app/notifications/index.tsx +++ b/src/app/notifications/index.tsx @@ -5,6 +5,8 @@ import { NotiMention } from '@app/notifications/components/mention'; import { NotiReaction } from '@app/notifications/components/reaction'; import { NotiRepost } from '@app/notifications/components/repost'; +import { useStorage } from '@libs/storage/provider'; + import { LoaderIcon } from '@shared/icons'; import { TitleBar } from '@shared/titleBar'; @@ -13,7 +15,9 @@ import { useActivities } from '@stores/activities'; import { useNostr } from '@utils/hooks/useNostr'; export function NotificationScreen() { + const { db } = useStorage(); const { fetchActivities } = useNostr(); + const [activities, setActivities, clearTotalNewActivities] = useActivities((state) => [ state.activities, state.setActivities, @@ -39,12 +43,13 @@ export function NotificationScreen() { useEffect(() => { async function getActivities() { const events = await fetchActivities(); - setActivities(events); - // clear total new activities - clearTotalNewActivities(); + setActivities(events, db.account.last_login_at); } getActivities(); + + // clear total new activities + clearTotalNewActivities(); }, []); return ( diff --git a/src/app/nwc/components/alby.tsx b/src/app/nwc/components/alby.tsx index a141cbf5..520ff8cb 100644 --- a/src/app/nwc/components/alby.tsx +++ b/src/app/nwc/components/alby.tsx @@ -71,7 +71,7 @@ export function NWCAlby() { diff --git a/src/app/nwc/components/other.tsx b/src/app/nwc/components/other.tsx index 49266b06..40340d79 100644 --- a/src/app/nwc/components/other.tsx +++ b/src/app/nwc/components/other.tsx @@ -89,7 +89,7 @@ export function NWCOther() { diff --git a/src/app/nwc/index.tsx b/src/app/nwc/index.tsx index cd16b9d6..4c00138d 100644 --- a/src/app/nwc/index.tsx +++ b/src/app/nwc/index.tsx @@ -71,7 +71,7 @@ export function NWCScreen() { the specs (NIP47) @@ -89,6 +89,33 @@ export function NWCScreen() {

Lume doesn't hold your Bitcoin

+
+
+ Recommend wallet that support NWC +
+

+ Mutiny Wallet:{' '} + + website + +

+

+ Self hosted NWC on Umbrel :{' '} + + website + +

+
diff --git a/src/shared/accounts/active.tsx b/src/shared/accounts/active.tsx index 2440506a..7a610c54 100644 --- a/src/shared/accounts/active.tsx +++ b/src/shared/accounts/active.tsx @@ -40,7 +40,7 @@ export function ActiveAccount() { case NDKKind.Text: return await sendNativeNotification('Mention'); case NDKKind.Contacts: - return await sendNativeNotification("You've new follower"); + return await sendNativeNotification("You've a new follower"); case NDKKind.Repost: return await sendNativeNotification('Repost'); case NDKKind.Reaction: @@ -48,7 +48,6 @@ export function ActiveAccount() { case NDKKind.Zap: return await sendNativeNotification('Zap'); default: - console.log('[notify] new event: ', event); break; } }); @@ -56,8 +55,8 @@ export function ActiveAccount() { if (status === 'loading') { return ( -
-
+
+
); diff --git a/src/shared/navigation.tsx b/src/shared/navigation.tsx index 91a17c8f..a20ca992 100644 --- a/src/shared/navigation.tsx +++ b/src/shared/navigation.tsx @@ -64,18 +64,20 @@ export function Navigation() { } >
- - - + {totalNewActivities > 0 ? ( +
+

+ {compactNumber.format(totalNewActivities)} +

+ +
+ ) : ( + + + + )} Notifications
- {totalNewActivities > 0 ? ( -
- - {compactNumber.format(totalNewActivities)} - -
- ) : null}
diff --git a/src/shared/notes/kinds/repost.tsx b/src/shared/notes/kinds/repost.tsx index b88036d2..63bf684d 100644 --- a/src/shared/notes/kinds/repost.tsx +++ b/src/shared/notes/kinds/repost.tsx @@ -55,8 +55,8 @@ export function Repost({ event }: { event: NDKEvent }) { if (embedEvent) { return (
-
- +
+
@@ -122,8 +122,8 @@ export function Repost({ event }: { event: NDKEvent }) { return (
-
- +
+
diff --git a/src/shared/notes/preview/video.tsx b/src/shared/notes/preview/video.tsx index a03cb621..c161fd74 100644 --- a/src/shared/notes/preview/video.tsx +++ b/src/shared/notes/preview/video.tsx @@ -12,6 +12,13 @@ export function VideoPreview({ urls }: { urls: string[] }) { className="!h-auto overflow-hidden rounded-lg object-fill" controls={true} pip={true} + light={ + {url} + } /> ))}
diff --git a/src/shared/user.tsx b/src/shared/user.tsx index 46587eb8..9e25f0f6 100644 --- a/src/shared/user.tsx +++ b/src/shared/user.tsx @@ -119,21 +119,24 @@ export const User = memo(function User({ if (variant === 'repost') { return ( -
- {pubkey} -
-
- {user?.display_name || user?.name || displayNpub(pubkey, 16)} -
- reposted - · - {createdAt} + <> +
+ {pubkey} +
+
+ {user?.display_name || user?.name || displayNpub(pubkey, 16)} +
+ reposted + · + {createdAt} +
-
+
+ ); } diff --git a/src/stores/activities.ts b/src/stores/activities.ts index bc09540e..906b89cc 100644 --- a/src/stores/activities.ts +++ b/src/stores/activities.ts @@ -22,7 +22,7 @@ export const useActivities = create((set) => ({ addActivity: (event: NDKEvent) => { set((state) => ({ activities: state.activities ? [event, ...state.activities] : [event], - totalNewActivities: state.totalNewActivities++, + totalNewActivities: (state.totalNewActivities += 1), })); }, clearTotalNewActivities: () => { diff --git a/src/utils/hooks/useNostr.ts b/src/utils/hooks/useNostr.ts index 627da89f..d0da3ee0 100644 --- a/src/utils/hooks/useNostr.ts +++ b/src/utils/hooks/useNostr.ts @@ -37,14 +37,10 @@ export function useNostr() { [] ); - const sub = async ( - filter: NDKFilter, - callback: (event: NDKEvent) => void, - closeOnEose?: boolean - ) => { + const sub = async (filter: NDKFilter, callback: (event: NDKEvent) => void) => { if (!ndk) throw new Error('NDK instance not found'); - const subEvent = ndk.subscribe(filter, { closeOnEose: closeOnEose ?? true }); + const subEvent = ndk.subscribe(filter, { closeOnEose: false }); subManager.set(JSON.stringify(filter), subEvent); subEvent.addListener('event', (event: NDKEvent) => {