From 5e01bb8cff74c1c97a2db8903527b1bea0e509ad Mon Sep 17 00:00:00 2001 From: jackiettran <41605212+jackiettran@users.noreply.github.com> Date: Sat, 13 Dec 2025 20:32:25 -0500 Subject: [PATCH] images for forum and forum comments --- backend/routes/forum.js | 16 +- frontend/src/App.tsx | 8 + frontend/src/components/CommentForm.tsx | 19 +- frontend/src/components/CommentThread.tsx | 93 ++++++++-- frontend/src/pages/CreateForumPost.tsx | 213 ++++++++++++++++------ frontend/src/pages/ForumPostDetail.tsx | 34 +++- frontend/src/types/index.ts | 3 + 7 files changed, 294 insertions(+), 92 deletions(-) diff --git a/backend/routes/forum.js b/backend/routes/forum.js index ee078cc..4f376a2 100644 --- a/backend/routes/forum.js +++ b/backend/routes/forum.js @@ -1111,7 +1111,7 @@ router.post('/posts/:id/comments', authenticateToken, async (req, res, next) => // PUT /api/forum/comments/:id - Edit comment router.put('/comments/:id', authenticateToken, async (req, res, next) => { try { - const { content } = req.body; + const { content, imageFilenames: rawImageFilenames } = req.body; const comment = await ForumComment.findByPk(req.params.id); if (!comment) { @@ -1126,7 +1126,19 @@ router.put('/comments/:id', authenticateToken, async (req, res, next) => { return res.status(400).json({ error: 'Cannot edit deleted comment' }); } - await comment.update({ content }); + const updateData = { content }; + + // Handle image filenames if provided + if (rawImageFilenames !== undefined) { + const imageFilenamesArray = Array.isArray(rawImageFilenames) ? rawImageFilenames : []; + const keyValidation = validateS3Keys(imageFilenamesArray, 'forum', { maxKeys: IMAGE_LIMITS.forum }); + if (!keyValidation.valid) { + return res.status(400).json({ error: keyValidation.error }); + } + updateData.imageFilenames = imageFilenamesArray; + } + + await comment.update(updateData); const updatedComment = await ForumComment.findByPk(comment.id, { include: [ diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 8eaf995..8a48d4d 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -159,6 +159,14 @@ const AppContent: React.FC = () => { } /> + + + + } + /> Promise; @@ -24,7 +25,7 @@ const CommentForm: React.FC = ({ const handleImageChange = (e: React.ChangeEvent) => { const files = Array.from(e.target.files || []); - const remainingSlots = 3 - imageFiles.length; + const remainingSlots = IMAGE_LIMITS.forum - imageFiles.length; const filesToAdd = files.slice(0, remainingSlots); setImageFiles((prev) => [...prev, ...filesToAdd]); @@ -81,15 +82,13 @@ const CommentForm: React.FC = ({ /> {error &&
{error}
} - {!isReply && ( - - )} +
@@ -222,8 +283,8 @@ const CommentThread: React.FC = ({ className="img-fluid rounded" style={{ width: "100%", - height: "100px", - objectFit: "cover", + maxHeight: "300px", + objectFit: "contain", cursor: "pointer", }} onClick={() => @@ -267,7 +328,7 @@ const CommentThread: React.FC = ({ {isAuthor && onEdit && !isEditing && (