Skip to content

Commit

Permalink
Handled all cases of updating of posts in photos and videos
Browse files Browse the repository at this point in the history
  • Loading branch information
pateldivyesh1323 committed Dec 5, 2023
1 parent 557d64a commit 392f38a
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 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,15 @@ export default function OrgPostCard(
e.preventDefault();

try {
const imageInput = document.getElementById(
'postImageUrl'
) as HTMLInputElement;
const videoInput = document.getElementById(
'postVideoUrl'
) as HTMLInputElement;

const { data } = await updatePostMutation({
variables: {
id: props.id,
title: postformState.posttitle,
text: postformState.postinfo,
...((postformState.postphoto !== null ||
(imageInput && imageInput.value === '')) && {
...(postPhotoUpdated && {
imageUrl: postformState.postphoto,
}),
...((postformState.postvideo !== null ||
(videoInput && videoInput.value === '')) && {
...(postVideoUpdated && {
videoUrl: postformState.postvideo,
}),
},
Expand Down Expand Up @@ -533,7 +529,7 @@ export default function OrgPostCard(
...prevPostFormState,
postphoto: '',
}));

setPostPhotoUpdated(true);
const file = e.target.files?.[0];
if (file) {
setPostFormState({
Expand Down Expand Up @@ -582,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 392f38a

Please sign in to comment.