polish widget code

This commit is contained in:
Ren Amamiya 2023-09-29 09:11:38 +07:00
parent cb3c95b133
commit 2f87ed8949
22 changed files with 293 additions and 260 deletions

View File

@ -2,7 +2,7 @@ import { NDKEvent, NDKKind } from '@nostr-dev-kit/ndk';
import { useQuery } from '@tanstack/react-query'; import { useQuery } from '@tanstack/react-query';
import { useCallback } from 'react'; import { useCallback } from 'react';
import { useParams } from 'react-router-dom'; import { useParams } from 'react-router-dom';
import { VList } from 'virtua'; import { WVList } from 'virtua';
import { UserProfile } from '@app/users/components/profile'; import { UserProfile } from '@app/users/components/profile';
@ -93,10 +93,10 @@ export function UserScreen() {
</div> </div>
</div> </div>
) : ( ) : (
<VList className="scrollbar-hide h-full"> <WVList>
{data.map((item) => renderItem(item))} {data.map((item) => renderItem(item))}
<div className="h-16" /> <div className="h-16" />
</VList> </WVList>
)} )}
</div> </div>
</div> </div>

View File

@ -2,6 +2,35 @@
@tailwind components; @tailwind components;
@tailwind utilities; @tailwind utilities;
html {
font-size: 14px;
}
a {
@apply cursor-default no-underline !important;
}
button {
@apply cursor-default focus:outline-none;
}
iframe {
height: auto !important;
}
span[data-slate-placeholder] {
margin-top: 0;
}
input::-ms-reveal,
input::-ms-clear {
display: none;
}
::-webkit-input-placeholder {
line-height: normal;
}
.border { .border {
background-clip: padding-box; background-clip: padding-box;
} }
@ -38,32 +67,3 @@
.ProseMirror img.ProseMirror-selectednode { .ProseMirror img.ProseMirror-selectednode {
@apply outline-fuchsia-500; @apply outline-fuchsia-500;
} }
html {
font-size: 14px;
}
a {
@apply cursor-default no-underline !important;
}
button {
@apply cursor-default focus:outline-none;
}
iframe {
height: auto !important;
}
span[data-slate-placeholder] {
margin-top: 0;
}
input::-ms-reveal,
input::-ms-clear {
display: none;
}
::-webkit-input-placeholder {
line-height: normal;
}

View File

@ -32,9 +32,7 @@ export function ActiveAccount() {
sub( sub(
filter, filter,
async (event) => { async (event) => {
console.log('new notify: ', event);
addActivity(event); addActivity(event);
switch (event.kind) { switch (event.kind) {
case NDKKind.Text: case NDKKind.Text:
return await sendNativeNotification('Mention'); return await sendNativeNotification('Mention');

View File

@ -14,7 +14,7 @@ export function ArticleNote(props: { event?: NDKEvent }) {
(tag) => tag[0] === 'published_at' (tag) => tag[0] === 'published_at'
)?.[1]; )?.[1];
if (publishedAt) { if (publishedAt) {
publishedAt = new Date(parseInt(publishedAt)).toLocaleDateString('en-US'); publishedAt = new Date(parseInt(publishedAt) * 1000).toLocaleDateString('en-US');
} else { } else {
publishedAt = new Date(props.event.created_at * 1000).toLocaleDateString('en-US'); publishedAt = new Date(props.event.created_at * 1000).toLocaleDateString('en-US');
} }
@ -29,7 +29,7 @@ export function ArticleNote(props: { event?: NDKEvent }) {
return ( return (
<Link to={`/notes/article/${props.event.id}`} preventScrollReset={true}> <Link to={`/notes/article/${props.event.id}`} preventScrollReset={true}>
<div className="mb-2 mt-3 flex flex-col rounded-lg"> <div className="mb-2 mt-2 flex flex-col rounded-lg">
{metadata.image && ( {metadata.image && (
<Image <Image
src={metadata.image} src={metadata.image}

View File

@ -17,6 +17,9 @@ export function VideoPreview({ urls }: { urls: string[] }) {
src={`https://thumbnail.video/api/get?url=${url}&seconds=1`} src={`https://thumbnail.video/api/get?url=${url}&seconds=1`}
alt={url} alt={url}
className="aspect-video h-full w-full bg-white object-cover" className="aspect-video h-full w-full bg-white object-cover"
loading="lazy"
decoding="async"
style={{ contentVisibility: 'auto' }}
/> />
} }
/> />

View File

@ -56,7 +56,7 @@ export const User = memo(function User({
return ( return (
<div className="flex items-start gap-3"> <div className="flex items-start gap-3">
<div className="h-10 w-10 shrink-0 animate-pulse overflow-hidden rounded-lg bg-white/10 backdrop-blur-xl" /> <div className="h-10 w-10 shrink-0 animate-pulse rounded-lg bg-white/10 backdrop-blur-xl" />
<div className="h-3.5 w-36 animate-pulse rounded bg-white/10 backdrop-blur-xl" /> <div className="h-3.5 w-36 animate-pulse rounded bg-white/10 backdrop-blur-xl" />
</div> </div>
); );
@ -150,10 +150,10 @@ export const User = memo(function User({
loading="lazy" loading="lazy"
decoding="async" decoding="async"
style={{ contentVisibility: 'auto' }} style={{ contentVisibility: 'auto' }}
className="h-12 w-12 rounded-lg" className="h-10 w-10 rounded-lg"
/> />
<Avatar.Fallback delayMs={300}> <Avatar.Fallback delayMs={300}>
<img src={svgURI} alt={pubkey} className="h-12 w-12 rounded-lg bg-black" /> <img src={svgURI} alt={pubkey} className="h-10 w-10 rounded-lg bg-black" />
</Avatar.Fallback> </Avatar.Fallback>
</Avatar.Root> </Avatar.Root>
<div className="flex w-full flex-col items-start gap-1"> <div className="flex w-full flex-col items-start gap-1">

View File

@ -5,7 +5,6 @@ import { UserStats } from '@app/users/components/stats';
import { useStorage } from '@libs/storage/provider'; import { useStorage } from '@libs/storage/provider';
import { Image } from '@shared/image';
import { NIP05 } from '@shared/nip05'; import { NIP05 } from '@shared/nip05';
import { useNostr } from '@utils/hooks/useNostr'; import { useNostr } from '@utils/hooks/useNostr';
@ -49,15 +48,45 @@ export function UserProfile({ pubkey }: { pubkey: string }) {
return ( return (
<div> <div>
<Image <div className="flex items-center justify-between">
src={user?.picture || user?.image} <img
alt={pubkey} src={user?.picture || user?.image}
className="h-14 w-14 rounded-md" alt={pubkey}
/> className="h-12 w-12 shrink-0 rounded-lg"
loading="lazy"
decoding="async"
style={{ contentVisibility: 'auto' }}
/>
<div className="inline-flex items-center gap-2">
{followed ? (
<button
type="button"
onClick={() => unfollowUser(pubkey)}
className="inline-flex h-9 w-28 items-center justify-center rounded-md bg-white/10 text-sm font-medium backdrop-blur-xl hover:bg-fuchsia-500"
>
Unfollow
</button>
) : (
<button
type="button"
onClick={() => followUser(pubkey)}
className="inline-flex h-9 w-28 items-center justify-center rounded-md bg-white/10 text-sm font-medium backdrop-blur-xl hover:bg-fuchsia-500"
>
Follow
</button>
)}
<Link
to={`/chats/${pubkey}`}
className="inline-flex h-9 w-28 items-center justify-center rounded-md bg-white/10 text-sm font-medium backdrop-blur-xl hover:bg-fuchsia-500"
>
Message
</Link>
</div>
</div>
<div className="mt-2 flex flex-1 flex-col gap-2"> <div className="mt-2 flex flex-1 flex-col gap-2">
<div className="flex flex-col gap-2"> <div className="flex flex-col gap-2">
<h5 className="text-lg font-semibold leading-none"> <h5 className="text-lg font-semibold leading-none">
{user?.displayName || user?.name || 'No name'} {user?.name || user?.display_name || user?.displayName || 'Anon'}
</h5> </h5>
{user?.nip05 ? ( {user?.nip05 ? (
<NIP05 <NIP05
@ -72,36 +101,11 @@ export function UserProfile({ pubkey }: { pubkey: string }) {
)} )}
</div> </div>
<div className="flex flex-col gap-4"> <div className="flex flex-col gap-4">
<p className="mt-2 max-w-[500px] select-text break-words text-white"> <p className="mb-3 mt-2 max-w-[500px] select-text break-words text-sm text-white">
{user?.about} {user?.about}
</p> </p>
<UserStats pubkey={pubkey} /> <UserStats pubkey={pubkey} />
</div> </div>
<div className="mt-4 inline-flex items-center gap-2">
{followed ? (
<button
type="button"
onClick={() => unfollowUser(pubkey)}
className="inline-flex h-10 w-36 items-center justify-center rounded-md bg-white/10 text-sm font-medium backdrop-blur-xl hover:bg-fuchsia-500"
>
Unfollow
</button>
) : (
<button
type="button"
onClick={() => followUser(pubkey)}
className="inline-flex h-10 w-36 items-center justify-center rounded-md bg-white/10 text-sm font-medium backdrop-blur-xl hover:bg-fuchsia-500"
>
Follow
</button>
)}
<Link
to={`/chats/${pubkey}`}
className="inline-flex h-10 w-36 items-center justify-center rounded-md bg-white/10 text-sm font-medium backdrop-blur-xl hover:bg-fuchsia-500"
>
Message
</Link>
</div>
</div> </div>
</div> </div>
); );

View File

@ -5,7 +5,8 @@ import { VList } from 'virtua';
import { useNDK } from '@libs/ndk/provider'; import { useNDK } from '@libs/ndk/provider';
import { ArticleNote, NoteSkeleton, NoteWrapper } from '@shared/notes'; import { LoaderIcon } from '@shared/icons';
import { ArticleNote, NoteWrapper } from '@shared/notes';
import { TitleBar } from '@shared/titleBar'; import { TitleBar } from '@shared/titleBar';
import { WidgetWrapper } from '@shared/widgets'; import { WidgetWrapper } from '@shared/widgets';
@ -14,13 +15,14 @@ import { Widget } from '@utils/types';
export function GlobalArticlesWidget({ params }: { params: Widget }) { export function GlobalArticlesWidget({ params }: { params: Widget }) {
const { ndk } = useNDK(); const { ndk } = useNDK();
const { status, data } = useQuery( const { status, data } = useQuery(
[params.id + '-' + params.title], ['global-articles'],
async () => { async () => {
const events = await ndk.fetchEvents({ const events = await ndk.fetchEvents({
kinds: [NDKKind.Article], kinds: [NDKKind.Article],
limit: 100, limit: 200,
}); });
return [...events] as unknown as NDKEvent[]; const sortedEvents = [...events].sort((x, y) => y.created_at - x.created_at);
return sortedEvents;
}, },
{ refetchOnWindowFocus: false } { refetchOnWindowFocus: false }
); );
@ -40,11 +42,12 @@ export function GlobalArticlesWidget({ params }: { params: Widget }) {
return ( return (
<WidgetWrapper> <WidgetWrapper>
<TitleBar id={params.id} title={params.title} /> <TitleBar id={params.id} title={params.title} />
<div className="h-full"> <div className="flex-1">
{status === 'loading' ? ( {status === 'loading' ? (
<div className="px-3 py-1.5"> <div className="flex h-full w-full items-center justify-center ">
<div className="rounded-xl bg-white/10 px-3 py-3 backdrop-blur-xl"> <div className="inline-flex flex-col items-center justify-center gap-2">
<NoteSkeleton /> <LoaderIcon className="h-5 w-5 animate-spin text-white" />
<p className="text-sm font-medium text-white/80">Loading article...</p>
</div> </div>
</div> </div>
) : data.length === 0 ? ( ) : data.length === 0 ? (
@ -52,12 +55,10 @@ export function GlobalArticlesWidget({ params }: { params: Widget }) {
<div className="flex flex-col items-center gap-4"> <div className="flex flex-col items-center gap-4">
<img src="/ghost.png" alt="empty feeds" className="h-16 w-16" /> <img src="/ghost.png" alt="empty feeds" className="h-16 w-16" />
<div className="text-center"> <div className="text-center">
<h3 className="text-xl font-semibold leading-tight"> <h3 className="font-semibold leading-tight">
Your newsfeed is empty Oops, it looks like there are no articles.
</h3> </h3>
<p className="text-center text-white/50"> <p className="text-white/50">You can close this widget</p>
Connect more people to explore more content
</p>
</div> </div>
</div> </div>
</div> </div>

View File

@ -5,23 +5,26 @@ import { VList } from 'virtua';
import { useNDK } from '@libs/ndk/provider'; import { useNDK } from '@libs/ndk/provider';
import { FileNote, NoteSkeleton, NoteWrapper } from '@shared/notes'; import { LoaderIcon } from '@shared/icons';
import { FileNote, NoteWrapper } from '@shared/notes';
import { TitleBar } from '@shared/titleBar'; import { TitleBar } from '@shared/titleBar';
import { WidgetWrapper } from '@shared/widgets'; import { WidgetWrapper } from '@shared/widgets';
import { nHoursAgo } from '@utils/date';
import { Widget } from '@utils/types'; import { Widget } from '@utils/types';
export function GlobalFilesWidget({ params }: { params: Widget }) { export function GlobalFilesWidget({ params }: { params: Widget }) {
const { ndk } = useNDK(); const { ndk } = useNDK();
const { status, data } = useQuery( const { status, data } = useQuery(
[params.id + '-' + params.title], ['global-file-sharing'],
async () => { async () => {
const events = await ndk.fetchEvents({ const events = await ndk.fetchEvents({
// @ts-expect-error, NDK not support file metadata yet // @ts-expect-error, NDK not support file metadata yet
kinds: [1063], kinds: [1063],
limit: 100, since: nHoursAgo(24),
}); });
return [...events] as unknown as NDKEvent[]; const sortedEvents = [...events].sort((x, y) => y.created_at - x.created_at);
return sortedEvents;
}, },
{ refetchOnWindowFocus: false } { refetchOnWindowFocus: false }
); );
@ -41,11 +44,14 @@ export function GlobalFilesWidget({ params }: { params: Widget }) {
return ( return (
<WidgetWrapper> <WidgetWrapper>
<TitleBar id={params.id} title={params.title} /> <TitleBar id={params.id} title={params.title} />
<div className="h-full"> <div className="flex-1">
{status === 'loading' ? ( {status === 'loading' ? (
<div className="px-3 py-1.5"> <div className="flex h-full w-full items-center justify-center ">
<div className="rounded-xl bg-white/10 px-3 py-3 backdrop-blur-xl"> <div className="inline-flex flex-col items-center justify-center gap-2">
<NoteSkeleton /> <LoaderIcon className="h-5 w-5 animate-spin text-white" />
<p className="text-sm font-medium text-white/80">
Loading file sharing event...
</p>
</div> </div>
</div> </div>
) : data.length === 0 ? ( ) : data.length === 0 ? (
@ -53,12 +59,10 @@ export function GlobalFilesWidget({ params }: { params: Widget }) {
<div className="flex flex-col items-center gap-4"> <div className="flex flex-col items-center gap-4">
<img src="/ghost.png" alt="empty feeds" className="h-16 w-16" /> <img src="/ghost.png" alt="empty feeds" className="h-16 w-16" />
<div className="text-center"> <div className="text-center">
<h3 className="text-xl font-semibold leading-tight"> <h3 className="font-semibold leading-tight">
Your newsfeed is empty Oops, it looks like there are no file sharing events.
</h3> </h3>
<p className="text-center text-white/50"> <p className="text-white/50">You can close this widget</p>
Connect more people to explore more content
</p>
</div> </div>
</div> </div>
</div> </div>

View File

@ -5,10 +5,10 @@ import { VList } from 'virtua';
import { useNDK } from '@libs/ndk/provider'; import { useNDK } from '@libs/ndk/provider';
import { LoaderIcon } from '@shared/icons';
import { import {
ArticleNote, ArticleNote,
FileNote, FileNote,
NoteSkeleton,
NoteWrapper, NoteWrapper,
Repost, Repost,
TextNote, TextNote,
@ -23,14 +23,15 @@ import { Widget } from '@utils/types';
export function GlobalHashtagWidget({ params }: { params: Widget }) { export function GlobalHashtagWidget({ params }: { params: Widget }) {
const { ndk } = useNDK(); const { ndk } = useNDK();
const { status, data } = useQuery( const { status, data } = useQuery(
[params.id + '-' + params.title], ['hashtag-' + params.title],
async () => { async () => {
const events = await ndk.fetchEvents({ const events = await ndk.fetchEvents({
kinds: [NDKKind.Text, NDKKind.Repost, NDKKind.Article], kinds: [NDKKind.Text, NDKKind.Repost, NDKKind.Article],
'#t': [params.content], '#t': [params.content],
since: nHoursAgo(24), since: nHoursAgo(24),
}); });
return [...events] as unknown as NDKEvent[]; const sortedEvents = [...events].sort((x, y) => y.created_at - x.created_at);
return sortedEvents;
}, },
{ refetchOnWindowFocus: false } { refetchOnWindowFocus: false }
); );
@ -72,12 +73,15 @@ export function GlobalHashtagWidget({ params }: { params: Widget }) {
return ( return (
<WidgetWrapper> <WidgetWrapper>
<TitleBar id={params.id} title={params.title + ' in 24 hours ago'} /> <TitleBar id={params.id} title={params.title} />
<div className="h-full"> <div className="flex-1">
{status === 'loading' ? ( {status === 'loading' ? (
<div className="px-3 py-1.5"> <div className="flex h-full w-full items-center justify-center ">
<div className="rounded-xl bg-white/10 px-3 py-3 backdrop-blur-xl"> <div className="inline-flex flex-col items-center justify-center gap-2">
<NoteSkeleton /> <LoaderIcon className="h-5 w-5 animate-spin text-white" />
<p className="text-sm font-medium text-white/80">
Loading event related to the hashtag {params.title}...
</p>
</div> </div>
</div> </div>
) : data.length === 0 ? ( ) : data.length === 0 ? (
@ -85,11 +89,11 @@ export function GlobalHashtagWidget({ params }: { params: Widget }) {
<div className="flex flex-col items-center gap-4"> <div className="flex flex-col items-center gap-4">
<img src="/ghost.png" alt="empty feeds" className="h-16 w-16" /> <img src="/ghost.png" alt="empty feeds" className="h-16 w-16" />
<div className="text-center"> <div className="text-center">
<h3 className="text-xl font-semibold leading-tight"> <h3 className="font-semibold leading-tight">
Your newsfeed is empty Oops, it looks like there are no events related to {params.title}.
</h3> </h3>
<p className="text-center text-white/50"> <p className="text-white/50">
Connect more people to explore more content You can close this widget or try with other hashtag
</p> </p>
</div> </div>
</div> </div>
@ -97,7 +101,6 @@ export function GlobalHashtagWidget({ params }: { params: Widget }) {
) : ( ) : (
<VList className="scrollbar-hide h-full"> <VList className="scrollbar-hide h-full">
{data.map((item) => renderItem(item))} {data.map((item) => renderItem(item))}
<div className="h-16" /> <div className="h-16" />
</VList> </VList>
)} )}

View File

@ -6,7 +6,7 @@ import { VList } from 'virtua';
import { useStorage } from '@libs/storage/provider'; import { useStorage } from '@libs/storage/provider';
import { ArrowRightCircleIcon, LoaderIcon } from '@shared/icons'; import { ArrowRightCircleIcon, LoaderIcon } from '@shared/icons';
import { FileNote, NoteSkeleton, NoteWrapper } from '@shared/notes'; import { ArticleNote, NoteWrapper } from '@shared/notes';
import { TitleBar } from '@shared/titleBar'; import { TitleBar } from '@shared/titleBar';
import { WidgetWrapper } from '@shared/widgets'; import { WidgetWrapper } from '@shared/widgets';
@ -16,7 +16,7 @@ export function LocalArticlesWidget({ params }: { params: Widget }) {
const { db } = useStorage(); const { db } = useStorage();
const { status, data, hasNextPage, isFetchingNextPage, fetchNextPage } = const { status, data, hasNextPage, isFetchingNextPage, fetchNextPage } =
useInfiniteQuery({ useInfiniteQuery({
queryKey: [params.id + '-' + params.title], queryKey: ['local-articles'],
queryFn: async ({ pageParam = 0 }) => { queryFn: async ({ pageParam = 0 }) => {
return await db.getAllEventsByKinds([NDKKind.Article], 20, pageParam); return await db.getAllEventsByKinds([NDKKind.Article], 20, pageParam);
}, },
@ -34,7 +34,7 @@ export function LocalArticlesWidget({ params }: { params: Widget }) {
const event: NDKEvent = JSON.parse(dbEvent.event as string); const event: NDKEvent = JSON.parse(dbEvent.event as string);
return ( return (
<NoteWrapper key={event.id} event={event}> <NoteWrapper key={event.id} event={event}>
<FileNote /> <ArticleNote />
</NoteWrapper> </NoteWrapper>
); );
}, },
@ -44,11 +44,12 @@ export function LocalArticlesWidget({ params }: { params: Widget }) {
return ( return (
<WidgetWrapper> <WidgetWrapper>
<TitleBar id={params.id} title={params.title} /> <TitleBar id={params.id} title={params.title} />
<div className="h-full"> <div className="flex-1">
{status === 'loading' ? ( {status === 'loading' ? (
<div className="px-3 py-1.5"> <div className="flex h-full w-full items-center justify-center ">
<div className="rounded-xl bg-white/10 px-3 py-3 backdrop-blur-xl"> <div className="inline-flex flex-col items-center justify-center gap-2">
<NoteSkeleton /> <LoaderIcon className="h-5 w-5 animate-spin text-white" />
<p className="text-sm font-medium text-white/80">Loading article...</p>
</div> </div>
</div> </div>
) : dbEvents.length === 0 ? ( ) : dbEvents.length === 0 ? (
@ -56,12 +57,10 @@ export function LocalArticlesWidget({ params }: { params: Widget }) {
<div className="flex flex-col items-center gap-4"> <div className="flex flex-col items-center gap-4">
<img src="/ghost.png" alt="empty feeds" className="h-16 w-16" /> <img src="/ghost.png" alt="empty feeds" className="h-16 w-16" />
<div className="text-center"> <div className="text-center">
<h3 className="text-xl font-semibold leading-tight"> <h3 className="font-semibold leading-tight">
Your newsfeed is empty Oops, it looks like there are no articles.
</h3> </h3>
<p className="text-center text-white/50"> <p className="text-white/50">You can close this widget</p>
Connect more people to explore more content
</p>
</div> </div>
</div> </div>
</div> </div>

View File

@ -14,7 +14,6 @@ import {
TextNote, TextNote,
UnknownNote, UnknownNote,
} from '@shared/notes'; } from '@shared/notes';
import { NoteSkeleton } from '@shared/notes/skeleton';
import { TitleBar } from '@shared/titleBar'; import { TitleBar } from '@shared/titleBar';
import { WidgetWrapper } from '@shared/widgets'; import { WidgetWrapper } from '@shared/widgets';
@ -24,7 +23,7 @@ export function LocalFeedsWidget({ params }: { params: Widget }) {
const { db } = useStorage(); const { db } = useStorage();
const { status, data, hasNextPage, isFetchingNextPage, fetchNextPage } = const { status, data, hasNextPage, isFetchingNextPage, fetchNextPage } =
useInfiniteQuery({ useInfiniteQuery({
queryKey: [params.id + '-' + params.title], queryKey: ['group-feeds-' + params.id],
queryFn: async ({ pageParam = 0 }) => { queryFn: async ({ pageParam = 0 }) => {
const authors = JSON.parse(params.content); const authors = JSON.parse(params.content);
return await db.getAllEventsByAuthors(authors, 20, pageParam); return await db.getAllEventsByAuthors(authors, 20, pageParam);
@ -81,11 +80,12 @@ export function LocalFeedsWidget({ params }: { params: Widget }) {
return ( return (
<WidgetWrapper> <WidgetWrapper>
<TitleBar id={params.id} title={params.title} /> <TitleBar id={params.id} title={params.title} />
<div className="h-full"> <div className="flex-1">
{status === 'loading' ? ( {status === 'loading' ? (
<div className="px-3 py-1.5"> <div className="flex h-full w-full items-center justify-center ">
<div className="rounded-xl bg-white/10 px-3 py-3 backdrop-blur-xl"> <div className="inline-flex flex-col items-center justify-center gap-2">
<NoteSkeleton /> <LoaderIcon className="h-5 w-5 animate-spin text-white" />
<p className="text-sm font-medium text-white/80">Loading newsfeed...</p>
</div> </div>
</div> </div>
) : dbEvents.length === 0 ? ( ) : dbEvents.length === 0 ? (
@ -93,12 +93,10 @@ export function LocalFeedsWidget({ params }: { params: Widget }) {
<div className="flex flex-col items-center gap-4"> <div className="flex flex-col items-center gap-4">
<img src="/ghost.png" alt="empty feeds" className="h-16 w-16" /> <img src="/ghost.png" alt="empty feeds" className="h-16 w-16" />
<div className="text-center"> <div className="text-center">
<h3 className="text-xl font-semibold leading-tight"> <h3 className="font-semibold leading-tight">
Your newsfeed is empty Oops, it looks like there are no posts.
</h3> </h3>
<p className="text-center text-white/50"> <p className="text-white/50">You can close this widget</p>
Connect more people to explore more content
</p>
</div> </div>
</div> </div>
</div> </div>

View File

@ -6,7 +6,7 @@ import { VList } from 'virtua';
import { useStorage } from '@libs/storage/provider'; import { useStorage } from '@libs/storage/provider';
import { ArrowRightCircleIcon, LoaderIcon } from '@shared/icons'; import { ArrowRightCircleIcon, LoaderIcon } from '@shared/icons';
import { FileNote, NoteSkeleton, NoteWrapper } from '@shared/notes'; import { FileNote, NoteWrapper } from '@shared/notes';
import { TitleBar } from '@shared/titleBar'; import { TitleBar } from '@shared/titleBar';
import { WidgetWrapper } from '@shared/widgets'; import { WidgetWrapper } from '@shared/widgets';
@ -16,7 +16,7 @@ export function LocalFilesWidget({ params }: { params: Widget }) {
const { db } = useStorage(); const { db } = useStorage();
const { status, data, hasNextPage, isFetchingNextPage, fetchNextPage } = const { status, data, hasNextPage, isFetchingNextPage, fetchNextPage } =
useInfiniteQuery({ useInfiniteQuery({
queryKey: [params.id + '-' + params.title], queryKey: ['local-file-sharing'],
queryFn: async ({ pageParam = 0 }) => { queryFn: async ({ pageParam = 0 }) => {
return await db.getAllEventsByKinds([1063], 20, pageParam); return await db.getAllEventsByKinds([1063], 20, pageParam);
}, },
@ -44,11 +44,14 @@ export function LocalFilesWidget({ params }: { params: Widget }) {
return ( return (
<WidgetWrapper> <WidgetWrapper>
<TitleBar id={params.id} title={params.title} /> <TitleBar id={params.id} title={params.title} />
<div className="h-full"> <div className="flex-1">
{status === 'loading' ? ( {status === 'loading' ? (
<div className="px-3 py-1.5"> <div className="flex h-full w-full items-center justify-center ">
<div className="rounded-xl bg-white/10 px-3 py-3 backdrop-blur-xl"> <div className="inline-flex flex-col items-center justify-center gap-2">
<NoteSkeleton /> <LoaderIcon className="h-5 w-5 animate-spin text-white" />
<p className="text-sm font-medium text-white/80">
Loading file sharing event...
</p>
</div> </div>
</div> </div>
) : dbEvents.length === 0 ? ( ) : dbEvents.length === 0 ? (
@ -56,12 +59,10 @@ export function LocalFilesWidget({ params }: { params: Widget }) {
<div className="flex flex-col items-center gap-4"> <div className="flex flex-col items-center gap-4">
<img src="/ghost.png" alt="empty feeds" className="h-16 w-16" /> <img src="/ghost.png" alt="empty feeds" className="h-16 w-16" />
<div className="text-center"> <div className="text-center">
<h3 className="text-xl font-semibold leading-tight"> <h3 className="font-semibold leading-tight">
Your newsfeed is empty Oops, it looks like there are no file sharing events.
</h3> </h3>
<p className="text-center text-white/50"> <p className="text-white/50">You can close this widget</p>
Connect more people to explore more content
</p>
</div> </div>
</div> </div>
</div> </div>

View File

@ -14,7 +14,6 @@ import {
TextNote, TextNote,
UnknownNote, UnknownNote,
} from '@shared/notes'; } from '@shared/notes';
import { NoteSkeleton } from '@shared/notes/skeleton';
import { TitleBar } from '@shared/titleBar'; import { TitleBar } from '@shared/titleBar';
import { WidgetWrapper } from '@shared/widgets'; import { WidgetWrapper } from '@shared/widgets';
@ -24,7 +23,7 @@ export function LocalFollowsWidget({ params }: { params: Widget }) {
const { db } = useStorage(); const { db } = useStorage();
const { status, data, hasNextPage, isFetchingNextPage, fetchNextPage } = const { status, data, hasNextPage, isFetchingNextPage, fetchNextPage } =
useInfiniteQuery({ useInfiniteQuery({
queryKey: [params.id + '-' + params.title], queryKey: ['follows-' + params.title],
queryFn: async ({ pageParam = 0 }) => { queryFn: async ({ pageParam = 0 }) => {
return await db.getAllEventsByAuthors(db.account.follows, 20, pageParam); return await db.getAllEventsByAuthors(db.account.follows, 20, pageParam);
}, },
@ -80,11 +79,12 @@ export function LocalFollowsWidget({ params }: { params: Widget }) {
return ( return (
<WidgetWrapper> <WidgetWrapper>
<TitleBar id={params.id} title="Follows" /> <TitleBar id={params.id} title="Follows" />
<div className="h-full"> <div className="flex-1">
{status === 'loading' ? ( {status === 'loading' ? (
<div className="px-3 py-1.5"> <div className="flex h-full w-full items-center justify-center ">
<div className="rounded-xl bg-white/10 px-3 py-3 backdrop-blur-xl"> <div className="inline-flex flex-col items-center justify-center gap-2">
<NoteSkeleton /> <LoaderIcon className="h-5 w-5 animate-spin text-white" />
<p className="text-sm font-medium text-white/80">Loading post...</p>
</div> </div>
</div> </div>
) : dbEvents.length === 0 ? ( ) : dbEvents.length === 0 ? (
@ -92,12 +92,10 @@ export function LocalFollowsWidget({ params }: { params: Widget }) {
<div className="flex flex-col items-center gap-4"> <div className="flex flex-col items-center gap-4">
<img src="/ghost.png" alt="empty feeds" className="h-16 w-16" /> <img src="/ghost.png" alt="empty feeds" className="h-16 w-16" />
<div className="text-center"> <div className="text-center">
<h3 className="text-xl font-semibold leading-tight"> <h3 className="font-semibold leading-tight">
Your newsfeed is empty Oops, it looks like there are no posts.
</h3> </h3>
<p className="text-center text-white/50"> <p className="text-white/50">You can close this widget</p>
Connect more people to explore more content
</p>
</div> </div>
</div> </div>
</div> </div>

View File

@ -103,7 +103,7 @@ export function LocalNetworkWidget() {
return ( return (
<WidgetWrapper> <WidgetWrapper>
<TitleBar title="Network" /> <TitleBar title="Network" />
<div className="h-full"> <div className="flex-1">
{status === 'loading' ? ( {status === 'loading' ? (
<div className="px-3 py-1.5"> <div className="px-3 py-1.5">
<div className="rounded-xl bg-white/10 px-3 py-3 backdrop-blur-xl"> <div className="rounded-xl bg-white/10 px-3 py-3 backdrop-blur-xl">

View File

@ -69,6 +69,7 @@ export function LocalThreadWidget({ params }: { params: Widget }) {
<NoteReplyForm id={params.content} pubkey={db.account.pubkey} /> <NoteReplyForm id={params.content} pubkey={db.account.pubkey} />
<RepliesList id={params.content} /> <RepliesList id={params.content} />
</div> </div>
<div className="h-16" />
</div> </div>
</WidgetWrapper> </WidgetWrapper>
); );

View File

@ -1,7 +1,7 @@
import { NDKEvent, NDKKind } from '@nostr-dev-kit/ndk'; import { NDKEvent, NDKKind } from '@nostr-dev-kit/ndk';
import { useQuery } from '@tanstack/react-query'; import { useQuery } from '@tanstack/react-query';
import { useCallback } from 'react'; import { useCallback } from 'react';
import { VList } from 'virtua'; import { WVList } from 'virtua';
import { useNDK } from '@libs/ndk/provider'; import { useNDK } from '@libs/ndk/provider';
@ -24,14 +24,16 @@ import { Widget } from '@utils/types';
export function LocalUserWidget({ params }: { params: Widget }) { export function LocalUserWidget({ params }: { params: Widget }) {
const { ndk } = useNDK(); const { ndk } = useNDK();
const { status, data } = useQuery( const { status, data } = useQuery(
[params.id + '-' + params.title], ['user-posts', params.content],
async () => { async () => {
const events = await ndk.fetchEvents({ const events = await ndk.fetchEvents({
kinds: [1, 6], // @ts-expect-error, NDK not support file metadata yet
kinds: [NDKKind.Text, NDKKind.Repost, 1063, NDKKind.Article],
authors: [params.content], authors: [params.content],
since: nHoursAgo(24), since: nHoursAgo(24),
}); });
return [...events] as unknown as NDKEvent[]; const sortedEvents = [...events].sort((x, y) => y.created_at - x.created_at);
return sortedEvents;
}, },
{ {
staleTime: Infinity, staleTime: Infinity,
@ -84,7 +86,9 @@ export function LocalUserWidget({ params }: { params: Widget }) {
<UserProfile pubkey={params.content} /> <UserProfile pubkey={params.content} />
</div> </div>
<div> <div>
<h3 className="mt-4 px-3 text-lg font-semibold text-white">Latest posts</h3> <h3 className="mb-3 mt-4 px-3 text-lg font-semibold text-white">
Latest posts
</h3>
<div className="flex h-full w-full flex-col justify-between gap-1.5 pb-10"> <div className="flex h-full w-full flex-col justify-between gap-1.5 pb-10">
{status === 'loading' ? ( {status === 'loading' ? (
<div className="px-3 py-1.5"> <div className="px-3 py-1.5">
@ -97,16 +101,16 @@ export function LocalUserWidget({ params }: { params: Widget }) {
<div className="rounded-xl bg-white/10 px-3 py-6 backdrop-blur-xl"> <div className="rounded-xl bg-white/10 px-3 py-6 backdrop-blur-xl">
<div className="flex flex-col items-center gap-4"> <div className="flex flex-col items-center gap-4">
<p className="text-center text-sm text-white"> <p className="text-center text-sm text-white">
No new post from user in 24 hours ago No new post from 24 hours ago
</p> </p>
</div> </div>
</div> </div>
</div> </div>
) : ( ) : (
<VList className="scrollbar-hide h-full"> <WVList>
{data.map((item) => renderItem(item))} {data.map((item) => renderItem(item))}
<div className="h-16" /> <div className="h-16" />
</VList> </WVList>
)} )}
</div> </div>
</div> </div>

View File

@ -1,6 +1,7 @@
import { useQuery } from '@tanstack/react-query'; import { useQuery } from '@tanstack/react-query';
import { VList } from 'virtua';
import { NoteSkeleton } from '@shared/notes/skeleton'; import { LoaderIcon } from '@shared/icons';
import { TitleBar } from '@shared/titleBar'; import { TitleBar } from '@shared/titleBar';
import { WidgetWrapper } from '@shared/widgets'; import { WidgetWrapper } from '@shared/widgets';
import { NostrBandUserProfile, type Profile } from '@shared/widgets/nostrBandUserProfile'; import { NostrBandUserProfile, type Profile } from '@shared/widgets/nostrBandUserProfile';
@ -34,27 +35,34 @@ export function TrendingAccountsWidget({ params }: { params: Widget }) {
return ( return (
<WidgetWrapper> <WidgetWrapper>
<TitleBar id={params.id} title="Trending Accounts" /> <TitleBar id={params.id} title="Trending Accounts" />
<div className="scrollbar-hide h-full max-w-full overflow-y-auto pb-20"> <div className="flex-1">
{status === 'loading' ? ( {status === 'loading' ? (
<div className="px-3 py-1.5"> <div className="flex h-full w-full items-center justify-center ">
<div className="rounded-xl bg-white/10 px-3 py-3 backdrop-blur-xl"> <div className="inline-flex flex-col items-center justify-center gap-2">
<NoteSkeleton /> <LoaderIcon className="h-5 w-5 animate-spin text-white" />
</div> <p className="text-sm font-medium text-white/80">
</div> Loading trending accounts...
) : status === 'error' ? (
<div className="px-3 py-1.5">
<div className="rounded-xl bg-white/10 px-3 py-3 backdrop-blur-xl">
<p className="text-center text-sm font-medium text-white">
Sorry, an unexpected error has occurred.
</p> </p>
</div> </div>
</div> </div>
) : status === 'error' ? (
<div className="flex h-full w-full flex-col items-center justify-center px-3">
<div className="flex flex-col items-center gap-4">
<img src="/ghost.png" alt="empty feeds" className="h-16 w-16" />
<div className="text-center">
<h3 className="font-semibold leading-tight">
Sorry, an unexpected error has occurred.
</h3>
</div>
</div>
</div>
) : ( ) : (
<div className="relative flex w-full flex-col gap-3 px-3 pt-1.5"> <VList className="scrollbar-hide h-full">
{data.map((item: Profile) => ( {data.map((item: Profile) => (
<NostrBandUserProfile key={item.pubkey} data={item} /> <NostrBandUserProfile key={item.pubkey} data={item} />
))} ))}
</div> <div className="h-16" />
</VList>
)} )}
</div> </div>
</WidgetWrapper> </WidgetWrapper>

View File

@ -1,7 +1,9 @@
import { NDKEvent } from '@nostr-dev-kit/ndk'; import { NDKEvent } from '@nostr-dev-kit/ndk';
import { useQuery } from '@tanstack/react-query'; import { useQuery } from '@tanstack/react-query';
import { VList } from 'virtua';
import { NoteSkeleton, NoteWrapper, TextNote } from '@shared/notes'; import { LoaderIcon } from '@shared/icons';
import { NoteWrapper, TextNote } from '@shared/notes';
import { TitleBar } from '@shared/titleBar'; import { TitleBar } from '@shared/titleBar';
import { WidgetWrapper } from '@shared/widgets'; import { WidgetWrapper } from '@shared/widgets';
@ -34,29 +36,36 @@ export function TrendingNotesWidget({ params }: { params: Widget }) {
return ( return (
<WidgetWrapper> <WidgetWrapper>
<TitleBar id={params.id} title="Trending Notes" /> <TitleBar id={params.id} title="Trending Notes" />
<div className="scrollbar-hide h-full max-w-full overflow-y-auto pb-20"> <div className="flex-1">
{status === 'loading' ? ( {status === 'loading' ? (
<div className="px-3 py-1.5"> <div className="flex h-full w-full items-center justify-center ">
<div className="rounded-xl bg-white/10 px-3 py-3 backdrop-blur-xl"> <div className="inline-flex flex-col items-center justify-center gap-2">
<NoteSkeleton /> <LoaderIcon className="h-5 w-5 animate-spin text-white" />
</div> <p className="text-sm font-medium text-white/80">
</div> Loading trending posts...
) : status === 'error' ? (
<div className="px-3 py-1.5">
<div className="rounded-xl bg-white/10 px-3 py-3 backdrop-blur-xl">
<p className="text-center text-sm font-medium text-white">
Sorry, an unexpected error has occurred.
</p> </p>
</div> </div>
</div> </div>
) : status === 'error' ? (
<div className="flex h-full w-full flex-col items-center justify-center px-3">
<div className="flex flex-col items-center gap-4">
<img src="/ghost.png" alt="empty feeds" className="h-16 w-16" />
<div className="text-center">
<h3 className="font-semibold leading-tight">
Sorry, an unexpected error has occurred.
</h3>
</div>
</div>
</div>
) : ( ) : (
<div className="relative flex w-full flex-col"> <VList className="scrollbar-hide h-full">
{data.map((item) => ( {data.map((item) => (
<NoteWrapper key={item.event.id} event={item.event}> <NoteWrapper key={item.event.id} event={item.event}>
<TextNote content={item.event.content} /> <TextNote content={item.event.content} />
</NoteWrapper> </NoteWrapper>
))} ))}
</div> <div className="h-16" />
</VList>
)} )}
</div> </div>
</WidgetWrapper> </WidgetWrapper>

View File

@ -72,77 +72,79 @@ export function NostrBandUserProfile({ data }: { data: Profile }) {
} }
return ( return (
<div className="rounded-xl bg-white/10 px-5 py-5 backdrop-blur-xl"> <div className="h-min w-full px-3 pb-3">
<div className="flex items-center justify-between"> <div className="rounded-xl bg-white/10 px-5 py-5 backdrop-blur-xl">
<div className="inline-flex items-center gap-2"> <div className="flex items-center justify-between">
<Image <div className="inline-flex items-center gap-2">
src={profile.picture} <Image
className="h-11 w-11 shrink-0 rounded-lg object-cover" src={profile.picture}
/> className="h-11 w-11 shrink-0 rounded-lg object-cover"
<div className="inline-flex flex-col gap-1"> />
<h3 className="max-w-[15rem] truncate font-semibold leading-none text-white"> <div className="inline-flex flex-col gap-1">
{profile.display_name || profile.name} <h3 className="max-w-[15rem] truncate font-semibold leading-none text-white">
</h3> {profile.display_name || profile.name}
<p className="max-w-[10rem] truncate text-sm leading-none text-white/50"> </h3>
{profile.nip05 || shortenKey(data.pubkey)} <p className="max-w-[10rem] truncate text-sm leading-none text-white/50">
</p> {profile.nip05 || shortenKey(data.pubkey)}
</p>
</div>
</div>
<div className="inline-flex items-center gap-2">
{followed ? (
<button
type="button"
onClick={() => unfollowUser(data.pubkey)}
className="inline-flex h-8 w-8 items-center justify-center rounded-md bg-white/10 text-white backdrop-blur-xl hover:bg-fuchsia-500 hover:text-white"
>
<UnfollowIcon className="h-4 w-4" />
</button>
) : (
<button
type="button"
onClick={() => followUser(data.pubkey)}
className="inline-flex h-8 w-8 items-center justify-center rounded-md bg-white/10 text-white backdrop-blur-xl hover:bg-fuchsia-500 hover:text-white"
>
<FollowIcon className="h-4 w-4" />
</button>
)}
</div> </div>
</div> </div>
<div className="inline-flex items-center gap-2"> <div className="mt-2">
{followed ? ( <p className="whitespace-pre-line break-words text-white">
<button {profile.about || profile.bio}
type="button" </p>
onClick={() => unfollowUser(data.pubkey)} </div>
className="inline-flex h-8 w-8 items-center justify-center rounded-md bg-white/10 text-white backdrop-blur-xl hover:bg-fuchsia-500 hover:text-white" <div className="mt-8">
> {status === 'loading' ? (
<UnfollowIcon className="h-4 w-4" /> <p>Loading...</p>
</button>
) : ( ) : (
<button <div className="flex w-full items-center gap-8">
type="button" <div className="inline-flex flex-col gap-1">
onClick={() => followUser(data.pubkey)} <span className="font-semibold leading-none text-white">
className="inline-flex h-8 w-8 items-center justify-center rounded-md bg-white/10 text-white backdrop-blur-xl hover:bg-fuchsia-500 hover:text-white" {userStats.stats[data.pubkey].followers_pubkey_count ?? 0}
> </span>
<FollowIcon className="h-4 w-4" /> <span className="text-sm leading-none text-white/50">Followers</span>
</button> </div>
<div className="inline-flex flex-col gap-1">
<span className="font-semibold leading-none text-white">
{userStats.stats[data.pubkey].pub_following_pubkey_count ?? 0}
</span>
<span className="text-sm leading-none text-white/50">Following</span>
</div>
<div className="inline-flex flex-col gap-1">
<span className="font-semibold leading-none text-white">
{userStats.stats[data.pubkey].zaps_received
? compactNumber.format(
userStats.stats[data.pubkey].zaps_received.msats / 1000
)
: 0}
</span>
<span className="text-sm leading-none text-white/50">Zaps received</span>
</div>
</div>
)} )}
</div> </div>
</div> </div>
<div className="mt-2">
<p className="whitespace-pre-line break-words text-white">
{profile.about || profile.bio}
</p>
</div>
<div className="mt-8">
{status === 'loading' ? (
<p>Loading...</p>
) : (
<div className="flex w-full items-center gap-8">
<div className="inline-flex flex-col gap-1">
<span className="font-semibold leading-none text-white">
{userStats.stats[data.pubkey].followers_pubkey_count ?? 0}
</span>
<span className="text-sm leading-none text-white/50">Followers</span>
</div>
<div className="inline-flex flex-col gap-1">
<span className="font-semibold leading-none text-white">
{userStats.stats[data.pubkey].pub_following_pubkey_count ?? 0}
</span>
<span className="text-sm leading-none text-white/50">Following</span>
</div>
<div className="inline-flex flex-col gap-1">
<span className="font-semibold leading-none text-white">
{userStats.stats[data.pubkey].zaps_received
? compactNumber.format(
userStats.stats[data.pubkey].zaps_received.msats / 1000
)
: 0}
</span>
<span className="text-sm leading-none text-white/50">Zaps received</span>
</div>
</div>
)}
</div>
</div> </div>
); );
} }

View File

@ -48,7 +48,7 @@ export function XhashtagWidget({ params }: { params: Widget }) {
try { try {
setWidget(db, { setWidget(db, {
kind: WidgetKinds.global.hashtag, kind: WidgetKinds.global.hashtag,
title: data.hashtag + ' in 24 hours ago', title: data.hashtag,
content: data.hashtag.replace('#', ''), content: data.hashtag.replace('#', ''),
}); });
// remove temp widget // remove temp widget

View File

@ -22,7 +22,7 @@ export const useActivities = create<ActivitiesState>((set) => ({
addActivity: (event: NDKEvent) => { addActivity: (event: NDKEvent) => {
set((state) => ({ set((state) => ({
activities: state.activities ? [event, ...state.activities] : [event], activities: state.activities ? [event, ...state.activities] : [event],
totalNewActivities: (state.totalNewActivities += 1), totalNewActivities: state.totalNewActivities++,
})); }));
}, },
clearTotalNewActivities: () => { clearTotalNewActivities: () => {