Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added close button to PostDetail #466

Merged
merged 3 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/components/Admin/custom/PostPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ export const PostPreview: FC = () => {
</Stack>
</Grid>
<Grid xs={5}>
{isDetailOpen && <PostDetail caption={formData?.caption ?? ''} details={formData?.details ?? ''} />}
{isDetailOpen && (
<PostDetail
closeDetail={() => openDetail(false)}
caption={formData?.caption ?? ''}
details={formData?.details ?? ''}
/>
)}
</Grid>
</Grid>
)}
Expand Down
19 changes: 14 additions & 5 deletions src/components/Posts/PostDetail.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import {Stack, Typography} from '@mui/material'
import {Box, Stack, Theme, Typography, useMediaQuery} from '@mui/material'

Check warning on line 1 in src/components/Posts/PostDetail.tsx

View workflow job for this annotation

GitHub Actions / branch-test

'Box' is defined but never used
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<PostDetailProps> = ({caption, details}) => {
export const PostDetail: FC<PostDetailProps> = ({caption, details, closeDetail}) => {
const lg = useMediaQuery<Theme>((theme) => theme.breakpoints.up('lg'))
const iconSize = lg ? 34 : 24

return (
<Stack
p={2}
Expand All @@ -17,11 +22,15 @@
backgroundColor: 'white',
maxHeight: '60vh',
overflow: 'auto',
position: 'relative',
}}
>
<Typography variant="postTitle" textTransform="uppercase" fontStyle="italic" mb={4}>
{caption}
</Typography>
<Stack direction="row" justifyContent="space-between" alignItems="center" mb={4}>
<Typography variant="postTitle" textTransform="uppercase" fontStyle="italic">
{caption}
</Typography>
<CloseButton size={iconSize} onClick={closeDetail} invertColors />
</Stack>
<PostMarkdown content={details} />
</Stack>
)
Expand Down
6 changes: 5 additions & 1 deletion src/components/Posts/Posts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ export const Posts: FC = () => {
</Stack>
</Grid>
<Grid xs={12} sm={6} mt={{xs: 2, sm: 0}}>
<PostDetail caption={posts[activePostDetailIndex].caption} details={posts[activePostDetailIndex].details} />
<PostDetail
closeDetail={() => setActivePostDetailIndex(undefined)}
caption={posts[activePostDetailIndex].caption}
details={posts[activePostDetailIndex].details}
/>
</Grid>
</Grid>
)}
Expand Down
Loading