import { createFileRoute } from '@tanstack/react-router' import { Article } from '@/types' import { useNavigate } from '@tanstack/react-router' import { useQuery } from '@tanstack/react-query' import { fetchArticle } from '@/api/articles' import { Button } from '@/components/ui/button' export const Route = createFileRoute('/notebook')({ component: NotebookPage, validateSearch: (search: Record): { articleId?: string; article?: Article } => { return { articleId: search.articleId as string, article: search.article as Article } }, }) function NotebookPage() { const { articleId, article: preloadedArticle } = Route.useSearch() const navigate = useNavigate() const { data: fetchedArticle, isLoading, isError } = useQuery({ queryKey: ['article', articleId], queryFn: () => { if (!articleId) throw new Error('No article ID provided'); return fetchArticle(articleId); }, enabled: !!articleId && !preloadedArticle, }) const article = preloadedArticle || fetchedArticle if (isLoading) { return (
) } if (isError) { return (

Failed to load article

) } if (!article) { return (

No Article Selected

) } const cells = [ { cell_type: 'markdown', metadata: { language: 'markdown' }, source: [ `# ${article.title}`, '', `Source: ${article.source}`, `Published: ${new Date(article.publishedAt).toLocaleString()}`, article.authors.length > 0 ? `Authors: ${article.authors.join(', ')}` : '', article.categories.length > 0 ? `Categories: ${article.categories.join(', ')}` : '', '', '---', '' ] }, { cell_type: 'markdown', metadata: { language: 'markdown' }, source: [article.content.split('\n').map(line => line.trim()).join('\n\n')] }, { cell_type: 'markdown', metadata: { language: 'markdown' }, source: [ '', '---', '', '## Additional Information', '', `Original Article: [${article.url}](${article.url})` ] } ] return (

Article Notebook

{cells.map((cell, index) => (
{cell.source.map((line, i) => (
{line}
))}
))}
) }