import * as React from 'react'; import { styled } from '@mui/material/styles'; import Card from '@mui/material/Card'; import CardHeader from '@mui/material/CardHeader'; import CardMedia from '@mui/material/CardMedia'; import CardContent from '@mui/material/CardContent'; import CardActions from '@mui/material/CardActions'; import Collapse from '@mui/material/Collapse'; import Avatar from '@mui/material/Avatar'; import IconButton, { IconButtonProps } from '@mui/material/IconButton'; import Typography from '@mui/material/Typography'; import { red } from '@mui/material/colors'; import FavoriteIcon from '@mui/icons-material/Favorite'; import ShareIcon from '@mui/icons-material/Share'; import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; import MoreVertIcon from '@mui/icons-material/MoreVert'; import api from "../api/axios"; interface ExpandMoreProps extends IconButtonProps { expand: boolean; } interface PostProps { postId: string; } interface PostResponse { description: string; status: string; likes: number; tags: string[]; user: { id: string; name: string; }; createdAt: string; updatedAt: string; images: { originalName: string; mimetype: string; url: string; }[]; following: boolean; } const ExpandMore = styled((props: ExpandMoreProps) => { const { expand, ...other } = props; return ; })(({ theme, expand }) => ({ marginLeft: 'auto', transition: theme.transitions.create('transform', { duration: theme.transitions.duration.shortest, }), transform: expand ? 'rotate(180deg)' : 'rotate(0deg)', })); export default function Post({ postId }: PostProps) { const [expanded, setExpanded] = React.useState(false); const [post, setPost] = React.useState(null); React.useEffect(() => { getPostbyID(); // eslint-disable-next-line }, [postId]); async function getPostbyID(): Promise { try { const response = await api.get(`/posts/getPost/{postId}?postId=${postId}`); //const response = await api.get(`http://localhost:3001/api/posts/getPost/{postId}?postId=${postId}`); setPost(response.data); } catch (error) { console.error("Failed to fetch post:", error); } } if (!post) { return ( Loading... ); } return ( {post.user.name.charAt(0).toUpperCase()} } action={ } title={post.user.name} subheader={new Date(post.createdAt).toLocaleString()} /> {post.images && post.images.length > 0 && ( )} {post.description} Status: {post.status} Likes: {post.likes} Tags: {post.tags.join(", ")} Following: {post.following ? "Ja" : "Nein"} setExpanded(!expanded)} aria-expanded={expanded} aria-label="show more" > Erstellt am: {new Date(post.createdAt).toLocaleString()} Zuletzt aktualisiert: {new Date(post.updatedAt).toLocaleString()} ); }