MCPcopy Create free account
hub / github.com/Bitbox-Connect/Bitbox / addAnswer

Function addAnswer

client/src/component/DiscussionForum.jsx:59–82  ·  view source on GitHub ↗
(questionId, answerContent)

Source from the content-addressed store, hash-verified

57
58 // Helper function to add an answer to a question
59 const addAnswer = async (questionId, answerContent) => {
60 try {
61 const response = await fetch(`${VITE_SERVER_PORT}/api/discussion/${questionId}/answer`, {
62 method: 'PUT',
63 headers: {
64 'Content-Type': 'application/json',
65 },
66 body: JSON.stringify({ answer: answerContent }),
67 });
68
69 if (response.ok) {
70 const updatedQuestion = await response.json();
71 setQuestions((prevQuestions) =>
72 prevQuestions.map((question) =>
73 question._id === questionId ? { ...question, ...updatedQuestion } : question
74 )
75 );
76 } else {
77 console.error('Failed to add answer');
78 }
79 } catch (error) {
80 console.error('Error adding answer:', error);
81 }
82 };
83
84 // Function to render the Question Card
85 const renderQuestionCard = (question, props) => {

Callers 1

handleSubmitFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected