diff --git a/web/src/components/forums/CreateDialog/CreateDialog.jsx b/web/src/components/forums/CreateDialog/CreateDialog.jsx
index 1eecf80d..40359f1d 100644
--- a/web/src/components/forums/CreateDialog/CreateDialog.jsx
+++ b/web/src/components/forums/CreateDialog/CreateDialog.jsx
@@ -11,10 +11,9 @@ export const useStyles = makeStyles((theme) => ({
export default function CreateDialog({
mode = 'post',
open = false,
- title = '',
- content = null,
setOpen,
handleCreatePost,
+ ...rest
}) {
// MUI theme-based css styles
const classes = useStyles();
@@ -26,10 +25,9 @@ export default function CreateDialog({
>
);
diff --git a/web/src/components/forums/Post/Post.jsx b/web/src/components/forums/Post/Post.jsx
index 54087a56..e25c1fea 100644
--- a/web/src/components/forums/Post/Post.jsx
+++ b/web/src/components/forums/Post/Post.jsx
@@ -33,11 +33,15 @@ export default function Post({
const classes = useStyles();
const [commentPressed, setCommentPressed] = React.useState(false);
const [isDialogOpen, setIsDialogOpen] = React.useState(false);
- // console.log({user});
- const closePublisher = () => {
+ const closePublisher = React.useCallback(() => {
setCommentPressed(false);
- };
+ }, []);
+
+ const handleEdit = React.useCallback((post) => {
+ setIsDialogOpen(false);
+ handleEditPost(post);
+ }, [handleEditPost]);
return (
@@ -47,9 +51,11 @@ export default function Post({
diff --git a/web/src/components/forums/Publisher/Publisher.jsx b/web/src/components/forums/Publisher/Publisher.jsx
index 9c07f160..a1c54b46 100644
--- a/web/src/components/forums/Publisher/Publisher.jsx
+++ b/web/src/components/forums/Publisher/Publisher.jsx
@@ -7,19 +7,21 @@ import {useSnackbar} from 'notistack';
export default function Publisher({
mode = 'post',
- initalTitle = '',
- initialContent = null,
setOpen,
onClose,
handlePublish,
+ initalTitle = '',
+ initialContent = null,
+ visibleToStudents = true,
+ anonymous = false,
}) {
// MUI theme-based css styles
const classes = useStyles();
// Form Data
const [title, setTitle] = useState(initalTitle);
const [content, setContent] = useState(initialContent ? initialContent : {});
- const [isVisibleToStudents, setIsVisisbleToStudents] = useState(true);
- const [isAnonymous, setIsAnonymous] = useState(false);
+ const [isVisibleToStudents, setIsVisisbleToStudents] = useState(visibleToStudents);
+ const [isAnonymous, setIsAnonymous] = useState(anonymous);
const {enqueueSnackbar} = useSnackbar();
const isPost = mode === 'post';
diff --git a/web/src/pages/core/public/Forum/Forum.jsx b/web/src/pages/core/public/Forum/Forum.jsx
index 572f7098..c5afb6e2 100644
--- a/web/src/pages/core/public/Forum/Forum.jsx
+++ b/web/src/pages/core/public/Forum/Forum.jsx
@@ -116,22 +116,30 @@ export default function Forum() {
}).catch(standardErrorHandler(enqueueSnackbar));
};
- const handleCourseSelect = (e) => {
+ const handleCourseSelect = React.useCallback((e) => {
console.log(e.target.value);
setSelectedCourse(e.target.value);
- };
+ }, []);
- const handleCreatePost = (post) => {
- // console.log(post);
+ const handleCreatePost = React.useCallback((post) => {
axios.post(`/api/public/forum/post`, {...post, course_id: selectedCourse.id})
.then(() => {
refreshPosts();
setIsDialogOpen(false);
})
.catch(standardErrorHandler(enqueueSnackbar));
- };
+ }, [selectedCourse]);
+
+ const handleEditPost = React.useCallback((post) => {
+ axios.patch(`/api/public/forum/post/${selectedPost.id}`, {...post})
+ .then(() => {
+ refreshPosts();
+ setIsDialogOpen(false);
+ })
+ .catch(standardErrorHandler(enqueueSnackbar));
+ }, [selectedPost]);
- const handleCreateComment = (comment) => {
+ const handleCreateComment = React.useCallback((comment) => {
const {parent_id = null} = comment;
const endpoint = (
parent_id ?
@@ -147,7 +155,7 @@ export default function Forum() {
refreshSelectedPost();
})
.catch(standardErrorHandler(enqueueSnackbar));
- };
+ }, []);
return (
@@ -257,7 +265,7 @@ export default function Forum() {
updatedDate={selectedPost.last_updated}
comments={selectedPost.comments}
handleCreateComment={handleCreateComment}
- handleEditPost={handleCreatePost}
+ handleEditPost={handleEditPost}
/>
)}