refactor(PostCard, ImageGrid, SmartImage): enhance post editing display and image handling
- Introduced a new method to determine the last edited time for posts, prioritizing content_edited_at for better accuracy in display. - Updated PostCard and PostDetailScreen components to utilize the new editing display logic. - Enhanced ImageGrid and SmartImage components to support additional preview URLs and improve image loading behavior, including lazy loading optimizations for web. - Modified Post and PostDTO interfaces to include contentEditedAt for better tracking of post edits.
This commit is contained in:
@@ -135,12 +135,24 @@ const PostCard: React.FC<PostCardProps> = ({
|
||||
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
|
||||
};
|
||||
|
||||
const isPostEdited = (createdAt?: string, updatedAt?: string): boolean => {
|
||||
if (!createdAt || !updatedAt) return false;
|
||||
const created = new Date(createdAt).getTime();
|
||||
const updated = new Date(updatedAt).getTime();
|
||||
if (Number.isNaN(created) || Number.isNaN(updated)) return false;
|
||||
return updated - created > 1000;
|
||||
/** 返回应展示的「最后编辑」时间字符串;优先 content_edited_at(与点赞/评论等统计更新解耦) */
|
||||
const getPostEditedDisplayAt = (
|
||||
createdAt?: string | null,
|
||||
contentEditedAt?: string | null,
|
||||
updatedAt?: string | null,
|
||||
): string | null => {
|
||||
if (contentEditedAt) {
|
||||
const c = new Date(createdAt || '').getTime();
|
||||
const e = new Date(contentEditedAt).getTime();
|
||||
if (!Number.isNaN(c) && !Number.isNaN(e) && e - c > 1000) return contentEditedAt;
|
||||
return null;
|
||||
}
|
||||
if (createdAt && updatedAt) {
|
||||
const c = new Date(createdAt).getTime();
|
||||
const u = new Date(updatedAt).getTime();
|
||||
if (!Number.isNaN(c) && !Number.isNaN(u) && u - c > 1000) return updatedAt;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
const getTruncatedContent = (content: string | undefined | null, maxLength: number = 100): string => {
|
||||
@@ -560,11 +572,18 @@ const PostCard: React.FC<PostCardProps> = ({
|
||||
<Text variant="caption" color={colors.text.hint} style={styles.timeText}>
|
||||
发布 {formatDateTime(post.created_at)}
|
||||
</Text>
|
||||
{isPostEdited(post.created_at, post.updated_at) && (
|
||||
{(() => {
|
||||
const editedAt = getPostEditedDisplayAt(
|
||||
post.created_at,
|
||||
post.content_edited_at,
|
||||
post.updated_at,
|
||||
);
|
||||
return editedAt ? (
|
||||
<Text variant="caption" color={colors.text.hint} style={styles.timeText}>
|
||||
{' · 修改 '}{formatDateTime(post.updated_at)}
|
||||
{' · 修改 '}{formatDateTime(editedAt)}
|
||||
</Text>
|
||||
)}
|
||||
) : null;
|
||||
})()}
|
||||
</View>
|
||||
</View>
|
||||
{post.is_pinned && (
|
||||
|
||||
Reference in New Issue
Block a user