Files
DeepTutor/web/components/common/ChatFileLink.tsx
Qiu 506cea9d4f feat(desktop): finish Windows chat file actions (#3051)
Continues #2978 and closes #2887. Includes the original Windows file actions, integrates the changes with dev, and adds an explicit default-app action.

Co-authored-by: Botong Wu <2048400180@qq.com>
2026-11-28 13:09:15 -03:00

55 lines
1.3 KiB
TypeScript

"use client";
import type { ReactNode } from "react";
import type { MessageAttachment } from "@/features/chat/ChatStateAdapter";
import { isChatFileLink } from "@/lib/chat-file-link";
import { scopedUrl } from "@/lib/workspace-scope";
export function ChatFileLink({
attachment,
onOpen,
className,
children,
ariaLabel,
unavailableReference,
}: {
attachment: MessageAttachment;
onOpen?: (attachment: MessageAttachment) => void;
className: string;
children: ReactNode;
ariaLabel?: string;
unavailableReference?: string;
}) {
const href = attachment.url && isChatFileLink(attachment.url)
? scopedUrl(attachment.url)
: unavailableReference
? `#chat-file-unavailable-${encodeURIComponent(unavailableReference)}`
: null;
if (href && onOpen) {
return (
<a
href={href}
data-chat-file-link=""
onClick={(event) => {
event.preventDefault();
onOpen(attachment);
}}
className={className}
aria-label={ariaLabel}
>
{children}
</a>
);
}
return (
<button
type="button"
onClick={onOpen ? () => onOpen(attachment) : undefined}
className={className}
aria-label={ariaLabel}
>
{children}
</button>
);
}