Recent posts
This commit is contained in:
@@ -28,9 +28,10 @@ import ErrorComponent from '../Error/ErrorComponent';
|
||||
|
||||
interface Props {
|
||||
post: PostNonAuth | PostAuth;
|
||||
disableActions?: boolean;
|
||||
}
|
||||
|
||||
const Post: FC<Props> = ({ post }) => {
|
||||
const Post: FC<Props> = ({ post, disableActions }) => {
|
||||
const [deleteOpen, setDeleteOpen] = useState(false);
|
||||
const [editOpen, setEditOpen] = useState(false);
|
||||
//eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
@@ -50,7 +51,7 @@ const Post: FC<Props> = ({ post }) => {
|
||||
<Card>
|
||||
<CardHeader
|
||||
avatar={
|
||||
'id' in post.user ? (
|
||||
!disableActions && 'id' in post.user ? (
|
||||
post.user.id !== Api.getAuthenticatedUser()?.id ? (
|
||||
<MUILink component={Link} to="/profile/$id" params={{ id: post.user.id }}>
|
||||
<Avatar alt={post.user.username} src={`storage/${post.user.image}`}>
|
||||
@@ -71,7 +72,7 @@ const Post: FC<Props> = ({ post }) => {
|
||||
)
|
||||
}
|
||||
title={
|
||||
'id' in post.user ? (
|
||||
!disableActions && 'id' in post.user ? (
|
||||
post.user.id !== Api.getAuthenticatedUser()?.id ? (
|
||||
<MUILink component={Link} to="/profile/$id" params={{ id: post.user.id }}>
|
||||
{post.user.username}
|
||||
@@ -94,15 +95,16 @@ const Post: FC<Props> = ({ post }) => {
|
||||
</CardContent>
|
||||
|
||||
<CardActions>
|
||||
{(Api.isAdmin() || ('id' in post.user && post.user.id === Api.getAuthenticatedUser()?.id)) && (
|
||||
<>
|
||||
<Button size="small" onClick={() => setEditOpen(true)}>
|
||||
{t('Edit')}
|
||||
</Button>
|
||||
<PostEditDialog post={post as PostAuth} open={editOpen} onClose={() => setEditOpen(false)} />
|
||||
</>
|
||||
)}
|
||||
{Api.isAdmin() && (
|
||||
{!disableActions &&
|
||||
(Api.isAdmin() || ('id' in post.user && post.user.id === Api.getAuthenticatedUser()?.id)) && (
|
||||
<>
|
||||
<Button size="small" onClick={() => setEditOpen(true)}>
|
||||
{t('Edit')}
|
||||
</Button>
|
||||
<PostEditDialog post={post as PostAuth} open={editOpen} onClose={() => setEditOpen(false)} />
|
||||
</>
|
||||
)}
|
||||
{!disableActions && Api.isAdmin() && (
|
||||
<>
|
||||
<Button size="small" color="error" onClick={() => setDeleteOpen(true)}>
|
||||
{t('Delete')}
|
||||
|
||||
@@ -13,17 +13,20 @@ import {
|
||||
} from '@mui/material';
|
||||
import { FC, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { PostAuth } from '../../types/Post';
|
||||
import { User } from '../../types/User';
|
||||
import convertDate from '../../utils/date';
|
||||
import UserEditDialog from '../Dialogs/UserEdit/UserEditDialog';
|
||||
import UserImageDialog from '../Dialogs/UserImage/UserImageDialog';
|
||||
import Post from '../Post/Post';
|
||||
|
||||
interface Props {
|
||||
user: User;
|
||||
posts: PostAuth[];
|
||||
canEdit?: boolean;
|
||||
}
|
||||
|
||||
const Profile: FC<Props> = ({ user, canEdit }) => {
|
||||
const Profile: FC<Props> = ({ user, posts, canEdit }) => {
|
||||
const [editOpen, setEditOpen] = useState(false);
|
||||
const [imageOpen, setImageOpen] = useState(false);
|
||||
|
||||
@@ -74,6 +77,11 @@ const Profile: FC<Props> = ({ user, canEdit }) => {
|
||||
<Typography sx={{ opacity: 0.36 }}>{t('Recent posts')}</Typography>
|
||||
</Divider>
|
||||
</Grid>
|
||||
{posts.map((post) => (
|
||||
<Grid item xs={12}>
|
||||
<Post post={post} disableActions />
|
||||
</Grid>
|
||||
))}
|
||||
</Grid>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user