Fix initialization order for previewImages and previewVideos
Move image/video extraction before hasPreviewableContent check to avoid accessing variables before initialization. Co-authored-by: shakespeare.diy <assistant@shakespeare.diy>
This commit is contained in:
@@ -197,13 +197,24 @@ export function ComposeBox({ onSuccess, placeholder = "What's on your mind?", co
|
||||
[detectedEmbeds, removedEmbeds]
|
||||
);
|
||||
|
||||
// Extract images and videos for preview mode
|
||||
const previewImages = useMemo(() => {
|
||||
if (!content) return [];
|
||||
const urlRegex = /https?:\/\/[^\s]+\.(jpg|jpeg|png|gif|webp|svg)(\?[^\s]*)?/gi;
|
||||
return content.match(urlRegex) || [];
|
||||
}, [content]);
|
||||
|
||||
const previewVideos = useMemo(() => {
|
||||
if (!content) return [];
|
||||
const urlRegex = /https?:\/\/[^\s]+\.(mp4|webm|mov)(\?[^\s]*)?/gi;
|
||||
return content.match(urlRegex) || [];
|
||||
}, [content]);
|
||||
|
||||
// Check if content has any previewable content (link previews, images, or videos)
|
||||
const hasPreviewableContent = useMemo(() => {
|
||||
return visibleEmbeds.length > 0 || previewImages.length > 0 || previewVideos.length > 0;
|
||||
}, [visibleEmbeds, previewImages, previewVideos]);
|
||||
|
||||
|
||||
|
||||
// Include quoted event if provided and not removed
|
||||
const quotedEventId = quotedEvent ? nip19.neventEncode({ id: quotedEvent.id, author: quotedEvent.pubkey }) : null;
|
||||
const quotedEventKey = quotedEventId ? `nostr:${quotedEventId}` : null;
|
||||
@@ -227,19 +238,6 @@ export function ComposeBox({ onSuccess, placeholder = "What's on your mind?", co
|
||||
};
|
||||
}, [user, content]);
|
||||
|
||||
// Extract images and videos for preview mode
|
||||
const previewImages = useMemo(() => {
|
||||
if (!content) return [];
|
||||
const urlRegex = /https?:\/\/[^\s]+\.(jpg|jpeg|png|gif|webp|svg)(\?[^\s]*)?/gi;
|
||||
return content.match(urlRegex) || [];
|
||||
}, [content]);
|
||||
|
||||
const previewVideos = useMemo(() => {
|
||||
if (!content) return [];
|
||||
const urlRegex = /https?:\/\/[^\s]+\.(mp4|webm|mov)(\?[^\s]*)?/gi;
|
||||
return content.match(urlRegex) || [];
|
||||
}, [content]);
|
||||
|
||||
const insertEmoji = useCallback((emoji: string) => {
|
||||
const textarea = textareaRef.current;
|
||||
if (textarea) {
|
||||
|
||||
Reference in New Issue
Block a user