@@ -65,8 +72,10 @@ export const NoteParent = memo(function NoteParent({ id }: { id: string }) {
- {contentParser(data.content, data.tags)}
+ {content ? content.parsed : ''}
+ {Array.isArray(content.images) && content.images.length ?
: <>>}
+ {Array.isArray(content.videos) && content.videos.length ?
: <>>}
e.stopPropagation()} className="mt-5 pl-[52px]">
diff --git a/src/app/newsfeed/components/note/quote.tsx b/src/app/newsfeed/components/note/quote.tsx
index 9cdf910f..8b728ffb 100644
--- a/src/app/newsfeed/components/note/quote.tsx
+++ b/src/app/newsfeed/components/note/quote.tsx
@@ -1,5 +1,7 @@
-import { contentParser } from '@lume/app/newsfeed/components/contentParser';
import { NoteDefaultUser } from '@lume/app/newsfeed/components/user/default';
+import { noteParser } from '@lume/app/note/components/parser';
+import ImagePreview from '@lume/app/note/components/preview/image';
+import VideoPreview from '@lume/app/note/components/preview/video';
import { RelayContext } from '@lume/shared/relayProvider';
import { READONLY_RELAYS } from '@lume/stores/constants';
@@ -42,6 +44,8 @@ export const NoteQuote = memo(function NoteQuote({ id }: { id: string }) {
}
};
+ const content = !error && data ? noteParser(data) : null;
+
return (
openNote(e)}
@@ -55,8 +59,10 @@ export const NoteQuote = memo(function NoteQuote({ id }: { id: string }) {
- {contentParser(data.content, data.tags)}
+ {content ? content.parsed : ''}
+ {Array.isArray(content.images) && content.images.length ?
: <>>}
+ {Array.isArray(content.videos) && content.videos.length ?
: <>>}
)}
diff --git a/src/app/newsfeed/components/note/rootNote.tsx b/src/app/newsfeed/components/note/rootNote.tsx
index ad9e1a05..09cc6bd0 100644
--- a/src/app/newsfeed/components/note/rootNote.tsx
+++ b/src/app/newsfeed/components/note/rootNote.tsx
@@ -1,6 +1,8 @@
-import { contentParser } from '@lume/app/newsfeed/components/contentParser';
import NoteMetadata from '@lume/app/newsfeed/components/note/metadata';
import { NoteDefaultUser } from '@lume/app/newsfeed/components/user/default';
+import { noteParser } from '@lume/app/note/components/parser';
+import ImagePreview from '@lume/app/note/components/preview/image';
+import VideoPreview from '@lume/app/note/components/preview/video';
import { RelayContext } from '@lume/shared/relayProvider';
import { READONLY_RELAYS } from '@lume/stores/constants';
@@ -44,14 +46,28 @@ export const RootNote = memo(function RootNote({ id, fallback }: { id: string; f
}
};
+ const content = !error && data ? noteParser(parseFallback) : null;
+
if (parseFallback) {
+ const contentFallback = noteParser(parseFallback);
+
return (
openNote(e)} className="relative z-10 flex flex-col">
- {contentParser(parseFallback.content, parseFallback.tags)}
+ {contentFallback.parsed}
+ {Array.isArray(contentFallback.images) && contentFallback.images.length ? (
+
+ ) : (
+ <>>
+ )}
+ {Array.isArray(contentFallback.videos) && contentFallback.videos.length ? (
+
+ ) : (
+ <>>
+ )}
e.stopPropagation()} className="mt-5 pl-[52px]">
@@ -90,8 +106,10 @@ export const RootNote = memo(function RootNote({ id, fallback }: { id: string; f
- {contentParser(data.content, data.tags)}
+ {content ? content.parsed : ''}
+ {Array.isArray(content.images) && content.images.length ?
: <>>}
+ {Array.isArray(content.videos) && content.videos.length ?
: <>>}
e.stopPropagation()} className="mt-5 pl-[52px]">
diff --git a/src/app/newsfeed/components/user/default.tsx b/src/app/newsfeed/components/user/default.tsx
index ff3acf65..96a177fc 100644
--- a/src/app/newsfeed/components/user/default.tsx
+++ b/src/app/newsfeed/components/user/default.tsx
@@ -11,10 +11,10 @@ export const NoteDefaultUser = ({ pubkey, time }: { pubkey: string; time: number
const { user, isError, isLoading } = useProfile(pubkey);
return (
-
+
{isError || isLoading ? (
<>
-
+
@@ -26,7 +26,7 @@ export const NoteDefaultUser = ({ pubkey, time }: { pubkey: string; time: number
>
) : (
<>
-
+

{
const references = parseReferences(event);
const content = { original: event.content, parsed: event.content, images: [], videos: [], others: [] };
+ // remove extra whitespace
+ content.parsed = content.parsed.replace(/\s+/g, ' ').trim();
+
// handle media
content.original.match(getURLs)?.forEach((url) => {
- if (url.match(/\.(jpg|jpeg|gif|png|webp|avif)$/i)) {
+ if (url.match(/\.(jpg|jpeg|gif|png|webp|avif)$/im)) {
// image url
content.images.push(url.trim());
// remove url from original content
@@ -21,7 +24,7 @@ export const noteParser = (event: Event) => {
content.videos.push(url.trim());
// remove url from original content
content.parsed = content.parsed.replace(url, '');
- } else if (url.match(/\.(mp4|webm|mov)$/i)) {
+ } else if (url.match(/\.(mp4|webm|mov)$/im)) {
// video
content.videos.push(url.trim());
// remove url from original content
@@ -34,13 +37,19 @@ export const noteParser = (event: Event) => {
// handle note references
references?.forEach((reference) => {
if (reference?.profile) {
- content.parsed.replace(reference.text, `
`);
+ content.parsed = content.parsed.replace(
+ reference.text,
+ `
`
+ );
}
if (reference?.event) {
- content.parsed.replace(reference.text, `
;`);
+ content.parsed = content.parsed.replace(reference.text, `
;`);
}
if (reference?.address) {
- content.parsed.replace(reference.text, `
`);
+ content.parsed = content.parsed.replace(
+ reference.text,
+ `
${reference.address}>`
+ );
}
});
diff --git a/src/app/note/components/preview/image.tsx b/src/app/note/components/preview/image.tsx
new file mode 100644
index 00000000..275fadd3
--- /dev/null
+++ b/src/app/note/components/preview/image.tsx
@@ -0,0 +1,31 @@
+export default function ImagePreview({ urls }: { urls: string[] }) {
+ return (
+
+ {urls.length === 1 ? (
+
+

+
+ ) : (
+ urls.map((url: string) => (
+
+

+
+ ))
+ )}
+
+ );
+}
diff --git a/src/app/note/components/preview/video.tsx b/src/app/note/components/preview/video.tsx
new file mode 100644
index 00000000..9607649e
--- /dev/null
+++ b/src/app/note/components/preview/video.tsx
@@ -0,0 +1,11 @@
+import { MediaOutlet, MediaPlayer } from '@vidstack/react';
+
+export default function VideoPreview({ urls }: { urls: string[] }) {
+ return (
+ e.stopPropagation()} className="relative mt-2 flex w-full flex-col rounded-lg bg-zinc-950">
+
+
+
+
+ );
+}