Skip to content

Commit

Permalink
fix bug related to sharing the post as image
Browse files Browse the repository at this point in the history
  • Loading branch information
sharunkumar committed Oct 5, 2024
1 parent e0230b2 commit a273f68
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/features/share/asImage/ShareAsImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,12 @@ export default function ShareAsImage({ data, header }: ShareAsImageProps) {
setShareAsImagePreferences,
} = useShareAsImagePreferences();

const isComment = "comment" in data;

// eslint-disable-next-line no-nested-ternary
const defaultMinDepth = allParentComments
? 0
: "comment" in data
: isComment
? getDepthFromComment(data.comment.comment)
: 0;

Expand All @@ -156,7 +158,7 @@ export default function ShareAsImage({ data, header }: ShareAsImageProps) {
}, [blob]);

const filteredComments = useMemo(() => {
if (!("comment" in data)) return [];
if (!isComment) return [];

const filtered = data.comments
.filter(
Expand Down Expand Up @@ -251,8 +253,7 @@ export default function ShareAsImage({ data, header }: ShareAsImageProps) {
async function onShare() {
if (!blob) return;

const apId =
"comment" in data ? data.comment.comment.ap_id : data.post.post.ap_id;
const apId = isComment ? data.comment.comment.ap_id : data.post.post.ap_id;

const filename = `${apId
.replace(/^https:\/\//, "")
Expand Down Expand Up @@ -312,7 +313,7 @@ export default function ShareAsImage({ data, header }: ShareAsImageProps) {
)}

<StyledIonList inset lines="full">
{"comment" in data && (
{isComment && (
<>
<IonItem>
<IonToggle
Expand All @@ -326,7 +327,7 @@ export default function ShareAsImage({ data, header }: ShareAsImageProps) {
Include Post Details
</IonToggle>
</IonItem>
{includePostDetails && hasPostBody ? (
{(isComment ? includePostDetails : true) && hasPostBody ? (
<IonItem>
<IonToggle
checked={includePostContent}
Expand Down Expand Up @@ -426,16 +427,16 @@ export default function ShareAsImage({ data, header }: ShareAsImageProps) {
<ShareImageContext.Provider
value={{ capturing: true, hideUsernames, hideCommunity }}
>
{includePostDetails && (
{(isComment ? includePostDetails : true) && (
<PostHeader
className={!("comment" in data) ? hideBottomBorderCss : ""}
className={!isComment ? hideBottomBorderCss : ""}
post={data.post}
showPostText={includePostContent}
showPostText={isComment ? includePostContent : true}
showPostActions={false}
constrainHeight={false}
/>
)}
{"comment" in data && (
{isComment && (
<>
{includePostDetails && <PostCommentSpacer />}
<CommentTree
Expand Down

0 comments on commit a273f68

Please sign in to comment.