This commit is contained in:
Ren Amamiya 2023-08-04 08:51:26 +07:00
parent 2e47415160
commit ac50cd1373
16 changed files with 108 additions and 78 deletions

View File

@ -81,7 +81,7 @@
"@tauri-apps/cli": "2.0.0-alpha.10",
"@trivago/prettier-plugin-sort-imports": "^4.2.0",
"@types/html-to-text": "^9.0.1",
"@types/node": "^18.17.1",
"@types/node": "^18.17.2",
"@types/react": "^18.2.18",
"@types/react-dom": "^18.2.7",
"@types/youtube-player": "^5.5.7",

View File

@ -190,8 +190,8 @@ devDependencies:
specifier: ^9.0.1
version: 9.0.1
'@types/node':
specifier: ^18.17.1
version: 18.17.1
specifier: ^18.17.2
version: 18.17.2
'@types/react':
specifier: ^18.2.18
version: 18.2.18
@ -269,7 +269,7 @@ devDependencies:
version: 4.9.5
vite:
specifier: ^4.4.8
version: 4.4.8(@types/node@18.17.1)
version: 4.4.8(@types/node@18.17.2)
vite-plugin-top-level-await:
specifier: ^1.3.1
version: 1.3.1(vite@4.4.8)
@ -2437,8 +2437,8 @@ packages:
resolution: {integrity: sha512-iiUgKzV9AuaEkZqkOLDIvlQiL6ltuZd9tGcW3gwpnX8JbuiuhFlEGmmFXEXkN50Cvq7Os88IY2v0dkDqXYWVgA==}
dev: false
/@types/node@18.17.1:
resolution: {integrity: sha512-xlR1jahfizdplZYRU59JlUx9uzF1ARa8jbhM11ccpCJya8kvos5jwdm2ZAgxSCwOl0fq21svP18EVwPBXMQudw==}
/@types/node@18.17.2:
resolution: {integrity: sha512-wBo3KqP/PBqje5TI9UTiuL3yWfP6sdPtjtygSOqcYZWT232dfDeDOnkDps5wqZBP9NgGgYrNejinl0faAuE+HQ==}
dev: true
/@types/normalize-package-data@2.4.1:
@ -2614,7 +2614,7 @@ packages:
vite: ^4
dependencies:
'@swc/core': 1.3.74
vite: 4.4.8(@types/node@18.17.1)
vite: 4.4.8(@types/node@18.17.2)
transitivePeerDependencies:
- '@swc/helpers'
dev: true
@ -2912,7 +2912,7 @@ packages:
hasBin: true
dependencies:
caniuse-lite: 1.0.30001519
electron-to-chromium: 1.4.482
electron-to-chromium: 1.4.484
node-releases: 2.0.13
update-browserslist-db: 1.0.11(browserslist@4.21.10)
@ -3389,8 +3389,8 @@ packages:
/eastasianwidth@0.2.0:
resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==}
/electron-to-chromium@1.4.482:
resolution: {integrity: sha512-h+UqpfmEr1Qkk0zp7ej/jid7CXoq4m4QzW6wNTb0ELJ/BZCpA4wgUylBIMGCe621tnr4l5VmoHjdoSx2lbnNJA==}
/electron-to-chromium@1.4.484:
resolution: {integrity: sha512-nO3ZEomTK2PO/3TUXgEx0A97xZTpKVf4p427lABHuCpT1IQ2N+njVh29DkQkCk6Q4m2wjU+faK4xAcfFndwjvw==}
/emoji-regex@8.0.0:
resolution: {integrity: sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==}
@ -6586,8 +6586,8 @@ packages:
dependencies:
glob: 7.2.3
/rollup@3.27.0:
resolution: {integrity: sha512-aOltLCrYZ0FhJDm7fCqwTjIUEVjWjcydKBV/Zeid6Mn8BWgDCUBBWT5beM5ieForYNo/1ZHuGJdka26kvQ3Gzg==}
/rollup@3.27.1:
resolution: {integrity: sha512-tXNDFwOkN6C2w5Blj1g6ForKeFw6c1mDu5jxoeDO3/pmYjgt+8yvIFjKzH5FQUq70OKZBkOt0zzv0THXL7vwzQ==}
engines: {node: '>=14.18.0', npm: '>=8.0.0'}
hasBin: true
optionalDependencies:
@ -7455,7 +7455,7 @@ packages:
'@rollup/plugin-virtual': 3.0.1
'@swc/core': 1.3.74
uuid: 9.0.0
vite: 4.4.8(@types/node@18.17.1)
vite: 4.4.8(@types/node@18.17.2)
transitivePeerDependencies:
- '@swc/helpers'
- rollup
@ -7472,13 +7472,13 @@ packages:
debug: 4.3.4
globrex: 0.1.2
tsconfck: 2.1.2(typescript@4.9.5)
vite: 4.4.8(@types/node@18.17.1)
vite: 4.4.8(@types/node@18.17.2)
transitivePeerDependencies:
- supports-color
- typescript
dev: true
/vite@4.4.8(@types/node@18.17.1):
/vite@4.4.8(@types/node@18.17.2):
resolution: {integrity: sha512-LONawOUUjxQridNWGQlNizfKH89qPigK36XhMI7COMGztz8KNY0JHim7/xDd71CZwGT4HtSRgI7Hy+RlhG0Gvg==}
engines: {node: ^14.18.0 || >=16.0.0}
hasBin: true
@ -7506,10 +7506,10 @@ packages:
terser:
optional: true
dependencies:
'@types/node': 18.17.1
'@types/node': 18.17.2
esbuild: 0.18.17
postcss: 8.4.27
rollup: 3.27.0
rollup: 3.27.1
optionalDependencies:
fsevents: 2.3.2
dev: true

View File

@ -22,7 +22,7 @@ export function ThreadBlock({ params }: { params: Block }) {
// useLiveThread(params.content);
return (
<div className="scrollbar-hide w-[400px] shrink-0 overflow-y-auto bg-white/10 pb-20">
<div className="scrollbar-hide h-full w-[400px] shrink-0 overflow-y-auto bg-white/10 pb-20">
<TitleBar id={params.id} title={params.title} />
<div className="h-full">
{status === 'loading' ? (

View File

@ -45,7 +45,7 @@ export function UserBlock({ params }: { params: Block }) {
<UserProfile pubkey={params.content} />
</div>
<div>
<h3 className="mt-2 px-3 text-lg font-semibold text-white">
<h3 className="mt-4 px-3 text-lg font-semibold text-white">
Latest activities
</h3>
<div className="flex h-full w-full flex-col justify-between gap-1.5 pb-10">

View File

@ -12,7 +12,15 @@ import {
import { Content } from '@utils/types';
export function NoteContent({ content }: { content: Content }) {
export function NoteContent({ content, long }: { content: Content; long?: boolean }) {
if (long) {
return (
<ReactMarkdown className="markdown" remarkPlugins={[remarkGfm]}>
{content as unknown as string}
</ReactMarkdown>
);
}
return (
<>
<ReactMarkdown

View File

@ -26,7 +26,7 @@ export function Repost({ event }: { event: LumeEvent }) {
if (status === 'error') {
return (
<div className="flex items-center justify-center overflow-hidden rounded-xl bg-white/10 px-3 py-3">
<p className="text-white/50">Failed to fetch</p>
<p className="text-white/50">Failed to fetch event: {repostID}</p>
</div>
);
}

View File

@ -17,7 +17,7 @@ export function SubNote({ id, root }: { id: string; root?: string }) {
if (status === 'error') {
return (
<div className="mb-5 flex overflow-hidden rounded-xl bg-white/10 px-3 py-3">
<p className="text-white/50">Failed to fetch</p>
<p className="break-all text-white/50">Failed to fetch event: {id}</p>
</div>
);
}
@ -30,7 +30,7 @@ export function SubNote({ id, root }: { id: string; root?: string }) {
<div className="relative z-20 -mt-6 flex items-start gap-3">
<div className="w-11 shrink-0" />
<div className="flex-1">
<NoteContent content={data.content} />
<NoteContent content={data.content} long={data.kind === 30023} />
<NoteActions id={data.event_id} pubkey={data.pubkey} root={root} />
</div>
</div>

View File

@ -23,6 +23,14 @@ export const MentionNote = memo(function MentionNote({ id }: { id: string }) {
}
};
if (!id) {
return (
<div className="mb-2 mt-3 cursor-default rounded-lg bg-white/10 px-3 py-3">
<p className="break-all">Failed to fetch event: {id}</p>
</div>
);
}
return (
<div
onClick={(e) => openThread(e, id)}
@ -56,14 +64,14 @@ export const MentionNote = memo(function MentionNote({ id }: { id: string }) {
},
}}
>
{data?.content?.parsed?.length > 160
? data.content.parsed.substring(0, 160) + '...'
: data.content.parsed}
{data?.content?.original?.length > 160
? data.content.original.substring(0, 160) + '...'
: data.content.original}
</ReactMarkdown>
</div>
</>
) : (
<p>Failed to fetch event</p>
<p className="break-all">Failed to fetch event: {id}</p>
)}
</div>
);

View File

@ -20,7 +20,11 @@ export function MentionUser({ pubkey }: { pubkey: string }) {
}
className="break-words font-normal text-blue-400 no-underline hover:text-blue-500"
>
{'@' + user?.name || user?.displayName || displayNpub(pubkey, 16)}
{user?.nip05 ||
user?.name ||
user?.display_name ||
user?.username ||
displayNpub(pubkey, 16)}
</button>
);
}

View File

@ -61,7 +61,7 @@ export function NoteMetadata({ id }: { id: string }) {
return { replies, users, zap };
},
{ refetchOnWindowFocus: false, refetchOnReconnect: false }
{ refetchOnWindowFocus: false, refetchOnReconnect: false, refetchOnMount: false }
);
if (status === 'loading') {

View File

@ -43,7 +43,7 @@ export function RepliesList({ id }: { id: string }) {
return (
<div className="mt-3">
<div className="flex flex-col">
<div className="rounded-xl border-t border-zinc-800/50 bg-zinc-900 px-3 py-3">
<div className="rounded-xl bg-white/10 px-3 py-3">
<NoteSkeleton />
</div>
</div>

View File

@ -93,7 +93,7 @@ export function User({
</div>
<Popover.Portal>
<Popover.Content
className="w-[300px] overflow-hidden rounded-md bg-white/10 backdrop-blur-xl"
className="w-[300px] overflow-hidden rounded-md bg-white/10 backdrop-blur-xl focus:outline-none"
sideOffset={5}
>
<div className="flex gap-2.5 border-b border-white/5 px-3 py-3">

View File

@ -102,12 +102,6 @@ export function UserProfile({ pubkey }: { pubkey: string }) {
>
Message
</Link>
<button
type="button"
className="group inline-flex h-10 w-10 items-center justify-center rounded-md bg-white/10 text-sm font-medium hover:bg-orange-500"
>
<ZapIcon className="h-5 w-5" />
</button>
</div>
</div>
</div>

View File

@ -8,47 +8,56 @@ import { LumeEvent } from '@utils/types';
export function useEvent(id: string, fallback?: string) {
const { ndk } = useNDK();
const { status, data, error, isFetching } = useQuery(['note', id], async () => {
const result = await getNoteByID(id);
if (result) {
return result as LumeEvent;
} else {
if (fallback) {
const embed: LumeEvent = JSON.parse(fallback);
embed['event_id'] = embed.id;
await createNote(
embed.id,
embed.pubkey,
embed.kind,
embed.tags,
embed.content as unknown as string,
embed.created_at
);
return embed;
const { status, data, error, isFetching } = useQuery(
['note', id],
async () => {
const result = await getNoteByID(id);
if (result) {
return result as LumeEvent;
} else {
const event = await ndk.fetchEvent(id);
if (event) {
if (fallback) {
const embed: LumeEvent = JSON.parse(fallback);
embed['event_id'] = embed.id;
await createNote(
event.id,
event.pubkey,
event.kind,
event.tags,
event.content,
event.created_at
embed.id,
embed.pubkey,
embed.kind,
embed.tags,
embed.content as unknown as string,
embed.created_at
);
event['event_id'] = event.id;
if (event.kind === 1) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
event['content'] = parser(event);
}
return event as unknown as LumeEvent;
return embed;
} else {
throw new Error('Event not found');
const event = await ndk.fetchEvent(id);
if (event) {
await createNote(
event.id,
event.pubkey,
event.kind,
event.tags,
event.content,
event.created_at
);
event['event_id'] = event.id;
if (event.kind === 1) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
event['content'] = parser(event);
}
return event as unknown as LumeEvent;
} else {
throw new Error('Event not found');
}
}
}
},
{
staleTime: Infinity,
refetchOnMount: false,
refetchOnWindowFocus: false,
refetchOnReconnect: false,
}
});
);
return { status, data, error, isFetching };
}

View File

@ -1,4 +1,3 @@
import { NDKFilter } from '@nostr-dev-kit/ndk';
import { useQuery } from '@tanstack/react-query';
import { useNDK } from '@libs/ndk/provider';
@ -15,12 +14,12 @@ export function useProfile(pubkey: string, fallback?: string) {
['user', pubkey],
async () => {
if (!fallback) {
const filter: NDKFilter = { kinds: [0], authors: [pubkey] };
const events = await ndk.fetchEvents(filter);
const latest = [...events].sort((a, b) => b.created_at - a.created_at).pop();
if (latest) {
await createMetadata(latest.id, latest.pubkey, latest.content);
return JSON.parse(latest.content);
const user = await ndk.getUser({ hexpubkey: pubkey });
await user.fetchProfile();
if (user.profile) {
user.profile.display_name = user.profile.displayName;
await createMetadata(user.npub, pubkey, JSON.stringify(user.profile));
return user.profile;
} else {
throw new Error('User not found');
}
@ -30,6 +29,7 @@ export function useProfile(pubkey: string, fallback?: string) {
}
},
{
staleTime: Infinity,
refetchOnMount: false,
refetchOnWindowFocus: false,
refetchOnReconnect: false,

View File

@ -5,6 +5,8 @@ import ReactPlayer from 'react-player';
import { Content, LumeEvent } from '@utils/types';
export function parser(event: LumeEvent) {
if (event.kind !== 1) return;
const references = parseReferences(event as unknown as Event);
const urls = getUrls(event.content as unknown as string);
@ -49,6 +51,7 @@ export function parser(event: LumeEvent) {
references?.forEach((item) => {
const profile = item.profile;
const event = item.event;
const addr = item.address;
if (event) {
content.notes.push(event.id);
content.parsed = content.parsed.replace(item.text, '');
@ -56,6 +59,10 @@ export function parser(event: LumeEvent) {
if (profile) {
content.parsed = content.parsed.replace(item.text, `~pub${item.profile.pubkey}~`);
}
if (addr) {
content.notes.push(addr.identifier);
content.parsed = content.parsed.replace(item.text, '');
}
});
return content;