Files
moeum/src/components/MainContent.tsx
T
2025-11-14 16:38:38 +00:00

116 lines
4.0 KiB
TypeScript

import { ChevronRight, MessageSquare, Eye, MoreHorizontal, Download } from 'lucide-react';
import { useArticle } from '../hooks/useApi';
interface MainContentProps {
theme: 'light' | 'dark';
articleSlug: string | null;
}
export function MainContent({ theme, articleSlug }: MainContentProps) {
const { data: article, isLoading, error } = useArticle(articleSlug);
if (!articleSlug) {
return (
<main className="flex-1 max-w-4xl px-4 sm:px-6 lg:px-12 py-4 sm:py-8">
<div className={`text-center py-12 ${
theme === 'dark' ? 'text-gray-400' : 'text-gray-600'
}`}>
<p className="text-lg">Select an article from the sidebar to view its content</p>
</div>
</main>
);
}
if (isLoading) {
return (
<main className="flex-1 max-w-4xl px-4 sm:px-6 lg:px-12 py-4 sm:py-8">
<div className={`text-center py-12 ${
theme === 'dark' ? 'text-gray-400' : 'text-gray-600'
}`}>
<p className="text-lg">Loading article...</p>
</div>
</main>
);
}
if (error || !article) {
return (
<main className="flex-1 max-w-4xl px-4 sm:px-6 lg:px-12 py-4 sm:py-8">
<div className={`text-center py-12 ${
theme === 'dark' ? 'text-red-400' : 'text-red-600'
}`}>
<p className="text-lg">Error loading article</p>
</div>
</main>
);
}
return (
<main className="flex-1 max-w-4xl px-4 sm:px-6 lg:px-12 py-4 sm:py-8">
{/* Breadcrumb */}
<div className={`flex items-center gap-2 text-xs sm:text-sm mb-4 sm:mb-6 ${
theme === 'dark' ? 'text-gray-400' : 'text-gray-600'
}`}>
<a href="#" className="hover:text-blue-600">Learn</a>
<ChevronRight className="w-3 h-3 sm:w-4 sm:h-4" />
<span>{article.title?.slice(0, 10)}</span>
</div>
{/* Action buttons */}
<div className="flex items-center gap-2 mb-4 sm:mb-6 flex-wrap">
<button className="flex items-center gap-2 px-3 py-1.5 bg-pink-600 text-white text-xs sm:text-sm rounded hover:bg-pink-700">
<MessageSquare className="w-3 h-3 sm:w-4 sm:h-4" />
<span className="hidden sm:inline">Ask Learn</span>
<span className="sm:hidden">Ask</span>
</button>
<button className={`flex items-center gap-2 px-3 py-1.5 text-xs sm:text-sm rounded border ${
theme === 'dark'
? 'bg-[#2d2d2d] text-white border-gray-700 hover:bg-[#3d3d3d]'
: 'bg-white text-gray-900 border-gray-300 hover:bg-gray-50'
}`}>
<Eye className="w-3 h-3 sm:w-4 sm:h-4" />
<span className="hidden sm:inline">Focus mode</span>
<span className="sm:hidden">Focus</span>
</button>
<button className={`p-1.5 rounded ${
theme === 'dark' ? 'hover:bg-gray-800' : 'hover:bg-gray-100'
}`}>
<MoreHorizontal className="w-4 h-4" />
</button>
</div>
{/* Main heading */}
<h1 className="text-2xl sm:text-3xl lg:text-4xl mb-4 sm:mb-6">{article.title}</h1>
{/* Article metadata */}
{article.updatedAt && (
<div className={`mb-6 text-xs ${
theme === 'dark' ? 'text-gray-500' : 'text-gray-500'
}`}>
Last updated: {new Date(article.updatedAt).toLocaleDateString()}
</div>
)}
{/* Article content */}
<div
className={`mb-6 sm:mb-8 leading-relaxed text-sm sm:text-base prose max-w-none ${
theme === 'dark' ? 'text-gray-300 prose-invert' : 'text-gray-700'
}`}
dangerouslySetInnerHTML={{ __html: article.content || '' }}
/>
{/* Footer */}
<div className={`mt-8 sm:mt-12 pt-4 sm:pt-6 border-t ${
theme === 'dark' ? 'border-gray-800' : 'border-gray-200'
}`}>
<button className={`flex items-center gap-2 text-xs sm:text-sm ${
theme === 'dark' ? 'text-gray-400 hover:text-white' : 'text-gray-600 hover:text-gray-900'
}`}>
<Download className="w-3 h-3 sm:w-4 sm:h-4" />
Download PDF
</button>
</div>
</main>
);
}