Skip to content

Commit

Permalink
fix: be able to delete image
Browse files Browse the repository at this point in the history
  • Loading branch information
Sembauke committed Nov 22, 2023
1 parent 1f3ef54 commit a67cafe
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
3 changes: 3 additions & 0 deletions apps/frontend/src/components/editor-drawer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ const EditorDrawer = ({
const handleFileInputChange = async (event) => {
const file = event.target.files[0];

if (!file) return;

const apiBase = process.env.NEXT_PUBLIC_STRAPI_BACKEND_URL;

const formData = new FormData();
Expand All @@ -99,6 +101,7 @@ const EditorDrawer = ({

if (response.status === 200) {
const data = await response.json();

handleFeatureImageChange(new URL(data[0].url, apiBase), data[0].id);
}
};
Expand Down
24 changes: 19 additions & 5 deletions apps/frontend/src/components/post-form.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const PostForm = ({ tags, user, authors, post }) => {

useEffect(() => {
if (post) {
const apiBase = process.env.NEXT_PUBLIC_STRAPI_BACKEND_URL;
const { title, body, slug, tags, feature_image } = post.attributes;
const tagIds = tags.data.map((tag) => tag.id);

Expand All @@ -56,9 +57,12 @@ const PostForm = ({ tags, user, authors, post }) => {
setPostId(post.id);
setPostTagId(tagIds);

setFeatureImageUrl(feature_image);

console.log(post.attributes);
if (feature_image.data) {
setFeatureImageUrl(
new URL(feature_image.data[0].attributes.url, apiBase),
);
setFeatureImageId(feature_image.data[0].id);
}
}
}, [post]);

Expand Down Expand Up @@ -100,7 +104,7 @@ const PostForm = ({ tags, user, authors, post }) => {
const data = {
data: {
title: title,
feature_image: [featureImageId],
feature_image: featureImageId !== null ? [featureImageId] : [],
slug: slugify(
postUrl != "" ? postUrl : title != "(UNTITLED)" ? title : nonce,
{
Expand Down Expand Up @@ -176,7 +180,17 @@ const PostForm = ({ tags, user, authors, post }) => {
});
}
},
[toast, title, postUrl, postTagId, content, author, postId, user],
[
toast,
title,
postUrl,
postTagId,
featureImageId,
content,
author,
postId,
user,
],
);

useEffect(() => {
Expand Down

0 comments on commit a67cafe

Please sign in to comment.