From 79d33ecf6603a7415da020a4e7b6225d79162abf Mon Sep 17 00:00:00 2001 From: matushl Date: Mon, 11 Dec 2023 00:40:07 +0100 Subject: [PATCH] Add Post detail --- src/components/Posts/Post.tsx | 40 +++++++++++++++++++++++++++++----- src/components/Posts/Posts.tsx | 13 ++++++++--- src/theme.ts | 2 +- 3 files changed, 45 insertions(+), 10 deletions(-) diff --git a/src/components/Posts/Post.tsx b/src/components/Posts/Post.tsx index 9c9ae050..f6b1ef76 100644 --- a/src/components/Posts/Post.tsx +++ b/src/components/Posts/Post.tsx @@ -4,6 +4,7 @@ import {FC} from 'react' import {formatDate} from '@/utils/formatDate' import {useSeminarInfo} from '@/utils/useSeminarInfo' +import {Button} from '../Clickable/Button' import {Link} from '../Clickable/Link' export interface IPost { @@ -16,33 +17,60 @@ export interface IPost { visible_after: string visible_until: string sites: number[] + isDialogOpen: boolean + openDialog: () => void } -export const Post: FC = ({caption, short_text, links, sites, added_at}) => { +export const Post: FC = ({caption, short_text, links, details, sites, added_at, isDialogOpen, openDialog}) => { const {seminarId} = useSeminarInfo() if (!sites.includes(seminarId)) return null return ( - + {caption} - - {short_text} - + + {short_text} + {/* alignItems so the links don't stretch */} + {details.length > 0 && ( + + )} {links.map(({id, url, caption}) => ( {caption} ))} - {formatDate(added_at)} + + {isDialogOpen && ( + + + {caption} + + + {details} + + + )} ) } diff --git a/src/components/Posts/Posts.tsx b/src/components/Posts/Posts.tsx index dab23501..9408c37b 100644 --- a/src/components/Posts/Posts.tsx +++ b/src/components/Posts/Posts.tsx @@ -1,7 +1,7 @@ import {Stack, Typography} from '@mui/material' import {useQuery} from '@tanstack/react-query' import axios from 'axios' -import {FC} from 'react' +import {FC, useState} from 'react' import {Loading} from '../Loading/Loading' import {IPost, Post} from './Post' @@ -17,14 +17,21 @@ export const Posts: FC = () => { }) const posts = postsData?.data ?? [] + const [activePostDetailId, setActivePostDetailId] = useState(null) + if (postsIsLoading) return if (postsError) return {postsError.message} return ( - + {posts.map((post) => ( - + setActivePostDetailId(post.id)} + /> ))} ) diff --git a/src/theme.ts b/src/theme.ts index 6c344996..107ec214 100644 --- a/src/theme.ts +++ b/src/theme.ts @@ -66,7 +66,7 @@ const _theme = createTheme({ button1: 'span', button2: 'span', button3: 'span', - postTitle: 'span', + postTitle: 'h1', postBody: 'span', }, },