From dca4ace10852f0b725b549ecb054d182815cf4fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=BA=C5=A1=20Hlav=C3=A1=C4=8Dik?= Date: Sat, 14 Dec 2024 15:29:14 +0100 Subject: [PATCH] Replace Post detail with "show more" workflow (#522) * Replace Post detail with "show more" workflow * Update PostReview in Admin * improve styles --- src/components/Admin/custom/PostPreview.tsx | 18 ++----- src/components/Posts/Post.tsx | 59 ++++++++++++--------- src/components/Posts/PostDetail.tsx | 37 ------------- src/components/Posts/Posts.tsx | 56 +++---------------- src/pages/strom/index.tsx | 2 +- 5 files changed, 45 insertions(+), 127 deletions(-) delete mode 100644 src/components/Posts/PostDetail.tsx diff --git a/src/components/Admin/custom/PostPreview.tsx b/src/components/Admin/custom/PostPreview.tsx index c21e4ebc..c5508449 100644 --- a/src/components/Admin/custom/PostPreview.tsx +++ b/src/components/Admin/custom/PostPreview.tsx @@ -1,22 +1,20 @@ import {Stack} from '@mui/material' import {ThemeProvider} from '@mui/material/styles' import Grid from '@mui/material/Unstable_Grid2' -import {FC, useState} from 'react' +import {FC} from 'react' import {FormDataConsumer} from 'react-admin' import {Post} from '@/components/Posts/Post' -import {PostDetail} from '@/components/Posts/PostDetail' import {theme} from '@/theme' export const PostPreview: FC = () => { - const [isDetailOpen, openDetail] = useState(false) return ( {({formData}) => ( - - + + { visible_after={formData?.visible_after ?? ''} visible_until={formData?.visible_until ?? ''} sites={formData?.sites ?? []} - openDetail={() => openDetail(true)} /> - - {isDetailOpen && ( - openDetail(false)} - caption={formData?.caption ?? ''} - details={formData?.details ?? ''} - /> - )} - )} diff --git a/src/components/Posts/Post.tsx b/src/components/Posts/Post.tsx index 0141baba..c2df14e1 100644 --- a/src/components/Posts/Post.tsx +++ b/src/components/Posts/Post.tsx @@ -1,10 +1,11 @@ import {Stack, Typography} from '@mui/material' -import {FC} from 'react' +import {FC, useState} from 'react' import {formatDate} from '@/utils/formatDate' import {Button} from '../Clickable/Button' import {Link} from '../Clickable/Link' +import {PostMarkdown} from './PostMarkdown' export interface IPost { id: number @@ -16,32 +17,38 @@ export interface IPost { visible_after: string visible_until: string sites: number[] - openDetail: () => void } -export const Post: FC = ({caption, short_text, links, details, added_at, openDetail}) => ( - - {caption} - - {short_text} - - - {/* alignItems so the links don't stretch */} - - {details.length > 0 && ( - - )} - {links.map(({id, url, caption}) => ( - - {caption} - - ))} +export const Post: FC = ({caption, short_text, links, details, added_at}) => { + const [displayDetail, setDisplayDetail] = useState(false) + const toggleDisplayDetail = () => setDisplayDetail((prev) => !prev) + + return ( + + {caption} + + {short_text} + + {displayDetail && } + + + {/* alignItems so the links don't stretch */} + + {details.length > 0 && ( + + )} + {links.map(({id, url, caption}) => ( + + {caption} + + ))} + + + {formatDate(added_at)} + - - {formatDate(added_at)} - - -) + ) +} diff --git a/src/components/Posts/PostDetail.tsx b/src/components/Posts/PostDetail.tsx deleted file mode 100644 index 297763de..00000000 --- a/src/components/Posts/PostDetail.tsx +++ /dev/null @@ -1,37 +0,0 @@ -import {Box, Stack, Theme, Typography, useMediaQuery} from '@mui/material' -import {FC} from 'react' - -import {CloseButton} from '../CloseButton/CloseButton' -import {PostMarkdown} from './PostMarkdown' - -type PostDetailProps = { - caption: string - details: string - closeDetail: () => void -} - -export const PostDetail: FC = ({caption, details, closeDetail}) => { - const lg = useMediaQuery((theme) => theme.breakpoints.up('lg')) - const iconSize = lg ? 34 : 24 - - return ( - - - - {caption} - - - - - - ) -} diff --git a/src/components/Posts/Posts.tsx b/src/components/Posts/Posts.tsx index 169abf26..80ecc100 100644 --- a/src/components/Posts/Posts.tsx +++ b/src/components/Posts/Posts.tsx @@ -1,15 +1,12 @@ import {Stack, Typography} from '@mui/material' -// new MUI Grid without spacing issues: https://mui.com/material-ui/react-grid2/ -import Grid from '@mui/material/Unstable_Grid2' import {useQuery} from '@tanstack/react-query' import axios from 'axios' -import {FC, useState} from 'react' +import {FC} from 'react' import {useSeminarInfo} from '@/utils/useSeminarInfo' import {Loading} from '../Loading/Loading' import {IPost, Post} from './Post' -import {PostDetail} from './PostDetail' export const Posts: FC = () => { const { @@ -24,54 +21,17 @@ export const Posts: FC = () => { const {seminarId} = useSeminarInfo() - const [activePostDetailIndex, setActivePostDetailIndex] = useState() - if (postsIsLoading) return if (postsError) return {postsError.message} return ( - <> - {/* detail prispevku chceme zobrazit na urovni toho prispevku - `activePostDetailIndex` teda rozdeluje prispevky na dva gridy: - - prvy grid su vsetky prispevky do rozbaleneho prispevku - len jeden grid item ako jeden stlpec prispevkov (`xs={4}` ako 4 stlpce z 12) - - druhy grid su prispevky od rozbaleneho prispevku - dva grid itemy ako jeden stlpec prispevkov (`xs={4}`) a druhy stlpec ako detail prispevku (`xs={5}` - detail je sirsi) */} - {activePostDetailIndex !== 0 && ( - - - - {posts.slice(0, activePostDetailIndex).map((post, index) => { - if (!post.sites.includes(seminarId)) return null - return setActivePostDetailIndex(index)} /> - })} - - - - )} - {activePostDetailIndex !== undefined && ( - - - - {posts.slice(activePostDetailIndex).map((post, index) => { - if (!post.sites.includes(seminarId)) return null - return ( - setActivePostDetailIndex(activePostDetailIndex + index)} - /> - ) - })} - - - - setActivePostDetailIndex(undefined)} - caption={posts[activePostDetailIndex].caption} - details={posts[activePostDetailIndex].details} - /> - - - )} - + + {posts + .filter((p) => p.sites.includes(seminarId)) + .map((post) => ( + + ))} + ) } diff --git a/src/pages/strom/index.tsx b/src/pages/strom/index.tsx index 48484003..5d128163 100644 --- a/src/pages/strom/index.tsx +++ b/src/pages/strom/index.tsx @@ -4,7 +4,7 @@ import {PageLayout} from '@/components/PageLayout/PageLayout' import {Posts} from '@/components/Posts/Posts' const Strom: NextPage = () => ( - + )