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} +

+
View Entry diff --git a/src/components/ForceFromEntry.tsx b/src/components/ForceFromEntry.tsx index 6fc14e8..454c9de 100644 --- a/src/components/ForceFromEntry.tsx +++ b/src/components/ForceFromEntry.tsx @@ -48,6 +48,9 @@ const ForceFromEntry = ({ neighbor.image = JSON.parse(neighbor.metadata).author; } } + if (JSON.parse(neighbor.metadata).title) { + neighbor.title = JSON.parse(neighbor.metadata).title; + } neighbors.push(neighbor); } } @@ -87,6 +90,9 @@ const ForceFromEntry = ({ penPal.image = JSON.parse(penPal.metadata).author; } } + if (JSON.parse(penPal.metadata).title) { + penPal.title = JSON.parse(penPal.metadata).title; + } penPals.push(penPal); } } @@ -132,6 +138,9 @@ const ForceFromEntry = ({ 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/SimpleDashboard.tsx b/src/components/SimpleDashboard.tsx index b1b8e0d..f6ae62c 100644 --- a/src/components/SimpleDashboard.tsx +++ b/src/components/SimpleDashboard.tsx @@ -8,6 +8,7 @@ import { fetchByID, fetchRandomEntry } from '@/helpers/functions'; import ForceFromEntry from './ForceFromEntry'; import SearchModalBeta from './SearchModalBeta'; +import Link from 'next/link'; const SimpleDashboard = () => { const router = useRouter(); @@ -21,6 +22,8 @@ const SimpleDashboard = () => { }); const [isSearchModalBetaOpen, setSearchModalBetaOpen] = useState(false); const [searchBetaModalQuery, setSearchBetaModalQuery] = useState(''); + const [logEntries, setLogEntries] = useState([]); + const [isSaving, setIsSaving] = useState(false); // const [inboxEntries, setInboxEntries] = useState([]); const { user, isLoaded } = useUser(); @@ -148,6 +151,56 @@ const SimpleDashboard = () => { fetchEntry(); }, []); + // get log entries + const fetchLogEntries = async () => { + try { + const response = await fetch('/api/log', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + page: 1, + limit: 10, + sortModel: [{ colId: 'createdAt', sort: 'desc' }], + }), + }); + const data = await response.json(); + console.log('Log entries:', data); + // if createdAt == updatedAt, say "added", else "updated" + const log = data.data.map((entry: any) => { + // skip entries with parent_id + let metadata; + try { + metadata = JSON.parse(entry.metadata); + } catch (err) { + console.error('Error parsing metadata:', err); + } + if (metadata.parent_id) { + return null; + } + if (entry.createdAt === entry.updatedAt) { + return { + ...entry, + action: 'added', + }; + } + return { + ...entry, + action: 'updated', + }; + }).filter((entry: any) => entry !== null); + console.log('Log:', log); + setLogEntries(log); + } catch (error) { + console.error('Error fetching log entries:', error); + } + }; + + useEffect(() => { + fetchLogEntries(); + }, []); + const closeModal = () => setSearchModalBetaOpen(false); return ( @@ -207,7 +260,6 @@ const SimpleDashboard = () => { closeModalFn={() => closeModal()} inputQuery={searchBetaModalQuery} /> - {randomEntry && ( <> )} + + {/* ask the user what they are thinking about right now in a text box and add it as an entry -- like a journal */} +

+ Journal +

+
+