Skip to content

Commit

Permalink
FIX routes used for editing
Browse files Browse the repository at this point in the history
  • Loading branch information
dolf321 committed Aug 23, 2023
1 parent e1c7478 commit 8693f81
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 22 deletions.
6 changes: 2 additions & 4 deletions web/src/components/forums/CreateDialog/CreateDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -26,10 +25,9 @@ export default function CreateDialog({
>
<Publisher
mode={mode}
initalTitle={title}
initialContent={content}
setOpen={setOpen}
handlePublish={handleCreatePost}
{...rest}
/>
</Dialog>
);
Expand Down
18 changes: 12 additions & 6 deletions web/src/components/forums/Post/Post.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Box className={classes.root} key={id}>
Expand All @@ -47,9 +51,11 @@ export default function Post({
<CreateDialog
open={isDialogOpen}
setOpen={setIsDialogOpen}
title={title}
content={content}
handleCreatePost={handleEditPost}
initalTitle={title}
initialContent={content}
visibleToStudents={true}
anonymous={false}
handleCreatePost={handleEdit}
/>
<Box className={classes.postInfoContainer}>
<Box className={classes.profilePic}>
Expand Down
10 changes: 6 additions & 4 deletions web/src/components/forums/Publisher/Publisher.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
24 changes: 16 additions & 8 deletions web/src/pages/core/public/Forum/Forum.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?
Expand All @@ -147,7 +155,7 @@ export default function Forum() {
refreshSelectedPost();
})
.catch(standardErrorHandler(enqueueSnackbar));
};
}, []);

return (
<StandardLayout>
Expand Down Expand Up @@ -257,7 +265,7 @@ export default function Forum() {
updatedDate={selectedPost.last_updated}
comments={selectedPost.comments}
handleCreateComment={handleCreateComment}
handleEditPost={handleCreatePost}
handleEditPost={handleEditPost}
/>
)}
</Grid>
Expand Down

0 comments on commit 8693f81

Please sign in to comment.