mirror of
https://github.com/purrgrammer/grimoire.git
synced 2026-04-08 22:47:02 +02:00
feat: rich relay links in chat
This commit is contained in:
@@ -1,39 +1,19 @@
|
||||
import type { RelayNode } from "@/lib/relay-transformer";
|
||||
import { useAddWindow } from "@/core/state";
|
||||
import { RelayLink } from "../RelayLink";
|
||||
|
||||
interface RelayNodeProps {
|
||||
node: RelayNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format relay URL for display by removing protocol and trailing slashes
|
||||
*/
|
||||
function formatRelayUrlForDisplay(url: string): string {
|
||||
return url
|
||||
.replace(/^wss?:\/\//, "") // Remove ws:// or wss://
|
||||
.replace(/\/$/, ""); // Remove trailing slash
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a relay URL as a clickable link that opens the relay viewer
|
||||
*/
|
||||
export function Relay({ node }: RelayNodeProps) {
|
||||
const addWindow = useAddWindow();
|
||||
const { url } = node;
|
||||
|
||||
const displayUrl = formatRelayUrlForDisplay(url);
|
||||
|
||||
const openRelay = () => {
|
||||
addWindow("relay", { url });
|
||||
};
|
||||
|
||||
return (
|
||||
<button
|
||||
onClick={openRelay}
|
||||
className="text-muted-foreground underline decoration-dotted hover:text-foreground cursor-crosshair"
|
||||
title={url}
|
||||
>
|
||||
{displayUrl}
|
||||
</button>
|
||||
<RelayLink
|
||||
url={node.url}
|
||||
className="inline-flex underline decoration-dotted cursor-crosshair hover:text-foreground"
|
||||
urlClassname="text-inherit"
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user