From bac70b19ece0d5e53d257b747b5c216b18d292b1 Mon Sep 17 00:00:00 2001 From: Ren Amamiya <123083837+reyamir@users.noreply.github.com> Date: Sat, 19 Aug 2023 15:27:10 +0700 Subject: [PATCH] polish --- .github/workflows/main.yml | 7 +-- src/app.tsx | 7 --- src/app/auth/unlock.tsx | 18 +++--- src/app/error.tsx | 4 +- .../components/userProfile.tsx} | 7 ++- src/app/space/components/widgets/thread.tsx | 4 +- .../components/widgets}/trendingNotes.tsx | 19 ++++-- .../components/widgets/trendingProfile.tsx} | 24 +++++--- src/app/space/components/widgets/user.tsx | 15 +++-- src/app/space/index.tsx | 2 +- src/app/trending/index.tsx | 11 ---- src/libs/storage/instance.ts | 17 +++--- src/shared/composer/composer.tsx | 6 +- src/shared/image.tsx | 11 ++-- src/shared/navigation.tsx | 59 ++++--------------- src/shared/notes/replies/list.tsx | 14 +++-- src/shared/notification/modal.tsx | 7 ++- src/shared/user.tsx | 2 +- src/stores/widgets.tsx | 2 +- src/utils/hooks/useEvent.tsx | 23 +++++--- 20 files changed, 117 insertions(+), 142 deletions(-) rename src/app/{trending/components/profile.tsx => space/components/userProfile.tsx} (97%) rename src/app/{trending/components => space/components/widgets}/trendingNotes.tsx (69%) rename src/app/{trending/components/trendingProfiles.tsx => space/components/widgets/trendingProfile.tsx} (61%) delete mode 100644 src/app/trending/index.tsx diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 28115141..bd088712 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,8 +1,5 @@ name: 'publish' -on: - push: - branches: - - main +on: workflow_dispatch env: CARGO_INCREMENTAL: 0 @@ -27,7 +24,7 @@ jobs: - name: setup node uses: actions/setup-node@v3 with: - node-version: 18 + node-version: 20 - uses: dtolnay/rust-toolchain@stable with: targets: aarch64-apple-darwin diff --git a/src/app.tsx b/src/app.tsx index ba371246..cf9c760b 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -54,13 +54,6 @@ const router = createBrowserRouter([ return { Component: SpaceScreen }; }, }, - { - path: 'trending', - async lazy() { - const { TrendingScreen } = await import('@app/trending'); - return { Component: TrendingScreen }; - }, - }, { path: 'events/:id', async lazy() { diff --git a/src/app/auth/unlock.tsx b/src/app/auth/unlock.tsx index 6d0f1926..9338c1ea 100644 --- a/src/app/auth/unlock.tsx +++ b/src/app/auth/unlock.tsx @@ -74,17 +74,17 @@ export function UnlockScreen() {

Enter password to unlock

-
- -
-
-
+ +
+
+ +
- - {errors.password &&

{errors.password.message}

} -
+ + {errors.password &&

{errors.password.message}

} +
@@ -76,54 +79,12 @@ export function Navigation() { - Spaces - - - twMerge( - 'flex h-9 items-center gap-2.5 rounded-md px-2 ', - isActive ? 'bg-white/10 text-white' : 'text-white/80' - ) - } - > - - - - Trending + Space
- {/* Channels - - {({ open }) => ( -
- -
- -
-

- Channels -

-
- - - -
- )} -
- */}
diff --git a/src/shared/notes/replies/list.tsx b/src/shared/notes/replies/list.tsx index e501218e..681af5fe 100644 --- a/src/shared/notes/replies/list.tsx +++ b/src/shared/notes/replies/list.tsx @@ -1,10 +1,13 @@ +import { NDKEvent } from '@nostr-dev-kit/ndk'; import { useQuery } from '@tanstack/react-query'; import { useNDK } from '@libs/ndk/provider'; import { NoteSkeleton, Reply } from '@shared/notes'; -import { LumeEvent } from '@utils/types'; +interface ReplyEvent extends NDKEvent { + replies: Array; +} export function RepliesList({ id }: { id: string }) { const { ndk } = useNDK(); @@ -12,10 +15,9 @@ export function RepliesList({ id }: { id: string }) { const events = await ndk.fetchEvents({ kinds: [1], '#e': [id], - since: 0, }); - const array = [...events] as unknown as LumeEvent[]; + const array = [...events] as unknown as ReplyEvent[]; if (array.length > 0) { const replies = new Set(); @@ -55,7 +57,7 @@ export function RepliesList({ id }: { id: string }) { } return ( -
+
{data?.length || 0} replies
@@ -71,8 +73,8 @@ export function RepliesList({ id }: { id: string }) {
) : ( data - ?.reverse() - .map((event: LumeEvent) => ) + .reverse() + .map((event: NDKEvent) => ) )}
diff --git a/src/shared/notification/modal.tsx b/src/shared/notification/modal.tsx index ab4cc45f..438924c3 100644 --- a/src/shared/notification/modal.tsx +++ b/src/shared/notification/modal.tsx @@ -9,7 +9,6 @@ import { BellIcon, CancelIcon, LoaderIcon } from '@shared/icons'; import { NotiMention, NotiReaction, NotiRepost } from '@shared/notification'; import { nHoursAgo } from '@utils/date'; -import { LumeEvent } from '@utils/types'; export function NotificationModal({ pubkey }: { pubkey: string }) { const { ndk } = useNDK(); @@ -23,10 +22,12 @@ export function NotificationModal({ pubkey }: { pubkey: string }) { }); const filterSelf = [...events].filter((el) => el.pubkey !== pubkey); const sorted = filterSelf.sort((a, b) => a.created_at - b.created_at); - return sorted as unknown as LumeEvent[]; + return sorted as unknown as NDKEvent[]; }, { refetchOnWindowFocus: false, + refetchOnMount: false, + refetchOnReconnect: false, } ); @@ -80,7 +81,7 @@ export function NotificationModal({ pubkey }: { pubkey: string }) {
- ) : data.length < 1 ? ( + ) : data?.length < 1 ? (

🎉

diff --git a/src/shared/user.tsx b/src/shared/user.tsx index a498c7fd..b2821d16 100644 --- a/src/shared/user.tsx +++ b/src/shared/user.tsx @@ -90,7 +90,7 @@ export function User({

diff --git a/src/stores/widgets.tsx b/src/stores/widgets.tsx index 5ee2bad9..b4fd37b6 100644 --- a/src/stores/widgets.tsx +++ b/src/stores/widgets.tsx @@ -22,7 +22,7 @@ export const useWidgets = create()( // default: add network widget dbWidgets.unshift({ - id: String(dbWidgets.length + 1), + id: '9999', title: 'Network', content: '', kind: 9999, diff --git a/src/utils/hooks/useEvent.tsx b/src/utils/hooks/useEvent.tsx index a29402b9..fbfef0c7 100644 --- a/src/utils/hooks/useEvent.tsx +++ b/src/utils/hooks/useEvent.tsx @@ -2,29 +2,38 @@ import { NDKEvent } from '@nostr-dev-kit/ndk'; import { useQuery } from '@tanstack/react-query'; import { useNDK } from '@libs/ndk/provider'; +import { useStorage } from '@libs/storage/provider'; import { parser } from '@utils/parser'; import { RichContent } from '@utils/types'; export function useEvent(id: string, embed?: string) { + const { db } = useStorage(); const { ndk } = useNDK(); const { status, data, error } = useQuery( ['event', id], async () => { + let richContent: RichContent; + // return embed event (nostr.band api) if (embed) { const event: NDKEvent = JSON.parse(embed); - let richContent: RichContent; if (event.kind === 1) richContent = parser(event); - return { event: event as NDKEvent, richContent: richContent }; + return { event: event, richContent: richContent }; } - const event = (await ndk.fetchEvent(id)) as NDKEvent; - if (!event) throw new Error('event not found'); - let richContent: RichContent; - if (event.kind === 1) richContent = parser(event); + // get event from db + const dbEvent = await db.getEventByID(id); + if (dbEvent) { + if (dbEvent.kind === 1) richContent = parser(dbEvent); + return { event: dbEvent, richContent: richContent }; + } else { + // get event from relay if event in db not present + const event = await ndk.fetchEvent(id); + if (event.kind === 1) richContent = parser(event); - return { event: event as NDKEvent, richContent: richContent }; + return { event: event, richContent: richContent }; + } }, { staleTime: Infinity,