mirror of
https://github.com/aljazceru/rabbit.git
synced 2025-12-18 14:34:25 +01:00
update
This commit is contained in:
@@ -7,6 +7,7 @@ import ColumnItem from '@/components/ColumnItem';
|
|||||||
import UserDisplayName from '@/components/UserDisplayName';
|
import UserDisplayName from '@/components/UserDisplayName';
|
||||||
import eventWrapper from '@/core/event';
|
import eventWrapper from '@/core/event';
|
||||||
import useFormatDate from '@/hooks/useFormatDate';
|
import useFormatDate from '@/hooks/useFormatDate';
|
||||||
|
import useModalState from '@/hooks/useModalState';
|
||||||
import TextNoteDisplayById from './textNote/TextNoteDisplayById';
|
import TextNoteDisplayById from './textNote/TextNoteDisplayById';
|
||||||
|
|
||||||
export type DeprecatedRepostProps = {
|
export type DeprecatedRepostProps = {
|
||||||
@@ -14,6 +15,7 @@ export type DeprecatedRepostProps = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const DeprecatedRepost: Component<DeprecatedRepostProps> = (props) => {
|
const DeprecatedRepost: Component<DeprecatedRepostProps> = (props) => {
|
||||||
|
const { showProfile } = useModalState();
|
||||||
const formatDate = useFormatDate();
|
const formatDate = useFormatDate();
|
||||||
const repostedId = () => props.event.tags.find(([tagName]) => tagName === 'e')?.[1];
|
const repostedId = () => props.event.tags.find(([tagName]) => tagName === 'e')?.[1];
|
||||||
const event = createMemo(() => eventWrapper(props.event));
|
const event = createMemo(() => eventWrapper(props.event));
|
||||||
@@ -25,7 +27,12 @@ const DeprecatedRepost: Component<DeprecatedRepostProps> = (props) => {
|
|||||||
<ArrowPathRoundedSquare />
|
<ArrowPathRoundedSquare />
|
||||||
</div>
|
</div>
|
||||||
<div class="flex-1 truncate break-all">
|
<div class="flex-1 truncate break-all">
|
||||||
|
<button
|
||||||
|
class="hover:text-blue-500 hover:underline"
|
||||||
|
onClick={() => showProfile(props.event.pubkey)}
|
||||||
|
>
|
||||||
<UserDisplayName pubkey={props.event.pubkey} />
|
<UserDisplayName pubkey={props.event.pubkey} />
|
||||||
|
</button>
|
||||||
{' がリポスト'}
|
{' がリポスト'}
|
||||||
</div>
|
</div>
|
||||||
<div>{formatDate(event().createdAtAsDate())}</div>
|
<div>{formatDate(event().createdAtAsDate())}</div>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import XMark from 'heroicons/24/outline/x-mark.svg';
|
|||||||
|
|
||||||
import Modal from '@/components/Modal';
|
import Modal from '@/components/Modal';
|
||||||
import Copy from '@/components/utils/Copy';
|
import Copy from '@/components/utils/Copy';
|
||||||
|
import SafeLink from '@/components/utils/SafeLink';
|
||||||
|
|
||||||
import useProfile from '@/nostr/useProfile';
|
import useProfile from '@/nostr/useProfile';
|
||||||
import npubEncodeFallback from '@/utils/npubEncodeFallback';
|
import npubEncodeFallback from '@/utils/npubEncodeFallback';
|
||||||
@@ -23,25 +24,19 @@ const ProfileDisplay: Component<ProfileDisplayProps> = (props) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal onClose={() => props.onClose?.()}>
|
<Modal onClose={() => props.onClose?.()}>
|
||||||
<div class="max-h-full w-[640px] max-w-full overflow-scroll">
|
<div class="max-h-full w-[640px] max-w-full">
|
||||||
<div class="flex justify-end">
|
<button class="h-8 w-8 text-stone-700" aria-label="Close" onClick={() => props.onClose?.()}>
|
||||||
<button
|
|
||||||
class="h-8 w-8 text-stone-700"
|
|
||||||
aria-label="Close"
|
|
||||||
onClick={() => props.onClose?.()}
|
|
||||||
>
|
|
||||||
<XMark />
|
<XMark />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
|
||||||
<div class="flex w-full flex-col overflow-hidden rounded-2xl border bg-white text-stone-700 shadow-lg">
|
<div class="flex w-full flex-col overflow-hidden rounded-2xl border bg-white text-stone-700 shadow-lg">
|
||||||
<Show when={query.isFetched} fallback={<>loading</>}>
|
<Show when={query.isFetched} fallback={<>loading</>}>
|
||||||
<div class="h-40 w-full sm:h-52">
|
<Show when={profile()?.banner} fallback={<div class="h-20" />} keyed>
|
||||||
<Show when={profile()?.banner} keyed>
|
|
||||||
{(bannerUrl) => (
|
{(bannerUrl) => (
|
||||||
|
<div class="h-40 w-full sm:h-52">
|
||||||
<img src={bannerUrl} alt="header" class="h-full w-full object-cover" />
|
<img src={bannerUrl} alt="header" class="h-full w-full object-cover" />
|
||||||
|
</div>
|
||||||
)}
|
)}
|
||||||
</Show>
|
</Show>
|
||||||
</div>
|
|
||||||
<div class="flex h-[64px] items-center gap-4 px-4">
|
<div class="flex h-[64px] items-center gap-4 px-4">
|
||||||
<div class="mt-[-64px] h-28 w-28 shrink-0 rounded-lg bg-stone-400 shadow-md">
|
<div class="mt-[-64px] h-28 w-28 shrink-0 rounded-lg bg-stone-400 shadow-md">
|
||||||
<Show when={profile()?.picture} keyed>
|
<Show when={profile()?.picture} keyed>
|
||||||
@@ -54,35 +49,33 @@ const ProfileDisplay: Component<ProfileDisplayProps> = (props) => {
|
|||||||
)}
|
)}
|
||||||
</Show>
|
</Show>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div class="flex-1 overflow-hidden">
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<div class="truncate text-xl font-bold">{profile()?.display_name}</div>
|
<div class="truncate text-xl font-bold">{profile()?.display_name}</div>
|
||||||
<div class="shrink-0 text-sm font-bold">@{profile()?.name}</div>
|
<div class="shrink-0 text-sm font-bold">@{profile()?.name}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex gap-1">
|
<div class="flex gap-1">
|
||||||
<div class="truncate text-xs">{npub()}</div>
|
<div class="truncate text-xs">{npub()}</div>
|
||||||
<Copy class="h-4 w-4 text-stone-500 hover:text-stone-700" text={npub()} />
|
<Copy
|
||||||
|
class="h-4 w-4 shrink-0 text-stone-500 hover:text-stone-700"
|
||||||
|
text={npub()}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="max-h-32 overflow-scroll whitespace-pre-wrap px-5 py-2 text-sm">
|
<div class="max-h-32 overflow-auto whitespace-pre-wrap px-5 py-2 text-sm">
|
||||||
{profile()?.about}
|
{profile()?.about}
|
||||||
</div>
|
</div>
|
||||||
<ul class="border-t px-5 py-2 text-xs">
|
<ul class="border-t px-5 py-2 text-xs">
|
||||||
<Show when={profile()?.website}>
|
<Show when={profile()?.website} keyed>
|
||||||
|
{(website) => (
|
||||||
<li class="flex items-center gap-1">
|
<li class="flex items-center gap-1">
|
||||||
<span class="inline-block h-4 w-4" area-label="website" title="website">
|
<span class="inline-block h-4 w-4" area-label="website" title="website">
|
||||||
<GlobeAlt />
|
<GlobeAlt />
|
||||||
</span>
|
</span>
|
||||||
<a
|
<SafeLink class="text-blue-500 underline" href={website} />
|
||||||
class="text-blue-500 underline"
|
|
||||||
href={profile()?.website}
|
|
||||||
target="_blank"
|
|
||||||
rel="noreferrer noopener"
|
|
||||||
>
|
|
||||||
{profile()?.website}
|
|
||||||
</a>
|
|
||||||
</li>
|
</li>
|
||||||
|
)}
|
||||||
</Show>
|
</Show>
|
||||||
</ul>
|
</ul>
|
||||||
</Show>
|
</Show>
|
||||||
|
|||||||
@@ -8,13 +8,17 @@ import UserDisplayName from '@/components/UserDisplayName';
|
|||||||
|
|
||||||
import useProfile from '@/nostr/useProfile';
|
import useProfile from '@/nostr/useProfile';
|
||||||
import useEvent from '@/nostr/useEvent';
|
import useEvent from '@/nostr/useEvent';
|
||||||
|
import eventWrapper from '@/core/event';
|
||||||
|
import useModalState from '@/hooks/useModalState';
|
||||||
|
|
||||||
type ReactionProps = {
|
type ReactionProps = {
|
||||||
event: NostrEvent;
|
event: NostrEvent;
|
||||||
};
|
};
|
||||||
|
|
||||||
const Reaction: Component<ReactionProps> = (props) => {
|
const Reaction: Component<ReactionProps> = (props) => {
|
||||||
const eventId = () => props.event.tags.find(([tagName]) => tagName === 'e')?.[1];
|
const { showProfile } = useModalState();
|
||||||
|
const event = () => eventWrapper(props.event);
|
||||||
|
const eventId = () => event().taggedEvents()[0].id;
|
||||||
|
|
||||||
const { profile } = useProfile(() => ({
|
const { profile } = useProfile(() => ({
|
||||||
pubkey: props.event.pubkey,
|
pubkey: props.event.pubkey,
|
||||||
@@ -50,9 +54,12 @@ const Reaction: Component<ReactionProps> = (props) => {
|
|||||||
</Show>
|
</Show>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<span class="truncate whitespace-pre-wrap break-all font-bold">
|
<button
|
||||||
|
class="truncate whitespace-pre-wrap break-all font-bold hover:text-blue-500 hover:underline"
|
||||||
|
onClick={() => showProfile(props.event.pubkey)}
|
||||||
|
>
|
||||||
<UserDisplayName pubkey={props.event.pubkey} />
|
<UserDisplayName pubkey={props.event.pubkey} />
|
||||||
</span>
|
</button>
|
||||||
{' がリアクション'}
|
{' がリアクション'}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -63,7 +70,7 @@ const Reaction: Component<ReactionProps> = (props) => {
|
|||||||
fallback={<div class="truncate">loading {eventId()}</div>}
|
fallback={<div class="truncate">loading {eventId()}</div>}
|
||||||
keyed
|
keyed
|
||||||
>
|
>
|
||||||
{(event) => <TextNoteDisplay event={event} />}
|
{(ev) => <TextNoteDisplay event={ev} />}
|
||||||
</Show>
|
</Show>
|
||||||
</div>
|
</div>
|
||||||
</ColumnItem>
|
</ColumnItem>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { Component, createEffect, createSignal, Show } from 'solid-js';
|
import { Component, createEffect, createSignal, Show } from 'solid-js';
|
||||||
import { fixUrl } from '@/utils/imageUrl';
|
import { fixUrl } from '@/utils/imageUrl';
|
||||||
|
import SafeLink from '../utils/SafeLink';
|
||||||
|
|
||||||
type ImageDisplayProps = {
|
type ImageDisplayProps = {
|
||||||
url: string;
|
url: string;
|
||||||
@@ -21,13 +22,13 @@ const ImageDisplay: Component<ImageDisplayProps> = (props) => {
|
|||||||
</button>
|
</button>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<a class="my-2 block" href={props.url} target="_blank" rel="noopener noreferrer">
|
<SafeLink class="my-2 block" href={props.url}>
|
||||||
<img
|
<img
|
||||||
class="inline-block max-h-64 max-w-full rounded object-contain shadow hover:shadow-md"
|
class="inline-block max-h-64 max-w-full rounded object-contain shadow hover:shadow-md"
|
||||||
src={fixUrl(new URL(props.url)).toString()}
|
src={fixUrl(props.url)}
|
||||||
alt={props.url}
|
alt={props.url}
|
||||||
/>
|
/>
|
||||||
</a>
|
</SafeLink>
|
||||||
</Show>
|
</Show>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import PlainTextDisplay from '@/components/textNote/PlainTextDisplay';
|
|||||||
import MentionedUserDisplay from '@/components/textNote/MentionedUserDisplay';
|
import MentionedUserDisplay from '@/components/textNote/MentionedUserDisplay';
|
||||||
import MentionedEventDisplay from '@/components/textNote/MentionedEventDisplay';
|
import MentionedEventDisplay from '@/components/textNote/MentionedEventDisplay';
|
||||||
import ImageDisplay from '@/components/textNote/ImageDisplay';
|
import ImageDisplay from '@/components/textNote/ImageDisplay';
|
||||||
|
import SafeLink from '@/components/utils/SafeLink';
|
||||||
import eventWrapper from '@/core/event';
|
import eventWrapper from '@/core/event';
|
||||||
import { isImageUrl } from '@/utils/imageUrl';
|
import { isImageUrl } from '@/utils/imageUrl';
|
||||||
import useConfig from '@/nostr/useConfig';
|
import useConfig from '@/nostr/useConfig';
|
||||||
@@ -58,16 +59,7 @@ const TextNoteContentDisplay = (props: TextNoteContentDisplayProps) => {
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return (
|
return <SafeLink class="text-blue-500 underline" href={item.content} />;
|
||||||
<a
|
|
||||||
class="text-blue-500 underline"
|
|
||||||
href={item.content}
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
>
|
|
||||||
{item.content}
|
|
||||||
</a>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -161,12 +161,14 @@ const TextNoteDisplay: Component<TextNoteDisplayProps> = (props) => {
|
|||||||
<div class="min-w-0 flex-auto">
|
<div class="min-w-0 flex-auto">
|
||||||
<div class="flex justify-between gap-1 text-xs">
|
<div class="flex justify-between gap-1 text-xs">
|
||||||
<button
|
<button
|
||||||
class="author flex min-w-0 truncate"
|
class="author flex min-w-0 truncate hover:text-blue-500"
|
||||||
onClick={() => showProfile(event().pubkey)}
|
onClick={() => showProfile(event().pubkey)}
|
||||||
>
|
>
|
||||||
{/* TODO link to author */}
|
{/* TODO link to author */}
|
||||||
<Show when={(author()?.display_name?.length ?? 0) > 0}>
|
<Show when={(author()?.display_name?.length ?? 0) > 0}>
|
||||||
<div class="author-name truncate pr-1 font-bold">{author()?.display_name}</div>
|
<div class="author-name truncate pr-1 font-bold hover:underline">
|
||||||
|
{author()?.display_name}
|
||||||
|
</div>
|
||||||
</Show>
|
</Show>
|
||||||
<div class="author-username truncate text-zinc-600">
|
<div class="author-username truncate text-zinc-600">
|
||||||
<Show
|
<Show
|
||||||
@@ -192,7 +194,7 @@ const TextNoteDisplay: Component<TextNoteDisplayProps> = (props) => {
|
|||||||
<For each={event().mentionedPubkeys()}>
|
<For each={event().mentionedPubkeys()}>
|
||||||
{(replyToPubkey: string) => (
|
{(replyToPubkey: string) => (
|
||||||
<button
|
<button
|
||||||
class="pr-1 text-blue-500 underline"
|
class="pr-1 text-blue-500 hover:underline"
|
||||||
onClick={() => showProfile(replyToPubkey)}
|
onClick={() => showProfile(replyToPubkey)}
|
||||||
>
|
>
|
||||||
<GeneralUserMentionDisplay pubkey={replyToPubkey} />
|
<GeneralUserMentionDisplay pubkey={replyToPubkey} />
|
||||||
|
|||||||
28
src/components/utils/SafeLink.tsx
Normal file
28
src/components/utils/SafeLink.tsx
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import { Component, Show, JSX } from 'solid-js';
|
||||||
|
|
||||||
|
type SafeLinkProps = {
|
||||||
|
class?: string;
|
||||||
|
href: string;
|
||||||
|
children?: JSX.Element;
|
||||||
|
};
|
||||||
|
|
||||||
|
const SafeLink: Component<SafeLinkProps> = (props) => {
|
||||||
|
const isSafe = () => {
|
||||||
|
try {
|
||||||
|
const url = new URL(props.href.toString());
|
||||||
|
return url.protocol === 'https:' || url.protocol === 'http:';
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Show when={isSafe()} fallback={props.href}>
|
||||||
|
<a class={props.class} href={props.href} target="_blank" rel="noreferrer noopener">
|
||||||
|
{props.children ?? props.href}
|
||||||
|
</a>
|
||||||
|
</Show>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SafeLink;
|
||||||
@@ -2,7 +2,9 @@ export const isImageUrl = (url: URL): boolean => {
|
|||||||
return /\.(jpeg|jpg|png|gif|webp)$/i.test(url.pathname);
|
return /\.(jpeg|jpg|png|gif|webp)$/i.test(url.pathname);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const fixUrl = (url: URL): URL => {
|
export const fixUrl = (urlString: string): string => {
|
||||||
|
try {
|
||||||
|
const url = new URL(urlString);
|
||||||
// Imgur
|
// Imgur
|
||||||
if (url.host === 'i.imgur.com' || url.host === 'imgur.com') {
|
if (url.host === 'i.imgur.com' || url.host === 'imgur.com') {
|
||||||
const match = url.pathname.match(/^\/([a-zA-Z0-9]+)\.(jpg|jpeg|png|gif)/);
|
const match = url.pathname.match(/^\/([a-zA-Z0-9]+)\.(jpg|jpeg|png|gif)/);
|
||||||
@@ -11,9 +13,9 @@ export const fixUrl = (url: URL): URL => {
|
|||||||
const imageId = match[1];
|
const imageId = match[1];
|
||||||
result.host = 'i.imgur.com';
|
result.host = 'i.imgur.com';
|
||||||
result.pathname = `${imageId}l.webp`;
|
result.pathname = `${imageId}l.webp`;
|
||||||
return result;
|
return result.toString();
|
||||||
}
|
}
|
||||||
return url;
|
return url.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gyazo
|
// Gyazo
|
||||||
@@ -21,8 +23,11 @@ export const fixUrl = (url: URL): URL => {
|
|||||||
const result = new URL(url);
|
const result = new URL(url);
|
||||||
result.host = 'thumb.gyazo.com';
|
result.host = 'thumb.gyazo.com';
|
||||||
result.pathname = `/thumb/640_w${url.pathname}`;
|
result.pathname = `/thumb/640_w${url.pathname}`;
|
||||||
return result;
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
return url;
|
return url.toString();
|
||||||
|
} catch {
|
||||||
|
return urlString;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user