Skip to content

Commit

Permalink
fix(articles): update edit feature
Browse files Browse the repository at this point in the history
  • Loading branch information
HoseaCodes committed May 22, 2024
1 parent 7fb4d13 commit b0f0b3c
Show file tree
Hide file tree
Showing 3 changed files with 209 additions and 144 deletions.
6 changes: 6 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,12 @@ const App = () => {
exact={true}
element={CreateArticle}
/>
<PrivateRoute
type={"admin"}
path="/admin/blog/:id"
exact={true}
element={CreateArticle}
/>
<PrivateRoute
type={"admin"}
path="/admin/blog/edit/:id"
Expand Down
18 changes: 14 additions & 4 deletions src/Pages/Articles/CreateArticle.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ function CreatArticle() {
draft: false,
scheduled: false,
scheduledDate: todaysDate,
images: {
secure_url: "",
},
};
const state = useContext(GlobalState);
const [article, setArticle] = useState(initialState);
Expand Down Expand Up @@ -81,7 +84,7 @@ function CreatArticle() {
articles.forEach((article) => {
if (article._id === param.id) {
setArticle(article);
// setImages(article.images)
setImages(article.images)
}
});
}
Expand Down Expand Up @@ -201,6 +204,7 @@ function CreatArticle() {
setArticle({ ...article, [name]: checked });
};

console.log({ article });
return (
<>
{loggedIn ? (
Expand Down Expand Up @@ -324,7 +328,7 @@ function CreatArticle() {
</div>
</div>
</div>
<div className="col-md-6">
<div className={onEdit ? "d-none" : `col-md-6`}>
<div id="div_id_downloads" className="required">
<div className="controls d-flex flex-row align-items-center">
<label
Expand Down Expand Up @@ -409,10 +413,16 @@ function CreatArticle() {
<span onClick={handleDestory}>X</span>
</div>
)}
{onEdit && (
<div id="file_img" style={styleUpload}>
<img src={images ? images.url : ""} alt="" />
<span onClick={handleDestory}>X</span>
</div>
)}
</div>
</div>
</div>
<div className="col-md-6">
<div className={onEdit ? "d-none" : `col-md-6`}>
<div id="div_id_downloads" className="required">
<div className="controls d-flex flex-column ">
<label
Expand Down Expand Up @@ -446,7 +456,7 @@ function CreatArticle() {
</div>
</div>
</div>
<div className="col-md-6">
<div className={onEdit ? "d-none" : `col-md-6`}>
<div
id="div_id_downloads"
className="form-group required"
Expand Down
Loading

0 comments on commit b0f0b3c

Please sign in to comment.