minor fixes

This commit is contained in:
Ren Amamiya
2023-04-29 09:25:33 +07:00
parent a1385f87dc
commit be8b40c86d
10 changed files with 70 additions and 66 deletions

View File

@@ -4,49 +4,46 @@ import { RelayPool } from 'nostr-relaypool';
import useSWRSubscription from 'swr/subscription';
export const useChannelProfile = (id: string, channelPubkey: string) => {
const { data } = useSWRSubscription(
id
? [
{
kinds: [41],
'#e': [id],
},
{
ids: [id],
kinds: [40],
},
]
: null,
(key, { next }) => {
const pool = new RelayPool(FULL_RELAYS);
const unsubscribe = pool.subscribe(
key,
FULL_RELAYS,
(event: { kind: number; pubkey: string; content: string }) => {
switch (event.kind) {
case 40:
next(null, JSON.parse(event.content));
break;
case 41:
if (event.pubkey === channelPubkey) {
next(null, JSON.parse(event.content));
}
default:
break;
}
},
undefined,
undefined,
const { data } = useSWRSubscription(id ? id : null, (key, { next }) => {
const pool = new RelayPool(FULL_RELAYS);
const unsubscribe = pool.subscribe(
[
{
unsubscribeOnEose: true,
kinds: [41],
'#e': [key],
},
{
ids: [key],
kinds: [40],
},
],
FULL_RELAYS,
(event: { kind: number; pubkey: string; content: string }) => {
switch (event.kind) {
case 40:
next(null, JSON.parse(event.content));
break;
case 41:
console.log(event);
if (event.pubkey === channelPubkey) {
next(null, JSON.parse(event.content));
}
break;
default:
break;
}
);
},
undefined,
undefined,
{
unsubscribeOnEose: true,
}
);
return () => {
unsubscribe();
};
}
);
return () => {
unsubscribe();
};
});
return data;
};

View File

@@ -14,10 +14,10 @@ export const messageParser = (noteContent: any) => {
return <ImagePreview key={match + i} url={match} size="small" />;
} else if (match.match(/(http:|https:)?(\/\/)?(www\.)?(youtube.com|youtu.be)\/(watch|embed)?(\?v=|\/)?(\S+)?/)) {
// youtube
return <YoutubePreview key={match + i} url={match} />;
return <YoutubePreview key={match + i} url={match} size="small" />;
} else if (match.match(/\.(mp4|webm)$/i)) {
// video
return <VideoPreview key={match + i} url={match} />;
return <VideoPreview key={match + i} url={match} size="small" />;
} else {
return (
<a key={match + i} href={match} className="cursor-pointer text-fuchsia-500" target="_blank" rel="noreferrer">