feat: implement show more for transcript

This commit is contained in:
jinhojang6 2024-05-23 02:49:03 +09:00
parent 5683afcfe9
commit bf612b5deb
1 changed files with 18 additions and 3 deletions

View File

@ -11,21 +11,36 @@ type Props = {
const getMaxRenderIndex = (isMobile: boolean) => (isMobile ? 7 : 20)
const DEFUALT_RENDER_COUNT = 6
const EpisodeBlocks = ({ data }: Props) => {
const [showMore, setShowMore] = useState(false)
const blocks = data?.content as LPE.Post.TextBlock[]
const isMobile = useWindowSize().width < 756
const [count, setCount] = useState(DEFUALT_RENDER_COUNT)
const handleShowMore = () => {
setCount((prev) =>
prev + DEFUALT_RENDER_COUNT > blocks.length
? blocks.length
: prev + DEFUALT_RENDER_COUNT,
)
if (count >= blocks.length) {
setShowMore(false)
}
}
return (
<BlocksContainer
className={`${showMore ? 'showMore' : ''}`}
n={getMaxRenderIndex(isMobile)}
>
{blocks.map((block, idx) => (
<RenderEpisodeBlock key={'block-' + idx} block={block} />
{blocks.slice(0, count).map((block, index) => (
<RenderEpisodeBlock key={'block-' + index} block={block} />
))}
{blocks.length > getMaxRenderIndex(isMobile) && (
<ShowButton onClick={() => setShowMore(!showMore)}>
<ShowButton onClick={handleShowMore}>
{showMore ? 'Show Less' : 'Show More'}
</ShowButton>
)}