From 1baad05e79c84e7b81bb8036682dfa48ae94d3e4 Mon Sep 17 00:00:00 2001 From: pradeepkumar Date: Sat, 7 Mar 2026 22:19:10 +0530 Subject: [PATCH] feat: Replace hardcoded default profile image with a dynamic placeholder and remove cache-busting from presigned URLs. --- src/app/(user)/user/profile/[id]/page.tsx | 55 +++++++++++------------ src/app/(user)/user/profiles/page.tsx | 50 ++++++++++++--------- 2 files changed, 54 insertions(+), 51 deletions(-) diff --git a/src/app/(user)/user/profile/[id]/page.tsx b/src/app/(user)/user/profile/[id]/page.tsx index 908060c..350b940 100644 --- a/src/app/(user)/user/profile/[id]/page.tsx +++ b/src/app/(user)/user/profile/[id]/page.tsx @@ -86,8 +86,6 @@ export default function AgentProfileView() { const [connectionStatus, setConnectionStatus] = useState(null); const [connectionRequestId, setConnectionRequestId] = useState(null); - const defaultImage = '/assets/demo_images/8f017153a7b4a239a4f0691234ef97dd55092282.jpg'; - // Helper to check if avatar is an S3 key (not a full URL or local path) const isS3Key = (avatar: string | null | undefined): boolean => { if (!avatar) return false; @@ -149,20 +147,11 @@ export default function AgentProfileView() { if (profile.avatar && isS3Key(profile.avatar)) { try { const presignedUrl = await uploadService.getPresignedDownloadUrl(profile.avatar); - // Add cache-busting parameter to force browser to fetch fresh image - // This prevents showing old cached image when avatar is updated - const profileWithTimestamp = profile as unknown as { updatedAt?: string }; - const cacheBuster = profileWithTimestamp.updatedAt - ? new Date(profileWithTimestamp.updatedAt).getTime() - : Date.now(); - const urlWithCacheBuster = `${presignedUrl}&_t=${cacheBuster}`; - setAvatarUrl(urlWithCacheBuster); + setAvatarUrl(presignedUrl); } catch (avatarErr) { console.error('Failed to get avatar URL:', avatarErr); - // Don't fail the whole page, just use default image } } else if (profile.avatar) { - // It's already a full URL or local path setAvatarUrl(profile.avatar); } } catch (err) { @@ -213,9 +202,9 @@ export default function AgentProfileView() { }; const getProfileImageUrl = () => { - // If image failed to load, return default + // If image failed to load, return null if (imageError) { - return defaultImage; + return null; } // If we have a presigned URL from S3, use it @@ -225,7 +214,7 @@ export default function AgentProfileView() { // Check for null, undefined, or empty string if (!agentProfile?.avatar || agentProfile.avatar.trim() === '') { - return defaultImage; + return null; } // For relative paths (local assets), return as-is @@ -233,8 +222,8 @@ export default function AgentProfileView() { return agentProfile.avatar; } - // Default fallback - return defaultImage; + // No image available + return null; }; // Format member since date @@ -293,18 +282,26 @@ export default function AgentProfileView() {
{/* Profile Image */}
-
- {/* eslint-disable-next-line @next/next/no-img-element */} - Profile { - const target = e.target as HTMLImageElement; - target.src = defaultImage; - setImageError(true); - }} - /> +
+ {getProfileImageUrl() ? ( + /* eslint-disable-next-line @next/next/no-img-element */ + Profile setImageError(true)} + /> + ) : ( +
+ Profile +
+ )} {/* Gradient Overlay */}
diff --git a/src/app/(user)/user/profiles/page.tsx b/src/app/(user)/user/profiles/page.tsx index 7fee1f2..1587dc2 100644 --- a/src/app/(user)/user/profiles/page.tsx +++ b/src/app/(user)/user/profiles/page.tsx @@ -64,12 +64,10 @@ interface ProfileCardProps { function ProfileCard({ profile, resolvedAvatarUrl }: ProfileCardProps) { const [showFullBio, setShowFullBio] = useState(false); const [showAllTags, setShowAllTags] = useState(false); - const defaultImage = '/assets/demo_images/8f017153a7b4a239a4f0691234ef97dd55092282.jpg'; - - const getProfileImageUrl = () => { + const getProfileImageUrl = (): string | null => { if (resolvedAvatarUrl) return resolvedAvatarUrl; if (profile.avatar?.startsWith('/')) return profile.avatar; - return defaultImage; + return null; }; // Format member since date @@ -237,17 +235,29 @@ function ProfileCard({ profile, resolvedAvatarUrl }: ProfileCardProps) {
{/* Profile Image & View Profile Button */}
-
- {/* eslint-disable-next-line @next/next/no-img-element */} - {`${profile.firstName} { - const target = e.target as HTMLImageElement; - target.src = defaultImage; - }} - /> +
+ {getProfileImageUrl() ? ( + /* eslint-disable-next-line @next/next/no-img-element */ + {`${profile.firstName} { + const target = e.target as HTMLImageElement; + target.style.display = 'none'; + }} + /> + ) : ( +
+ {`${profile.firstName} +
+ )}