diff --git a/src/components/Posts/Post.tsx b/src/components/Posts/Post.tsx index ec821c09..5f7900f4 100644 --- a/src/components/Posts/Post.tsx +++ b/src/components/Posts/Post.tsx @@ -1,4 +1,4 @@ -import {Stack, Typography} from '@mui/material' +import {Grid, Stack, Typography} from '@mui/material' import {FC} from 'react' import {formatDate} from '@/utils/formatDate' @@ -6,7 +6,7 @@ import {useSeminarInfo} from '@/utils/useSeminarInfo' import {Button} from '../Clickable/Button' import {Link} from '../Clickable/Link' -import {PostMarkdown} from './PostMarkdown' +import {PostDetail} from './PostDetail' export interface IPost { id: number @@ -18,17 +18,16 @@ export interface IPost { visible_after: string visible_until: string sites: number[] - isDetailOpen: boolean openDetail: () => void } -export const Post: FC = ({caption, short_text, links, details, sites, added_at, isDetailOpen, openDetail}) => { +export const Post: FC = ({caption, short_text, links, details, sites, added_at, openDetail}) => { const {seminarId} = useSeminarInfo() if (!sites.includes(seminarId)) return null return ( - + {caption} {short_text} @@ -51,24 +50,6 @@ export const Post: FC = ({caption, short_text, links, details, sites, add {formatDate(added_at)} - - {isDetailOpen && ( - - - {caption} - - - - )} ) } diff --git a/src/components/Posts/PostDetail.tsx b/src/components/Posts/PostDetail.tsx new file mode 100644 index 00000000..c71a4489 --- /dev/null +++ b/src/components/Posts/PostDetail.tsx @@ -0,0 +1,28 @@ +import {Stack, Typography} from '@mui/material' +import {FC} from 'react' + +import {PostMarkdown} from './PostMarkdown' + +export interface IPost { + caption: string + details: string +} + +export const PostDetail: FC = ({caption, details}) => { + return ( + + + {caption} + + + + ) +} diff --git a/src/components/Posts/Posts.tsx b/src/components/Posts/Posts.tsx index 256dab5d..e85b14d1 100644 --- a/src/components/Posts/Posts.tsx +++ b/src/components/Posts/Posts.tsx @@ -1,10 +1,11 @@ -import {Stack, Typography} from '@mui/material' +import {Grid, Stack, Typography} from '@mui/material' import {useQuery} from '@tanstack/react-query' import axios from 'axios' -import {FC, useState} from 'react' +import {FC, Fragment, useRef, useState} from 'react' import {Loading} from '../Loading/Loading' import {IPost, Post} from './Post' +import {PostDetail} from './PostDetail' export const Posts: FC = () => { const { @@ -17,22 +18,39 @@ export const Posts: FC = () => { }) const posts = postsData?.data ?? [] - const [activePostDetailId, setActivePostDetailId] = useState(null) + const [activePostDetailIndex, setActivePostDetailIndex] = useState(undefined) if (postsIsLoading) return if (postsError) return {postsError.message} return ( - - {posts.map((post) => ( - setActivePostDetailId(post.id)} - /> - ))} - + <> + {activePostDetailIndex !== 0 && ( + + + {posts.slice(0, activePostDetailIndex).map((post, index) => ( + setActivePostDetailIndex(index)} /> + ))} + + + )} + {activePostDetailIndex !== undefined && ( + + + {posts.slice(activePostDetailIndex).map((post, index) => ( + setActivePostDetailIndex(activePostDetailIndex + index)} + /> + ))} + + + + + + )} + ) } diff --git a/src/pages/strom/index.tsx b/src/pages/strom/index.tsx index 52345e36..6fbf0eeb 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 = () => ( - + )