fix note parser
This commit is contained in:
@@ -23,16 +23,16 @@ export const noteParser = (event: Event) => {
|
|||||||
// make sure url is trimmed
|
// make sure url is trimmed
|
||||||
const url = item.trim();
|
const url = item.trim();
|
||||||
|
|
||||||
if (url.match(/\.(jpg|jpeg|gif|png|webp|avif)$/gim)) {
|
if (url.match(/\.(jpg|jpeg|gif|png|webp|avif)$/i)) {
|
||||||
// image url
|
// image url
|
||||||
content.images.push(url);
|
content.images.push(url);
|
||||||
// remove url from original content
|
// remove url from original content
|
||||||
content.parsed = content.parsed.replace(url, '');
|
content.parsed = content.parsed.toString().replace(url, '');
|
||||||
} else if (url.match(/\.(mp4|webm|mov)$/i)) {
|
} else if (url.match(/\.(mp4|webm|mov)$/i)) {
|
||||||
// video
|
// video
|
||||||
content.videos.push(url);
|
content.videos.push(url);
|
||||||
// remove url from original content
|
// remove url from original content
|
||||||
content.parsed = content.parsed.replace(url, '');
|
content.parsed = content.parsed.toString().replace(url, '');
|
||||||
} else {
|
} else {
|
||||||
content.parsed = reactStringReplace(content.parsed, url, () => {
|
content.parsed = reactStringReplace(content.parsed, url, () => {
|
||||||
return (
|
return (
|
||||||
@@ -65,5 +65,12 @@ export const noteParser = (event: Event) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// remove extra spaces
|
||||||
|
content.parsed.forEach((item, index) => {
|
||||||
|
if (typeof item === 'string') {
|
||||||
|
content.parsed[index] = item.replace(/\s{2,}/g, ' ');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return content;
|
return content;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,7 +2,10 @@ import { MediaOutlet, MediaPlayer } from '@vidstack/react';
|
|||||||
|
|
||||||
export default function VideoPreview({ urls }: { urls: string[] }) {
|
export default function VideoPreview({ urls }: { urls: string[] }) {
|
||||||
return (
|
return (
|
||||||
<div onClick={(e) => e.stopPropagation()} className="relative mt-2 flex w-full flex-col rounded-lg bg-zinc-950">
|
<div
|
||||||
|
onClick={(e) => e.stopPropagation()}
|
||||||
|
className="relative mt-2 flex w-full flex-col overflow-hidden rounded-lg bg-zinc-950"
|
||||||
|
>
|
||||||
<MediaPlayer src={urls[0]} poster="" controls>
|
<MediaPlayer src={urls[0]} poster="" controls>
|
||||||
<MediaOutlet />
|
<MediaOutlet />
|
||||||
</MediaPlayer>
|
</MediaPlayer>
|
||||||
|
|||||||
@@ -10,9 +10,18 @@ import { memo, useContext } from 'react';
|
|||||||
import useSWRSubscription from 'swr/subscription';
|
import useSWRSubscription from 'swr/subscription';
|
||||||
import { navigate } from 'vite-plugin-ssr/client/router';
|
import { navigate } from 'vite-plugin-ssr/client/router';
|
||||||
|
|
||||||
|
function isJSON(str: string) {
|
||||||
|
try {
|
||||||
|
JSON.parse(str);
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
export const RootNote = memo(function RootNote({ id, fallback }: { id: string; fallback?: any }) {
|
export const RootNote = memo(function RootNote({ id, fallback }: { id: string; fallback?: any }) {
|
||||||
const pool: any = useContext(RelayContext);
|
const pool: any = useContext(RelayContext);
|
||||||
const parseFallback = fallback.length > 1 ? JSON.parse(fallback) : null;
|
const parseFallback = isJSON(fallback) ? JSON.parse(fallback) : null;
|
||||||
|
|
||||||
const { data, error } = useSWRSubscription(parseFallback ? null : id, (key, { next }) => {
|
const { data, error } = useSWRSubscription(parseFallback ? null : id, (key, { next }) => {
|
||||||
const unsubscribe = pool.subscribe(
|
const unsubscribe = pool.subscribe(
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export const NoteDefaultUser = ({ pubkey, time }: { pubkey: string; time: number
|
|||||||
<div className="group relative z-10 flex h-11 items-center gap-2">
|
<div className="group relative z-10 flex h-11 items-center gap-2">
|
||||||
{isError || isLoading ? (
|
{isError || isLoading ? (
|
||||||
<>
|
<>
|
||||||
<div className="h-11 w-11 shrink animate-pulse overflow-hidden rounded-md"></div>
|
<div className="h-11 w-11 shrink animate-pulse overflow-hidden rounded-md bg-zinc-800"></div>
|
||||||
<div className="flex w-full flex-1 items-start justify-between">
|
<div className="flex w-full flex-1 items-start justify-between">
|
||||||
<div className="flex flex-col gap-1">
|
<div className="flex flex-col gap-1">
|
||||||
<div className="flex items-baseline gap-2">
|
<div className="flex items-baseline gap-2">
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export const NoteRepostUser = ({ pubkey, time }: { pubkey: string; time: number
|
|||||||
<div className="group flex items-center gap-2">
|
<div className="group flex items-center gap-2">
|
||||||
{isError || isLoading ? (
|
{isError || isLoading ? (
|
||||||
<>
|
<>
|
||||||
<div className="relative h-11 w-11 shrink animate-pulse overflow-hidden rounded-md"></div>
|
<div className="relative h-11 w-11 shrink animate-pulse overflow-hidden rounded-md bg-zinc-800"></div>
|
||||||
<div className="flex w-full flex-1 items-start justify-between">
|
<div className="flex w-full flex-1 items-start justify-between">
|
||||||
<div className="flex flex-col gap-1">
|
<div className="flex flex-col gap-1">
|
||||||
<div className="flex items-baseline gap-2">
|
<div className="flex items-baseline gap-2">
|
||||||
|
|||||||
Reference in New Issue
Block a user