From 65fac30dd355df7248399a4c0f584ac9e71d939f Mon Sep 17 00:00:00 2001 From: Team 1280 Programming Laptop <59985235+Team1280Programming@users.noreply.github.com> Date: Mon, 19 Feb 2024 13:52:53 -0800 Subject: [PATCH] feat: add topic cards to display topics on the page (#23) Co-authored-by: Team1280Programming --- src/app/topic/page.tsx | 68 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/app/topic/page.tsx diff --git a/src/app/topic/page.tsx b/src/app/topic/page.tsx new file mode 100644 index 0000000..4b7dcc7 --- /dev/null +++ b/src/app/topic/page.tsx @@ -0,0 +1,68 @@ +import { documents, topics } from '@/app/db/data' +import cardEffects from '@/app/styles/cardEffects.module.css' +import string2hex from '@/app/utils/string2hex' +import { Zilla_Slab } from 'next/font/google' +import Link from 'next/link' +import { notFound } from 'next/navigation' +import { Fragment } from 'react' + +const zillaSlab = Zilla_Slab({ subsets: ['latin'], weight: ['500'] }) + +const TopicCard = ({ params }: Readonly<{ params: { shortName: string } }>) => { + const { shortName } = params + const { name, description } = topics[shortName] + if (!name) { + notFound() + } + + return ( + +
+ + {name} + +
{description}
+
+ + ) +} + +const getNumberOfDocumentsByTopic = (topicId: string) => { + // Filter documents by author + const filteredDocuments = Object.entries(documents) + .filter(([_, doc]) => doc.manifest.topics.includes(topicId)) + .map(([slug, doc]) => ({ slug, doc })) + + return filteredDocuments.length +} + +const Page = () => { + const sortedTopics = Object.entries(topics).sort((a, b) => { + const numDocsA = getNumberOfDocumentsByTopic(a[0]) + const numDocsB = getNumberOfDocumentsByTopic(b[0]) + return numDocsB - numDocsA + }) + + return ( +
+

+ Topics +

+
+ {sortedTopics.map((entry) => { + return ( + + + + ) + })} +
+
+ ) +} + +export default Page