Skip to content

Commit

Permalink
fix: Update post removes photos or videos (#1111)
Browse files Browse the repository at this point in the history
* Fixed update post photo and video bug

* Fixed removing of posts by user

* Handled all cases of updating of posts in photos and videos
  • Loading branch information
pateldivyesh1323 authored Dec 6, 2023
1 parent 441ab0e commit 2c972fd
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions src/components/OrgPostCard/OrgPostCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export default function OrgPostCard(
postvideo: '',
pinned: false,
});

const [postPhotoUpdated, setPostPhotoUpdated] = useState(false);
const [postVideoUpdated, setPostVideoUpdated] = useState(false);
const [togglePost, setPostToggle] = useState('Read more');
const [showEditModal, setShowEditModal] = useState(false);
const [showDeleteModal, setShowDeleteModal] = useState(false);
Expand Down Expand Up @@ -80,6 +81,8 @@ export default function OrgPostCard(
postvideo: props.postVideo,
pinned: props.pinned,
});
setPostPhotoUpdated(false);
setPostVideoUpdated(false);
setShowEditModal((prev) => !prev);
};
const toggleShowDeleteModal = (): void => setShowDeleteModal((prev) => !prev);
Expand All @@ -105,6 +108,7 @@ export default function OrgPostCard(
...postformState,
postphoto: '',
});
setPostPhotoUpdated(true);
const fileInput = document.getElementById(
'postImageUrl'
) as HTMLInputElement;
Expand All @@ -118,6 +122,7 @@ export default function OrgPostCard(
...postformState,
postvideo: '',
});
setPostVideoUpdated(true);
const fileInput = document.getElementById(
'postVideoUrl'
) as HTMLInputElement;
Expand Down Expand Up @@ -201,24 +206,17 @@ export default function OrgPostCard(
e.preventDefault();

try {
let imageUrl = null;
let videoUrl = null;

if (e.target?.postphoto && e.target?.postphoto.files.length > 0) {
imageUrl = postformState.postphoto;
}

if (e.target?.postvideo && e.target?.postvideo.files.length > 0) {
videoUrl = postformState.postvideo;
}

const { data } = await updatePostMutation({
variables: {
id: props.id,
title: postformState.posttitle,
text: postformState.postinfo,
imageUrl,
videoUrl,
...(postPhotoUpdated && {
imageUrl: postformState.postphoto,
}),
...(postVideoUpdated && {
videoUrl: postformState.postvideo,
}),
},
});

Expand Down Expand Up @@ -531,7 +529,7 @@ export default function OrgPostCard(
...prevPostFormState,
postphoto: '',
}));

setPostPhotoUpdated(true);
const file = e.target.files?.[0];
if (file) {
setPostFormState({
Expand Down Expand Up @@ -580,6 +578,7 @@ export default function OrgPostCard(
...prevPostFormState,
postvideo: '',
}));
setPostVideoUpdated(true);
const target = e.target as HTMLInputElement;
const file = target.files && target.files[0];
if (file) {
Expand Down

0 comments on commit 2c972fd

Please sign in to comment.