feat: Add ellipsis support for file name, caption, path, and time in FileExtra component

This commit is contained in:
jarvis2f 2025-02-15 21:04:38 +08:00
parent faba558f83
commit 0f66477ba2
2 changed files with 24 additions and 16 deletions

View file

@ -24,9 +24,10 @@ import useIsMobile from "@/hooks/use-is-mobile";
interface FileExtraProps { interface FileExtraProps {
file: TelegramFile; file: TelegramFile;
rowHeight: RowHeight; rowHeight: RowHeight;
ellipsis?: boolean;
} }
function FileName({ file }: { file: TelegramFile }) { function FileName({ file, ellipsis }: FileExtraProps) {
if (!file.fileName) { if (!file.fileName) {
return null; return null;
} }
@ -34,7 +35,12 @@ function FileName({ file }: { file: TelegramFile }) {
<SpoiledWrapper hasSensitiveContent={file.hasSensitiveContent}> <SpoiledWrapper hasSensitiveContent={file.hasSensitiveContent}>
<p className="flex items-center gap-2"> <p className="flex items-center gap-2">
<Mountain className="h-4 w-4 flex-shrink-0" /> <Mountain className="h-4 w-4 flex-shrink-0" />
<span className="overflow-hidden truncate text-ellipsis rounded px-1 text-sm hover:bg-gray-100 dark:hover:bg-gray-800"> <span
className={cn(
"overflow-hidden rounded px-1 text-sm hover:bg-gray-100 dark:hover:bg-gray-800",
ellipsis && "line-clamp-1",
)}
>
{file.fileName} {file.fileName}
</span> </span>
</p> </p>
@ -42,7 +48,7 @@ function FileName({ file }: { file: TelegramFile }) {
); );
} }
function FileCaption({ file, rowHeight }: FileExtraProps) { function FileCaption({ file, rowHeight, ellipsis }: FileExtraProps) {
if (!file.caption) { if (!file.caption) {
return null; return null;
} }
@ -54,8 +60,8 @@ function FileCaption({ file, rowHeight }: FileExtraProps) {
<Captions className="h-4 w-4 flex-shrink-0" /> <Captions className="h-4 w-4 flex-shrink-0" />
<p <p
className={cn( className={cn(
rowHeight !== "l" && "line-clamp-1", (rowHeight !== "l" || ellipsis) && "line-clamp-1",
"overflow-hidden truncate text-ellipsis text-wrap text-start text-sm", "overflow-hidden text-wrap text-start text-sm",
)} )}
> >
{file.caption} {file.caption}
@ -75,7 +81,7 @@ function FileCaption({ file, rowHeight }: FileExtraProps) {
); );
} }
function FilePath({ file }: { file: TelegramFile }) { function FilePath({ file, ellipsis }: FileExtraProps) {
const [, copyToClipboard] = useCopyToClipboard(); const [, copyToClipboard] = useCopyToClipboard();
const isMobile = useIsMobile(); const isMobile = useIsMobile();
@ -89,7 +95,8 @@ function FilePath({ file }: { file: TelegramFile }) {
<FileCheck className="h-4 w-4 flex-shrink-0" /> <FileCheck className="h-4 w-4 flex-shrink-0" />
<p <p
className={cn( className={cn(
"group line-clamp-1 cursor-pointer overflow-hidden truncate text-ellipsis text-wrap rounded px-1 hover:bg-gray-100 dark:hover:bg-gray-800", "group cursor-pointer overflow-hidden text-wrap rounded px-1 hover:bg-gray-100 dark:hover:bg-gray-800",
ellipsis && "line-clamp-1",
isMobile && "px-0", isMobile && "px-0",
)} )}
onClick={() => !isMobile && copyToClipboard(file.localPath)} onClick={() => !isMobile && copyToClipboard(file.localPath)}
@ -108,7 +115,7 @@ function FilePath({ file }: { file: TelegramFile }) {
); );
} }
function FileTime({ file }: { file: TelegramFile }) { function FileTime({ file }: FileExtraProps) {
const isMobile = useIsMobile(); const isMobile = useIsMobile();
return ( return (
<div className="flex items-center gap-2"> <div className="flex items-center gap-2">
@ -134,7 +141,7 @@ function FileTime({ file }: { file: TelegramFile }) {
<TooltipTrigger asChild> <TooltipTrigger asChild>
<p className="flex items-center gap-2"> <p className="flex items-center gap-2">
<ClockArrowDown className="h-4 w-4" /> <ClockArrowDown className="h-4 w-4" />
<span className="rounded px-1 text-sm text-muted-foreground hover:bg-gray-100 dark:hover:bg-gray-800"> <span className="rounded px-1 text-sm hover:bg-gray-100 dark:hover:bg-gray-800">
{formatDistanceToNow(new Date(file.completionDate), { {formatDistanceToNow(new Date(file.completionDate), {
addSuffix: true, addSuffix: true,
})} })}
@ -156,7 +163,8 @@ function hasValue(value: string | null | undefined): boolean {
return value !== null && value !== undefined && value.trim() !== ""; return value !== null && value !== undefined && value.trim() !== "";
} }
export default function FileExtra({ file, rowHeight }: FileExtraProps) { export default function FileExtra(fileExtraProps: FileExtraProps) {
const { file, rowHeight } = fileExtraProps;
if (rowHeight === "s") { if (rowHeight === "s") {
const renderOrder = [ const renderOrder = [
{ key: "fileName", Component: FileName }, { key: "fileName", Component: FileName },
@ -172,7 +180,7 @@ export default function FileExtra({ file, rowHeight }: FileExtraProps) {
) { ) {
return ( return (
<TooltipProvider> <TooltipProvider>
<item.Component file={file} rowHeight={rowHeight} /> <item.Component {...fileExtraProps} />
</TooltipProvider> </TooltipProvider>
); );
} }
@ -182,10 +190,10 @@ export default function FileExtra({ file, rowHeight }: FileExtraProps) {
return ( return (
<div className="relative flex flex-col space-y-1 overflow-hidden"> <div className="relative flex flex-col space-y-1 overflow-hidden">
<TooltipProvider> <TooltipProvider>
<FileName file={file} /> <FileName {...fileExtraProps} />
<FileCaption file={file} rowHeight={rowHeight} /> <FileCaption {...fileExtraProps} />
<FilePath file={file} /> <FilePath {...fileExtraProps} />
<FileTime file={file} /> <FileTime {...fileExtraProps} />
</TooltipProvider> </TooltipProvider>
</div> </div>
); );

View file

@ -50,7 +50,7 @@ export function FileCard({
<div className="flex items-center gap-4"> <div className="flex items-center gap-4">
<FileAvatar file={file} className="h-16 w-16 min-w-16" /> <FileAvatar file={file} className="h-16 w-16 min-w-16" />
<div className="flex-1 overflow-hidden"> <div className="flex-1 overflow-hidden">
<FileExtra file={file} rowHeight="s" /> <FileExtra file={file} rowHeight="s" ellipsis={true}/>
<div className="flex items-center justify-between"> <div className="flex items-center justify-between">
<div className="flex flex-col justify-start gap-0.5"> <div className="flex flex-col justify-start gap-0.5">
<span className="text-xs text-muted-foreground"> <span className="text-xs text-muted-foreground">