diff --git a/client/package-lock.json b/client/package-lock.json index 0246cf8..65e9880 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -2045,7 +2045,6 @@ }, "node_modules/@types/react-dom": { "version": "18.3.1", - "dev": true, "license": "MIT", "dependencies": { "@types/react": "*" diff --git a/client/src/App.jsx b/client/src/App.jsx index 5a69abf..2a0844e 100644 --- a/client/src/App.jsx +++ b/client/src/App.jsx @@ -38,6 +38,7 @@ import "aos/dist/aos.css"; import Collab from "./component/Collab"; import CreateBlog from "./component/CreateBlog"; import UploadProject from "./component/UploadProject"; +import DiscussionForum from "./component/DiscussionForum"; const Layout = ({ children, mode, setProgress, toggleMode, showAlert }) => { return ( @@ -146,6 +147,7 @@ function App() { } /> } /> } /> + } /> } /> diff --git a/client/src/component/DiscussionForum.jsx b/client/src/component/DiscussionForum.jsx new file mode 100644 index 0000000..3da0732 --- /dev/null +++ b/client/src/component/DiscussionForum.jsx @@ -0,0 +1,156 @@ +import { useState, useEffect } from 'react'; + +const DiscussionForum = (props) => { + const [questions, setQuestions] = useState([]); + + // Fetch questions from localStorage + useEffect(() => { + const storedQuestions = localStorage.getItem('questions'); + if (storedQuestions) { + setQuestions(JSON.parse(storedQuestions)); + } + }, []); + + // Save questions to localStorage + const saveQuestions = (updatedQuestions) => { + setQuestions(updatedQuestions); + localStorage.setItem('questions', JSON.stringify(updatedQuestions)); + }; + + // Helper function to save a new question + const addQuestion = (content) => { + const newQuestion = { + id: Date.now().toString(), + content, + answered: false, + answer: '', + }; + + const updatedQuestions = [...questions, newQuestion]; + saveQuestions(updatedQuestions); + }; + + // Helper function to add an answer to a question + const addAnswer = (questionId, answerContent) => { + const updatedQuestions = questions.map((question) => + question.id === questionId + ? { ...question, answered: true, answer: answerContent } + : question + ); + saveQuestions(updatedQuestions); + }; + + // Function to render the Question Card + const renderQuestionCard = (question) => { + return ( +
+

{question.content}

+ {question.answered ? ( +
+

Answer:

+

{question.answer}

+
+ ) : ( + + )} +
+ ); + }; + + // Function to render the Answer Form + const AnswerForm = ({ questionId }) => { + const [answer, setAnswer] = useState(''); + + const handleSubmit = (e) => { + e.preventDefault(); + if (answer.trim()) { + addAnswer(questionId, answer); + setAnswer(''); + } + }; + + return ( +
+