()
| 69 | } |
| 70 | |
| 71 | export default function PostContent() { |
| 72 | const {postObj, comments = [], editable, avatar, latestYear, urlPostId, currentDisplayName} = useLoaderData(); |
| 73 | const smallPage = useSmallPage(); |
| 74 | const [open, setOpen] = useState(false); |
| 75 | |
| 76 | if (!postObj) { |
| 77 | return <Typography>帖子加载失败或不存在。</Typography>; |
| 78 | } |
| 79 | const handleClose = () => { |
| 80 | setOpen(false); |
| 81 | }; |
| 82 | const handleOpen = () => { |
| 83 | setOpen(true); |
| 84 | }; |
| 85 | const authorUrl = latestYear ? postsApplicantPath(urlPostId, `${postObj.author}@${latestYear}`) : null; |
| 86 | const authorLinkProps = authorUrl ? {component: Link, to: authorUrl} : {}; |
| 87 | const commentsByParentId = comments.reduce((acc, comment) => { |
| 88 | const parentId = comment.parentId; |
| 89 | acc[parentId] = [...(acc[parentId] ?? []), comment]; |
| 90 | return acc; |
| 91 | }, {}); |
| 92 | const topLevelComments = getVisibleComments(postObj.id, commentsByParentId, true); |
| 93 | return ( |
| 94 | <> |
| 95 | <Box className="PostContentHeader" sx={{pb: "0.5rem"}}> |
| 96 | <Box sx={{pb: "0.5rem", display: 'flex', gap: '1rem', alignItems: 'center'}}> |
| 97 | <Avatar |
| 98 | src={avatar} |
| 99 | sx={{ |
| 100 | height: (smallPage ? "4.5rem" : "4rem"), |
| 101 | width: (smallPage ? "4.5rem" : "4rem"), |
| 102 | cursor: authorUrl ? 'pointer' : 'default' |
| 103 | }} |
| 104 | {...authorLinkProps} |
| 105 | /> |
| 106 | <Box sx={{minWidth: 0}}> |
| 107 | <BoldTypography variant="h6" |
| 108 | sx={authorUrl ? {cursor: 'pointer', textDecoration: "none"} : {}} |
| 109 | {...authorLinkProps} |
| 110 | > |
| 111 | {postObj.author} |
| 112 | </BoldTypography> |
| 113 | <Typography variant="body2" sx={{color: 'text.secondary'}}> |
| 114 | 创建于 {utcToLocal(postObj.created_at, true)} |
| 115 | </Typography> |
| 116 | <Typography variant="body2" sx={{color: 'text.secondary'}}> |
| 117 | 最后修改于 {utcToLocal(postObj.updated_at ?? postObj.created_at, true)} |
| 118 | </Typography> |
| 119 | </Box> |
| 120 | </Box> |
| 121 | <Box className='ReviseRefreshButtonGroup'> |
| 122 | {editable ? |
| 123 | <> |
| 124 | <Tooltip title="编辑内容" arrow> |
| 125 | <IconButton component={Link} to={`${postsPostPath(urlPostId)}/edit${window.location.search}`}> |
| 126 | <Edit/> |
| 127 | </IconButton> |
| 128 | </Tooltip> |
nothing calls this directly
no test coverage detected