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:
@@ -318,12 +318,23 @@ export const PostDetailScreen: React.FC = () => {
|
||||
return formatDateTime(dateString);
|
||||
};
|
||||
|
||||
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;
|
||||
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;
|
||||
};
|
||||
|
||||
// 格式化数字
|
||||
@@ -1081,14 +1092,21 @@ export const PostDetailScreen: React.FC = () => {
|
||||
<Text variant="caption" color={colors.text.hint} style={styles.metaInfoText}>
|
||||
发布 {formatRelativeTime(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 style={styles.metaInfoDot}>·</Text>
|
||||
<Text variant="caption" color={colors.text.hint} style={styles.metaInfoText}>
|
||||
修改 {formatRelativeTime(post.updated_at)}
|
||||
修改 {formatRelativeTime(editedAt)}
|
||||
</Text>
|
||||
</>
|
||||
)}
|
||||
) : null;
|
||||
})()}
|
||||
{post.views_count !== undefined && post.views_count > 0 && (
|
||||
<>
|
||||
<Text style={styles.metaInfoDot}>·</Text>
|
||||
|
||||
Reference in New Issue
Block a user