Skip to content

Commit

Permalink
Fix formatting and navigation in SinglePost and Write components
Browse files Browse the repository at this point in the history
  • Loading branch information
khadeshyam committed Jan 25, 2024
1 parent 55846fa commit 5988de3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion client/src/components/singlePost/SinglePost.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function SinglePost() {
setPost(res.data);
setTitle(res.data.title);
setDesc(res.data.desc);
setIsLoading(false);
setIsLoading(false);
};
getPost();
}, [path]);
Expand Down
12 changes: 8 additions & 4 deletions client/src/pages/write/Write.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,33 @@ import { useContext, useState } from "react";
import "./write.css";
import { Context } from "../../context/Context";
import API from "../../utils/axios";
import { useNavigate } from "react-router-dom";

export default function Write() {
const [title, setTitle] = useState("");
const [desc, setDesc] = useState("");
const [file, setFile] = useState(null);
const { user } = useContext(Context);
const navigate = useNavigate();

const handleSubmit = async (e) => {
e.preventDefault();
const data = new FormData();
const filename = file.name + Date.now();
const filename = file?.name + Date.now();
data.append("file", file);
data.append("name", filename);
data.append("username", user.username);
data.append("title", title);
data.append("desc", desc);
try {
const res = await API.post("/posts", data);
window.location.replace("/post/" + res.data._id);
} catch (err) {
console.log('res', res);
console.log('res', res?.data?._id);
res?.data?._id && navigate(`/post/${res?.data?._id}`);
} catch (err) {
console.log('err posting file',);
}
}; return (
}; return (
<div className="write">
{file && (
<img className="writeImg" src={URL.createObjectURL(file)} alt="" />
Expand Down

0 comments on commit 5988de3

Please sign in to comment.