|
| 1 | +import { articles } from '@/lib/strapiClient' |
| 2 | +import { createFileRoute, Link } from '@tanstack/react-router' |
| 3 | + |
| 4 | +export const Route = createFileRoute('/demo/strapi')({ |
| 5 | + component: RouteComponent, |
| 6 | + loader: async () => { |
| 7 | + const { data: strapiArticles } = await articles.find() |
| 8 | + return strapiArticles |
| 9 | + }, |
| 10 | +}) |
| 11 | + |
| 12 | +function RouteComponent() { |
| 13 | + const strapiArticles = Route.useLoaderData() |
| 14 | + |
| 15 | + return ( |
| 16 | + <div className="min-h-screen bg-gradient-to-b from-slate-900 via-slate-800 to-slate-900 p-8"> |
| 17 | + <div className="max-w-7xl mx-auto"> |
| 18 | + <h1 className="text-4xl font-bold mb-8 text-white"> |
| 19 | + <span className="bg-gradient-to-r from-cyan-400 to-blue-400 bg-clip-text text-transparent"> |
| 20 | + Strapi |
| 21 | + </span>{' '} |
| 22 | + <span className="text-gray-300">Articles</span> |
| 23 | + </h1> |
| 24 | + |
| 25 | + {strapiArticles && strapiArticles.length > 0 ? ( |
| 26 | + <div className="grid gap-6 md:grid-cols-2 lg:grid-cols-3"> |
| 27 | + {strapiArticles.map((article) => ( |
| 28 | + <Link |
| 29 | + key={article.id} |
| 30 | + to="/demo/strapi/$articleId" |
| 31 | + params={{ articleId: article.documentId }} |
| 32 | + className="block" |
| 33 | + > |
| 34 | + <article className="bg-slate-800/50 backdrop-blur-sm border border-slate-700 rounded-xl p-6 hover:border-cyan-500/50 transition-all duration-300 hover:shadow-lg hover:shadow-cyan-500/10 cursor-pointer h-full"> |
| 35 | + <h2 className="text-xl font-semibold text-white mb-3"> |
| 36 | + {article.title || 'Untitled'} |
| 37 | + </h2> |
| 38 | + |
| 39 | + {article.description && ( |
| 40 | + <p className="text-gray-400 mb-4 leading-relaxed"> |
| 41 | + {article.description} |
| 42 | + </p> |
| 43 | + )} |
| 44 | + |
| 45 | + {article.content && ( |
| 46 | + <p className="text-gray-400 line-clamp-3 leading-relaxed"> |
| 47 | + {article.content} |
| 48 | + </p> |
| 49 | + )} |
| 50 | + |
| 51 | + {article.createdAt && ( |
| 52 | + <p className="text-sm text-cyan-400/70 mt-4"> |
| 53 | + {new Date(article.createdAt).toLocaleDateString()} |
| 54 | + </p> |
| 55 | + )} |
| 56 | + </article> |
| 57 | + </Link> |
| 58 | + ))} |
| 59 | + </div> |
| 60 | + ) : ( |
| 61 | + <p className="text-gray-400">No articles found.</p> |
| 62 | + )} |
| 63 | + </div> |
| 64 | + </div> |
| 65 | + ) |
| 66 | +} |
0 commit comments