From 02dd271eb8186e9feb8e99f09daa4a58afe6bf60 Mon Sep 17 00:00:00 2001 From: Barresi Date: Thu, 18 Jul 2024 20:03:55 +0700 Subject: [PATCH] feat: add show full text comp --- src/entities/post-news/ui/post-news.tsx | 32 +++------------------ src/shared/ui/show-full-text.tsx | 38 +++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 28 deletions(-) create mode 100644 src/shared/ui/show-full-text.tsx diff --git a/src/entities/post-news/ui/post-news.tsx b/src/entities/post-news/ui/post-news.tsx index adb68567..76fdc857 100644 --- a/src/entities/post-news/ui/post-news.tsx +++ b/src/entities/post-news/ui/post-news.tsx @@ -4,9 +4,10 @@ import { type IPost } from '@shared/lib/types/api' import { CarouselItem, CarouselWithPoints } from '@shared/ui/carousel' import { LinkName } from '@shared/ui/link-name' import { UserAvatar } from '@shared/ui/user-avatar' -import { useState, type FC, type ReactNode } from 'react' +import { type FC, type ReactNode } from 'react' import eye from '@assets/ui/Eye.svg' +import { ShowFullText } from '@shared/ui/show-full-text' interface IPostNewsProps { post: IPost | undefined @@ -14,7 +15,6 @@ interface IPostNewsProps { buttonDelete: ReactNode } const PostNews: FC = ({ post, buttonLike, buttonDelete }) => { - const [isExpanded, setIsExpanded] = useState(false) const maxLength = useWindowSize(1024) ? 200 : 400 const createDate = post?.createdAt @@ -25,10 +25,6 @@ const PostNews: FC = ({ post, buttonLike, buttonDelete }) => { import.meta.env.VITE_BACKEND_DOMEN }/ftp/posts/${post?.createdById}/` - const toggleExpand = (): void => { - setIsExpanded(!isExpanded) - } - return (
@@ -49,28 +45,8 @@ const PostNews: FC = ({ post, buttonLike, buttonDelete }) => {
{buttonDelete}
-
- {isExpanded ? ( -
- {post?.text} - -
- ) : ( -
- {post?.text.slice(0, maxLength)} - {post?.text.length ? post?.text.length > maxLength && '...' : null} - {post?.text.length - ? post?.text.length > maxLength && ( - - ) - : null} -
- )} -
+ + {post?.pictures.length ? ( post?.pictures.length === 1 ? ( diff --git a/src/shared/ui/show-full-text.tsx b/src/shared/ui/show-full-text.tsx new file mode 100644 index 00000000..45064629 --- /dev/null +++ b/src/shared/ui/show-full-text.tsx @@ -0,0 +1,38 @@ +import { useState, type FC } from 'react' + +interface IShowFullTextProps { + text: string | undefined | null + maxLength: number + className?: string +} +const ShowFullText: FC = ({ className, maxLength = 200, text }) => { + const [isExpanded, setIsExpanded] = useState(false) + const toggleExpand = (): void => { + setIsExpanded(!isExpanded) + } + return ( +
+ {isExpanded ? ( +
+ {text} + +
+ ) : ( +
+ {text?.slice(0, maxLength)} + {text?.length ? text.length > maxLength && '...' : null} + {text?.length + ? text.length > maxLength && ( + + ) + : null} +
+ )} +
+ ) +} +export { ShowFullText }