diff --git a/components/chatbot/RelatedContent.js b/components/chatbot/RelatedContent.js index 193f1c1a..a3cc6bf3 100644 --- a/components/chatbot/RelatedContent.js +++ b/components/chatbot/RelatedContent.js @@ -1,7 +1,8 @@ -import React, { useState } from 'react'; -import Divider from '@mui/material/Divider'; -import Typography from '@mui/material/Typography'; -import LikeActions from './LikeActions'; +import React, { useState, useEffect } from 'react'; +import Divider from "@mui/material/Divider"; +import Typography from "@mui/material/Typography"; +import LikeActions from "./LikeActions"; +import { useMDX } from "@/lib/content/mdx"; export default function RelatedContent({ relevantDocs, selectedBotMessageId }) { // Define state to hold thumb up and thumb down status for each document @@ -9,38 +10,47 @@ export default function RelatedContent({ relevantDocs, selectedBotMessageId }) { // Function to update thumb up and thumb down status for a specific document const handleLikeActions = (docId, actionType) => { - setThumbState(prevState => { - const currentThumbState = prevState[docId] || { thumbUp: false, thumbDown: false }; + setThumbState((prevState) => { + const currentThumbState = prevState[docId] || { + thumbUp: false, + thumbDown: false, + }; let updatedState; - + // Toggle logic - if (actionType === 'thumbUp') { + if (actionType === "thumbUp") { updatedState = { ...prevState, [docId]: { ...currentThumbState, thumbUp: !currentThumbState.thumbUp, - thumbDown: currentThumbState.thumbUp ? currentThumbState.thumbDown : false, + thumbDown: currentThumbState.thumbUp + ? currentThumbState.thumbDown + : false, }, }; - } else if (actionType === 'thumbDown') { + } else if (actionType === "thumbDown") { updatedState = { ...prevState, [docId]: { ...currentThumbState, - thumbUp: currentThumbState.thumbDown ? currentThumbState.thumbUp : false, + thumbUp: currentThumbState.thumbDown + ? currentThumbState.thumbUp + : false, thumbDown: !currentThumbState.thumbDown, }, }; } - + return updatedState; }); }; - + // Filter relevantDocs based on selectedBotMessageId - const filteredDocs = relevantDocs.filter((doc) => doc.messageId === selectedBotMessageId); - console.log('filteredDocs:', filteredDocs); + const filteredDocs = relevantDocs.filter( + (doc) => doc.messageId === selectedBotMessageId + ); + console.log("filteredDocs:", filteredDocs); return (

Related Documents

@@ -48,18 +58,24 @@ export default function RelatedContent({ relevantDocs, selectedBotMessageId }) { filteredDocs.map((doc, index) => (

{doc.metadata.title}

-

{doc.pageContent}

+ {doc.pageContent}

- Source:{' '} - + Source:{" "} + {doc.metadata.url}

handleLikeActions(doc.docId, 'thumbUp')} - handleThumbDownClick={() => handleLikeActions(doc.docId, 'thumbDown')} + handleThumbUpClick={() => handleLikeActions(doc.docId, "thumbUp")} + handleThumbDownClick={() => + handleLikeActions(doc.docId, "thumbDown") + } /> {index < filteredDocs.length - 1 && }
@@ -71,4 +87,26 @@ export default function RelatedContent({ relevantDocs, selectedBotMessageId }) { )}
); -} \ No newline at end of file +} + +function MDXContent({ children }) { + const [pageContent, setPageContent] = useState({ + content: undefined, + frontmatter: undefined, + }); + + useEffect(() => { + // process the rawcontent + if (children) { + const { mdxContent, frontmatter } = useMDX(children, "mdx"); + if (mdxContent && frontmatter) { + setPageContent({ content: mdxContent, frontmatter: frontmatter }); + } + } + }, [children]); + + const Content = pageContent.content; + + + return
; +}