import React, { useState, useEffect } from 'react'; import { ExternalLink, FileText, Loader2, Brain, Cpu, MessageSquare } from 'lucide-react'; import { Link } from 'react-router-dom'; import api from '../services/api'; interface Algorithm { algorithm: string; name: string; category: string; description: string; count: number; sampleIds: string[]; } interface Paper { pmid: string; title: string; authors: string[]; journal: string; pubDate: string; } interface AlgorithmCardProps { algorithm: Algorithm; problem: string; onSeeMorePapers: (algorithm: string) => void; } const AlgorithmCard: React.FC = ({ algorithm, problem, onSeeMorePapers }) => { const [samplePapers, setSamplePapers] = useState([]); const [loadingPapers, setLoadingPapers] = useState(false); useEffect(() => { // Temporarily disabled to avoid PubMed API rate limiting issues // if (algorithm.sampleIds.length > 0) { // fetchSamplePapers(); // } }, [algorithm.sampleIds]); const fetchSamplePapers = async () => { try { setLoadingPapers(true); console.log(`[${algorithm.name}] Fetching sample papers for IDs:`, algorithm.sampleIds); const papers = []; // Fetch papers sequentially with delays to avoid rate limiting for (let i = 0; i < algorithm.sampleIds.length && i < 2; i++) { try { console.log(`[${algorithm.name}] Fetching paper ${i + 1}/${Math.min(algorithm.sampleIds.length, 2)}: ${algorithm.sampleIds[i]}`); if (i > 0) { // Add delay between requests to avoid rate limiting await new Promise(resolve => setTimeout(resolve, 500)); } const response = await api.get(`/pubmed/paper/${algorithm.sampleIds[i]}`); console.log(`[${algorithm.name}] Response for ${algorithm.sampleIds[i]}:`, response.status, response.data); if (response.data && response.data.title) { papers.push(response.data); console.log(`[${algorithm.name}] Successfully added paper: ${response.data.title}`); } else { console.log(`[${algorithm.name}] Invalid paper data for ${algorithm.sampleIds[i]}:`, response.data); } } catch (error) { console.error(`[${algorithm.name}] Failed to fetch paper ${algorithm.sampleIds[i]}:`, { status: error.response?.status, statusText: error.response?.statusText, data: error.response?.data, message: error.message }); // Continue with next paper if one fails } } console.log(`[${algorithm.name}] Final fetched papers:`, papers); setSamplePapers(papers); } catch (error) { console.error(`[${algorithm.name}] Failed to fetch sample papers:`, error); } finally { setLoadingPapers(false); } }; const getCategoryIcon = (category: string) => { switch (category) { case 'deep_learning': return ; case 'llms': return ; default: return ; } }; const getCategoryColor = (category: string) => { switch (category) { case 'deep_learning': return 'bg-purple-100 text-purple-800'; case 'llms': return 'bg-green-100 text-green-800'; default: return 'bg-blue-100 text-blue-800'; } }; return (
{getCategoryIcon(algorithm.category)} {algorithm.name}
{algorithm.category === 'deep_learning' ? 'Deep Learning' : algorithm.category === 'llms' ? 'LLMs' : 'Classical ML'}

{algorithm.description}

{algorithm.count.toLocaleString()}
Papers Found
{algorithm.sampleIds.length > 0 && (

Sample Papers:

{loadingPapers ? (
Loading papers...
) : samplePapers.length > 0 ? (
{samplePapers.slice(0, 2).map((paper) => (

{paper.title}

{paper.journal} {paper.pubDate && `(${paper.pubDate})`}

))}
) : (

{algorithm.count} papers found - Click "See More Papers on PubMed" to view

)}
)}
); }; export default AlgorithmCard;