Fix profile privacy and simplify code

This commit is contained in:
gpt-engineer-app[bot]
2025-10-14 18:11:10 +00:00
parent 85c79ad511
commit 6698ee9a29
6 changed files with 100 additions and 217 deletions

View File

@@ -24,7 +24,6 @@ import { profileEditSchema } from '@/lib/validation';
import { LocationDisplay } from '@/components/profile/LocationDisplay';
import { UserBlockButton } from '@/components/profile/UserBlockButton';
import { PersonalLocationDisplay } from '@/components/profile/PersonalLocationDisplay';
import { useProfileFieldAccess } from '@/hooks/useProfileFieldAccess';
import { useUserRole } from '@/hooks/useUserRole';
export default function Profile() {
@@ -59,9 +58,6 @@ export default function Profile() {
});
const [recentActivity, setRecentActivity] = useState<any[]>([]);
const [activityLoading, setActivityLoading] = useState(false);
// Profile field access checking
const { canViewField, loading: fieldAccessLoading } = useProfileFieldAccess(profile?.user_id);
// User role checking
const { isModerator, loading: rolesLoading } = useUserRole();
@@ -489,9 +485,9 @@ export default function Profile() {
variant="avatar"
maxFiles={1}
maxSizeMB={1}
existingPhotos={canViewField('avatar_url') && profile.avatar_url ? [profile.avatar_url] : []}
existingPhotos={profile.avatar_url ? [profile.avatar_url] : []}
onUploadComplete={handleAvatarUpload}
currentImageId={avatarImageId}
currentImageId={avatarImageId}
onError={error => {
toast({
title: "Upload Error",
@@ -577,7 +573,7 @@ export default function Profile() {
{profile.display_name && <Badge variant="secondary" className="cursor-pointer hover:bg-secondary/80" onClick={() => navigate(`/profile/${profile.username}`)}>@{profile.username}</Badge>}
</div>
{canViewField('bio') && profile.bio && (
{profile.bio && (
<p className="text-muted-foreground mb-4 max-w-2xl">
{profile.bio}
</p>
@@ -592,31 +588,23 @@ export default function Profile() {
})}
</div>
{/* Show pronouns if enabled and privacy allows */}
{profile.show_pronouns && canViewField('preferred_pronouns') && profile.preferred_pronouns && (
{/* Show pronouns if enabled and present (privacy already enforced by get_filtered_profile) */}
{profile.show_pronouns && profile.preferred_pronouns && (
<div className="flex items-center gap-1">
<User className="w-4 h-4" />
{profile.preferred_pronouns}
</div>
)}
{/* Show personal location if available and privacy allows */}
{canViewField('personal_location') && profile.personal_location && (
<PersonalLocationDisplay
personalLocation={profile.personal_location}
userId={profile.user_id}
isOwnProfile={isOwnProfile}
/>
)}
{/* Show personal location (privacy already enforced by get_filtered_profile) */}
<PersonalLocationDisplay
personalLocation={profile.personal_location}
/>
{/* Show location only if privacy allows */}
{canViewField('location_id') && profile.location && (
<LocationDisplay
location={profile.location}
userId={profile.user_id}
isOwnProfile={isOwnProfile}
/>
)}
{/* Show location (privacy already enforced by get_filtered_profile) */}
<LocationDisplay
location={profile.location}
/>
</div>
</div>}
</div>