diff --git a/src/app/[locale]/(auth)/api/log/route.ts b/src/app/[locale]/(auth)/api/log/route.ts new file mode 100644 index 0000000..830758c --- /dev/null +++ b/src/app/[locale]/(auth)/api/log/route.ts @@ -0,0 +1,46 @@ +import { NextResponse } from 'next/server'; + +import { logger } from '@/libs/Logger'; + +import { GET } from '../getCBPath/route'; + +// import env variables + +export const POST = async (request: Request) => { + const { page, limit, sortModel } = await request.json(); + const { CLOUD_URL } = process.env; + + const dbRes = await GET(request); + if (!dbRes) { + return NextResponse.json({}, { status: 500 }); + } + const { DATABASE_URL, API_KEY } = await dbRes.json(); + + const resp = await fetch(`${CLOUD_URL}/log`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + page, + limit, + sortModel, + dbPath: DATABASE_URL, + apiKey: API_KEY, + }), + }); + logger.info('resp:', resp); + const data = await resp.json(); + + try { + logger.info(`A new log has been created ${JSON.stringify(data)}`); + + return NextResponse.json({ + data, + }); + } catch (error) { + logger.error(error, 'An error occurred while creating a log'); + + return NextResponse.json({}, { status: 500 }); + } +}; diff --git a/src/components/EntryPage.tsx b/src/components/EntryPage.tsx index db70229..7fc697e 100644 --- a/src/components/EntryPage.tsx +++ b/src/components/EntryPage.tsx @@ -876,7 +876,6 @@ const EntryPage = () => { ); neighbor.parent = parent; } - console.log('pushing neighbor:', neighbor.id); // if metadata.author includes imagedelivery.net, add it to the thumbnails array if (JSON.parse(neighbor.metadata).author) { if ( @@ -885,6 +884,9 @@ const EntryPage = () => { neighbor.image = JSON.parse(neighbor.metadata).author; } } + if (JSON.parse(neighbor.metadata).title) { + neighbor.title = JSON.parse(neighbor.metadata).title; + } neighbors.push(neighbor); } } @@ -929,7 +931,9 @@ const EntryPage = () => { penPal.image = JSON.parse(penPal.metadata).author; } } - console.log('pushing penPal:', penPal.id); + if (JSON.parse(penPal.metadata).title) { + penPal.title = JSON.parse(penPal.metadata).title; + } penPals.push(penPal); } } @@ -970,7 +974,6 @@ const EntryPage = () => { ); internalLink.parent = parent; } - console.log('pushing internalLink:', internalLink.id); if (JSON.parse(internalLink.metadata).author) { if ( JSON.parse(internalLink.metadata).author.includes( @@ -980,6 +983,9 @@ const EntryPage = () => { internalLink.image = JSON.parse(internalLink.metadata).author; } } + if (JSON.parse(internalLink.metadata).title) { + internalLink.title = JSON.parse(internalLink.metadata).title; + } internalLinks.push(internalLink); } } diff --git a/src/components/ForceDirectedGraph.tsx b/src/components/ForceDirectedGraph.tsx index 7a125e8..d42757b 100644 --- a/src/components/ForceDirectedGraph.tsx +++ b/src/components/ForceDirectedGraph.tsx @@ -14,11 +14,13 @@ const ForceDirectedGraph = ({ data }: any) => { content: '', id: '', image: '', + title: '', }); const [showModal, setShowModal] = useState(false); - const openModal = (content: any, id: any, image: any) => { - setModalContent({ content, id, image }); + const openModal = (content: any, id: any, image: any, title: any) => { + console.log('title:', title); + setModalContent({ content, id, image, title }); setShowModal(true); }; @@ -63,6 +65,7 @@ const ForceDirectedGraph = ({ data }: any) => { group: 'neighbor', similarity: n.similarity, image: n.image, + title: n.title, })), // Add internal links as nodes with 'internalLink' group ...data.internalLinks.map((link: any, idx: any) => ({ @@ -70,6 +73,7 @@ const ForceDirectedGraph = ({ data }: any) => { label: link.internalLink, group: 'internalLink', image: link.image, + title: link.title, })), ...data.internalLinks.flatMap((link: any) => link.penPals.map((penPal: any) => ({ @@ -78,6 +82,7 @@ const ForceDirectedGraph = ({ data }: any) => { group: 'penPal', similarity: penPal.similarity, image: penPal.image, + title: penPal.title, })), ), ...data.comments.map((comment: any, idx: any) => ({ @@ -85,6 +90,7 @@ const ForceDirectedGraph = ({ data }: any) => { label: comment.comment, group: 'comment', image: comment.image, + title: comment.title, })), ...data.comments.flatMap((comment: any) => comment.penPals.map((penPal: any) => ({ @@ -93,6 +99,7 @@ const ForceDirectedGraph = ({ data }: any) => { group: 'penPal', similarity: penPal.similarity, image: penPal.image, + title: penPal.title, })), ), // Add parents of neighbors and penpals @@ -240,7 +247,7 @@ const ForceDirectedGraph = ({ data }: any) => { if (d.group === 'internalLink') return 'brown'; // Internal links as brown nodes return 'gray'; }) - .on('click', (_, d) => openModal(d.label, d.id, d.image)) + .on('click', (_, d) => openModal(d.label, d.id, d.image, d.title)) .call(drag(simulation) as any); const labels = g @@ -302,6 +309,10 @@ const ForceDirectedGraph = ({ data }: any) => {
{modalContent.content}
)}+ {modalContent.title} +
+