fix: privacy setting is not working

This commit is contained in:
reya 2024-04-17 13:50:50 +07:00
parent 413d8d82df
commit f3c52237fa
2 changed files with 33 additions and 58 deletions

View File

@ -3,7 +3,7 @@ import { Event } from "@lume/types";
import { cn } from "@lume/utils";
import { useQuery } from "@tanstack/react-query";
import { useTranslation } from "react-i18next";
import { Note, User } from "@lume/ui";
import { Note, Spinner, User } from "@lume/ui";
import { useRouteContext } from "@tanstack/react-router";
export function RepostNote({
@ -27,51 +27,16 @@ export function RepostNote({
const embed: Event = JSON.parse(event.content);
return embed;
}
const id = event.tags.find((el) => el[0] === "e")[1];
return await ark.get_event(id);
} catch {
throw new Error("Failed to get repost event");
const id = event.tags.find((el) => el[0] === "e")?.[1];
if (id) return await ark.get_event(id);
} catch (e) {
throw new Error(e);
}
},
refetchOnWindowFocus: false,
refetchOnMount: false,
});
if (isLoading) {
return <div className="w-full px-3 pb-3">Loading...</div>;
}
if (isError || !repostEvent) {
return (
<Note.Root
className={cn(
"flex flex-col gap-2 border-b border-neutral-100 px-3 py-5 dark:border-neutral-900",
className,
)}
>
<User.Provider pubkey={event.pubkey}>
<User.Root className="flex h-14 gap-2 px-3">
<div className="inline-flex w-10 shrink-0 items-center justify-center">
<RepostIcon className="h-5 w-5 text-blue-500" />
</div>
<div className="inline-flex items-center gap-2">
<User.Avatar className="size-6 shrink-0 rounded object-cover" />
<div className="inline-flex items-baseline gap-1">
<User.Name className="font-medium text-neutral-900 dark:text-neutral-100" />
<span className="text-blue-500">{t("note.reposted")}</span>
</div>
</div>
</User.Root>
</User.Provider>
<div className="mb-3 select-text px-3">
<div className="flex flex-col items-start justify-start rounded-lg bg-red-100 px-3 py-3 dark:bg-red-900">
<p className="text-red-500">Failed to get event</p>
</div>
</div>
</Note.Root>
);
}
return (
<Note.Root
className={cn(
@ -93,26 +58,34 @@ export function RepostNote({
</div>
</User.Root>
</User.Provider>
<Note.Provider event={repostEvent}>
<div className="flex flex-col gap-2">
<Note.User />
<div className="flex gap-3">
<div className="size-11 shrink-0" />
<div className="min-w-0 flex-1">
<Note.Content />
<div className="mt-4 flex items-center justify-between">
<div className="-ml-1 inline-flex items-center gap-4">
<Note.Reply />
<Note.Repost />
<Note.Pin />
{settings.zap ? <Note.Zap /> : null}
{isLoading ? (
<Spinner />
) : isError ? (
<div className="w-full h-16 flex items-center px-3 border border-neutral-100 dark:border-neutral-900">
<p>Event not found</p>
</div>
) : (
<Note.Provider event={repostEvent}>
<div className="flex flex-col gap-2">
<Note.User />
<div className="flex gap-3">
<div className="size-11 shrink-0" />
<div className="min-w-0 flex-1">
<Note.Content />
<div className="mt-4 flex items-center justify-between">
<div className="-ml-1 inline-flex items-center gap-4">
<Note.Reply />
<Note.Repost />
<Note.Pin />
{settings.zap ? <Note.Zap /> : null}
</div>
<Note.Menu />
</div>
<Note.Menu />
</div>
</div>
</div>
</div>
</Note.Provider>
</Note.Provider>
)}
</Note.Root>
);
}

View File

@ -25,7 +25,9 @@ export function NoteContent({
compact?: boolean;
className?: string;
}) {
const settings: Settings = useRouteContext({ strict: false });
const { settings }: { settings: Settings } = useRouteContext({
strict: false,
});
const event = useNoteContext();
const content = useMemo(() => {
const text = event.content.trim();
@ -124,7 +126,7 @@ export function NoteContent({
);
if (compact) {
parsedContent = reactStringReplace(parsedContent, /\n|\r/g, () => (
parsedContent = reactStringReplace(parsedContent, /[\r\n]{2,}/g, () => (
<div key={nanoid()} className="h-1.5" />
));
}