Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 4 additions & 22 deletions src/components/RepositoryCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,10 @@ const RepositoryCardComponent: React.FC<RepositoryCardProps> = ({
const [editModalOpen, setEditModalOpen] = useState(false);
const [readmeModalOpen, setReadmeModalOpen] = useState(false);
const [showTooltip, setShowTooltip] = useState(false);
const [isTextTruncated, setIsTextTruncated] = useState(false);
const [unstarring, setUnstarring] = useState(false);
const [showDragHint, setShowDragHint] = useState(false);
const dragHintTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);

const descriptionRef = useRef<HTMLParagraphElement>(null);

// 高亮搜索关键词的工具函数 - 使用缓存优化
const highlightSearchTerm = useCallback((text: string, searchTerm: string): React.ReactNode => {
if (!searchTerm.trim() || !text) return text;
Expand Down Expand Up @@ -176,28 +173,14 @@ const RepositoryCardComponent: React.FC<RepositoryCardProps> = ({
return result;
}, []);

// Check if text is actually truncated by comparing scroll height with client height
// Cleanup drag hint timeout on unmount
useEffect(() => {
const checkTruncation = () => {
if (descriptionRef.current) {
const element = descriptionRef.current;
const isTruncated = element.scrollHeight > element.clientHeight;
setIsTextTruncated(isTruncated);
}
};

// Check truncation after component mounts and when content changes
checkTruncation();

// Also check on window resize
window.addEventListener('resize', checkTruncation);
return () => {
window.removeEventListener('resize', checkTruncation);
if (dragHintTimeoutRef.current) {
clearTimeout(dragHintTimeoutRef.current);
}
};
}, [repository, showAISummary]);
}, []);

const formatNumber = (num: number) => {
if (num >= 1000000) return `${(num / 1000000).toFixed(1)}M`;
Expand Down Expand Up @@ -882,18 +865,17 @@ const RepositoryCardComponent: React.FC<RepositoryCardProps> = ({
<div className="mb-4 flex-1">
<div
className="relative group"
onMouseEnter={() => isTextTruncated && setShowTooltip(true)}
onMouseEnter={() => setShowTooltip(true)}
onMouseLeave={() => setShowTooltip(false)}
>
<p
ref={descriptionRef}
className="text-gray-800 dark:text-text-secondary text-[13px] leading-[1.625] line-clamp-3 mb-2 transition-colors duration-200 hover:text-gray-900 dark:hover:text-text-primary rounded px-1 -mx-1 hover:bg-gray-50/50 dark:hover:bg-white/[0.02]"
>
{highlightSearchTerm(displayContent.content, searchQuery)}
</p>

{/* Enhanced Tooltip - Optimized for Light Mode Readability */}
{isTextTruncated && showTooltip && (
{showTooltip && (
<div className="absolute z-50 bottom-full left-0 right-0 mb-2 p-4 bg-white dark:bg-surface-3 text-gray-900 dark:text-text-primary text-[13px] leading-[1.625] rounded-xl shadow-dialog border border-gray-200/80 dark:border-white/[0.04] animate-fade-in max-h-[280px] overflow-y-auto scrollbar-auto">
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
<div className="whitespace-pre-wrap break-words pr-2">
{highlightSearchTerm(displayContent.content, searchQuery)}
Expand Down
38 changes: 33 additions & 5 deletions src/components/SubscriptionRepoCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export const SubscriptionRepoCard: React.FC<SubscriptionRepoCardProps> = ({ repo
// 取消Star确认对话框状态
const [unstarConfirmOpen, setUnstarConfirmOpen] = useState(false);
const [pendingUnstarAction, setPendingUnstarAction] = useState<(() => void) | null>(null);
const [descTooltip, setDescTooltip] = useState(false);
const [aiTooltip, setAiTooltip] = useState(false);

const abortControllerRef = useRef<AbortController | null>(null);

Expand Down Expand Up @@ -403,18 +405,44 @@ export const SubscriptionRepoCard: React.FC<SubscriptionRepoCardProps> = ({ repo

{/* Description */}
{repo.description && (
<p className="text-sm text-gray-700 dark:text-text-tertiary mb-3 line-clamp-2">
{repo.description}
</p>
<div
className="relative mb-3"
onMouseEnter={() => setDescTooltip(true)}
onMouseLeave={() => setDescTooltip(false)}
>
<p className="text-sm text-gray-700 dark:text-text-tertiary line-clamp-2 rounded px-1 -mx-1 hover:bg-gray-50/50 dark:hover:bg-white/[0.02] transition-colors duration-200">
{repo.description}
</p>
{descTooltip && (
<div className="absolute z-50 bottom-full left-0 right-0 mb-2 p-4 bg-white dark:bg-surface-3 text-gray-900 dark:text-text-primary text-sm leading-[1.625] rounded-xl shadow-dialog border border-gray-200/80 dark:border-white/[0.04] animate-fade-in max-h-[280px] overflow-y-auto scrollbar-auto">
<div className="whitespace-pre-wrap break-words pr-2">
{repo.description}
</div>
<div className="absolute top-full left-4 w-0 h-0 border-l-[6px] border-l-transparent border-r-[6px] border-r-transparent border-t-[6px] border-t-white dark:border-t-surface-3 drop-shadow-sm"></div>
</div>
)}
</div>
Comment thread
coderabbitai[bot] marked this conversation as resolved.
)}

{/* AI Summary */}
{repo.ai_summary && (
<div className="flex items-start gap-1.5 mb-3">
<div
className="relative flex items-start gap-1.5 mb-3"
onMouseEnter={() => setAiTooltip(true)}
onMouseLeave={() => setAiTooltip(false)}
>
<Bot className="w-4 h-4 text-gray-700 dark:text-text-secondary flex-shrink-0 mt-0.5" />
<p className="text-sm text-gray-700 dark:text-text-secondary line-clamp-2">
<p className="text-sm text-gray-700 dark:text-text-secondary line-clamp-2 rounded px-1 -mx-1 hover:bg-gray-50/50 dark:hover:bg-white/[0.02] transition-colors duration-200">
{repo.ai_summary}
</p>
{aiTooltip && (
<div className="absolute z-50 bottom-full left-0 right-0 mb-2 p-4 bg-white dark:bg-surface-3 text-gray-900 dark:text-text-primary text-sm leading-[1.625] rounded-xl shadow-dialog border border-gray-200/80 dark:border-white/[0.04] animate-fade-in max-h-[280px] overflow-y-auto scrollbar-auto">
<div className="whitespace-pre-wrap break-words pr-2">
{repo.ai_summary}
</div>
<div className="absolute top-full left-4 w-0 h-0 border-l-[6px] border-l-transparent border-r-[6px] border-r-transparent border-t-[6px] border-t-white dark:border-t-surface-3 drop-shadow-sm"></div>
</div>
)}
</div>
)}

Expand Down
Loading