diff --git a/src/app.tsx b/src/app.tsx index d6049276..0285b39d 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -70,10 +70,10 @@ const router = createBrowserRouter([ }, }, { - path: 'lodge', + path: 'notifications', async lazy() { - const { LodgeScreen } = await import('@app/lodge'); - return { Component: LodgeScreen }; + const { NotificationScreen } = await import('@app/notifications'); + return { Component: NotificationScreen }; }, }, ], diff --git a/src/app/lodge/components/base/list.tsx b/src/app/lodge/components/base/list.tsx deleted file mode 100644 index 04d7b94e..00000000 --- a/src/app/lodge/components/base/list.tsx +++ /dev/null @@ -1,3 +0,0 @@ -export function BaseList() { - return
; -} diff --git a/src/app/lodge/components/content.tsx b/src/app/notifications/components/content.tsx similarity index 100% rename from src/app/lodge/components/content.tsx rename to src/app/notifications/components/content.tsx diff --git a/src/app/lodge/components/mention.tsx b/src/app/notifications/components/mention.tsx similarity index 89% rename from src/app/lodge/components/mention.tsx rename to src/app/notifications/components/mention.tsx index 672acbf9..c527a760 100644 --- a/src/app/lodge/components/mention.tsx +++ b/src/app/notifications/components/mention.tsx @@ -1,8 +1,8 @@ import { NDKEvent } from '@nostr-dev-kit/ndk'; import { useMemo } from 'react'; -import { NotiContent } from '@app/lodge/components/content'; -import { NotiUser } from '@app/lodge/components/user'; +import { NotiContent } from '@app/notifications/components/content'; +import { NotiUser } from '@app/notifications/components/user'; import { formatCreatedAt } from '@utils/createdAt'; import { parser } from '@utils/parser'; diff --git a/src/app/lodge/components/reaction.tsx b/src/app/notifications/components/reaction.tsx similarity index 87% rename from src/app/lodge/components/reaction.tsx rename to src/app/notifications/components/reaction.tsx index 04e80391..7c0e1749 100644 --- a/src/app/lodge/components/reaction.tsx +++ b/src/app/notifications/components/reaction.tsx @@ -1,7 +1,7 @@ import { NDKEvent } from '@nostr-dev-kit/ndk'; -import { SimpleNote } from '@app/lodge/components/simpleNote'; -import { NotiUser } from '@app/lodge/components/user'; +import { SimpleNote } from '@app/notifications/components/simpleNote'; +import { NotiUser } from '@app/notifications/components/user'; import { formatCreatedAt } from '@utils/createdAt'; diff --git a/src/app/lodge/components/repost.tsx b/src/app/notifications/components/repost.tsx similarity index 89% rename from src/app/lodge/components/repost.tsx rename to src/app/notifications/components/repost.tsx index 21e6f807..d0e1a77b 100644 --- a/src/app/lodge/components/repost.tsx +++ b/src/app/notifications/components/repost.tsx @@ -1,7 +1,7 @@ import { NDKEvent } from '@nostr-dev-kit/ndk'; -import { SimpleNote } from '@app/lodge/components/simpleNote'; -import { NotiUser } from '@app/lodge/components/user'; +import { SimpleNote } from '@app/notifications/components/simpleNote'; +import { NotiUser } from '@app/notifications/components/user'; import { useStorage } from '@libs/storage/provider'; diff --git a/src/app/lodge/components/simpleNote.tsx b/src/app/notifications/components/simpleNote.tsx similarity index 100% rename from src/app/lodge/components/simpleNote.tsx rename to src/app/notifications/components/simpleNote.tsx diff --git a/src/app/lodge/components/user.tsx b/src/app/notifications/components/user.tsx similarity index 100% rename from src/app/lodge/components/user.tsx rename to src/app/notifications/components/user.tsx diff --git a/src/app/lodge/index.tsx b/src/app/notifications/index.tsx similarity index 72% rename from src/app/lodge/index.tsx rename to src/app/notifications/index.tsx index 1f965f47..3402eb3e 100644 --- a/src/app/lodge/index.tsx +++ b/src/app/notifications/index.tsx @@ -1,10 +1,10 @@ -import { NDKEvent, NDKFilter } from '@nostr-dev-kit/ndk'; +import { NDKEvent } from '@nostr-dev-kit/ndk'; import { useQuery } from '@tanstack/react-query'; -import { useCallback, useEffect } from 'react'; +import { useCallback } from 'react'; -import { NotiMention } from '@app/lodge/components/mention'; -import { NotiReaction } from '@app/lodge/components/reaction'; -import { NotiRepost } from '@app/lodge/components/repost'; +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'; @@ -13,11 +13,11 @@ import { TitleBar } from '@shared/titleBar'; import { useNostr } from '@utils/hooks/useNostr'; -export function LodgeScreen() { +export function NotificationScreen() { const { db } = useStorage(); - const { sub, fetchActivities } = useNostr(); + const { fetchActivities } = useNostr(); const { status, data } = useQuery( - ['lodge', db.account.pubkey], + ['notifications', db.account.pubkey], async () => { return await fetchActivities(); }, @@ -40,22 +40,10 @@ export function LodgeScreen() { [data] ); - useEffect(() => { - const filter: NDKFilter = { - '#p': [db.account.pubkey], - kinds: [1, 3, 6, 7, 9735], - since: db.account.last_login_at ?? Math.floor(Date.now() / 1000), - }; - - sub(filter, async (event) => { - console.log('[notify] new noti', event.id); - }); - }, []); - return (
-
+
diff --git a/src/shared/accounts/active.tsx b/src/shared/accounts/active.tsx index 53f12f91..331c450d 100644 --- a/src/shared/accounts/active.tsx +++ b/src/shared/accounts/active.tsx @@ -1,13 +1,53 @@ +import { NDKFilter, NDKKind } from '@nostr-dev-kit/ndk'; +import { useEffect } from 'react'; import { Link } from 'react-router-dom'; +import { useStorage } from '@libs/storage/provider'; + import { Image } from '@shared/image'; import { NetworkStatusIndicator } from '@shared/networkStatusIndicator'; +import { useNostr } from '@utils/hooks/useNostr'; import { useProfile } from '@utils/hooks/useProfile'; +import { sendNativeNotification } from '@utils/notification'; export function ActiveAccount({ data }: { data: { pubkey: string; npub: string } }) { + const { sub } = useNostr(); + const { db } = useStorage(); const { status, user } = useProfile(data.pubkey); + useEffect(() => { + const filter: NDKFilter = { + '#p': [db.account.pubkey], + kinds: [ + NDKKind.Text, + NDKKind.Contacts, + NDKKind.Repost, + NDKKind.Reaction, + NDKKind.Zap, + ], + since: Math.floor(Date.now() / 1000), + }; + + sub(filter, async (event) => { + switch (event.kind) { + case NDKKind.Text: + return await sendNativeNotification('Mention'); + case NDKKind.Contacts: + return await sendNativeNotification("You've new follower"); + case NDKKind.Repost: + return await sendNativeNotification('Repost'); + case NDKKind.Reaction: + return await sendNativeNotification('Reaction'); + case NDKKind.Zap: + return await sendNativeNotification('Zap'); + default: + console.log('[notify] new event: ', event); + break; + } + }); + }, []); + if (status === 'loading') { return
; } diff --git a/src/shared/navigation.tsx b/src/shared/navigation.tsx index 1c708115..be144e58 100644 --- a/src/shared/navigation.tsx +++ b/src/shared/navigation.tsx @@ -85,7 +85,7 @@ export function Navigation() { Space twMerge( @@ -97,7 +97,7 @@ export function Navigation() { - Lodge + Notifications
diff --git a/src/utils/notification.ts b/src/utils/notification.ts index d1df4d5e..795783f4 100644 --- a/src/utils/notification.ts +++ b/src/utils/notification.ts @@ -4,13 +4,13 @@ import { sendNotification, } from '@tauri-apps/plugin-notification'; -export async function sendNativeNotification(content: string) { +export async function sendNativeNotification(content: string, title?: string) { let permissionGranted = await isPermissionGranted(); if (!permissionGranted) { const permission = await requestPermission(); permissionGranted = permission === 'granted'; } if (permissionGranted) { - sendNotification({ title: 'Lume', body: content }); + sendNotification({ title: title || 'Lume', body: content }); } }