-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
95 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { t } from '@lingui/core/macro'; | ||
import { Select, Trans } from '@lingui/react/macro'; | ||
import { type HTMLProps, memo, useCallback, useEffect, useState } from 'react'; | ||
|
||
import { ClickableButton } from '@/components/ClickableButton.js'; | ||
import { NakedMarkup } from '@/components/Markup/NakedMarkup.js'; | ||
import { IS_APPLE, IS_SAFARI } from '@/constants/bowser.js'; | ||
import { classNames } from '@/helpers/classNames.js'; | ||
import { formatUrl } from '@/helpers/formatUrl.js'; | ||
import { isValidUrl } from '@/helpers/isValidUrl.js'; | ||
import { useDetectOverflow } from '@/hooks/useDetectOverflow.js'; | ||
import type { Post } from '@/providers/types/SocialMedia.js'; | ||
import { useComposeStateStore } from '@/store/useComposeStore.js'; | ||
|
||
interface PostBodyReplyContentProps { | ||
post: Post; | ||
} | ||
|
||
const overrideComponents = { | ||
a: function Anchor({ title }: HTMLProps<HTMLAnchorElement>) { | ||
return <span>{title && isValidUrl(title) ? formatUrl(title, 30) : title}</span>; | ||
}, | ||
}; | ||
|
||
export const PostBodyReplyContent = memo<PostBodyReplyContentProps>(function PostBodyReplyContent({ post }) { | ||
const liteRawContent = post.metadata.content?.content; | ||
const [overflow, ref] = useDetectOverflow<HTMLDivElement>(); | ||
const [multiple, setMultiple] = useState(1); | ||
const { focused } = useComposeStateStore(); | ||
|
||
const toggleShowMore = useCallback(() => { | ||
setMultiple((prev) => (overflow ? prev + 1 : Math.max(1, prev - 1))); | ||
}, [overflow]); | ||
|
||
useEffect(() => { | ||
if (focused) { | ||
setMultiple(1); | ||
} | ||
}, [focused]); | ||
|
||
return ( | ||
<div> | ||
<div | ||
ref={ref} | ||
className={classNames('single-post line-clamp-3 w-full self-stretch break-words text-base text-main', { | ||
'max-h-[7.8rem]': IS_SAFARI && IS_APPLE, | ||
})} | ||
style={{ WebkitLineClamp: multiple * 3 }} | ||
> | ||
<NakedMarkup post={post} components={overrideComponents}> | ||
{liteRawContent} | ||
</NakedMarkup> | ||
</div> | ||
<div className="flex flex-col text-base text-main"> | ||
{overflow || multiple > 1 ? ( | ||
<ClickableButton className="inline-flex text-highlight" onClick={toggleShowMore}> | ||
{overflow ? <Trans>Show more</Trans> : <Trans>Show less</Trans>} | ||
</ClickableButton> | ||
) : null} | ||
{post.metadata.content?.asset?.type ? ( | ||
<Select | ||
value={post.metadata.content.asset.type} | ||
_Image="[Image]" | ||
_Video="[Video]" | ||
_Audio="[Audio]" | ||
_Poll="[Poll]" | ||
other="" | ||
/> | ||
) : null} | ||
{post.quoteOn ? <span>{t`[Quote]`}</span> : null} | ||
</div> | ||
</div> | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters