mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 02:31:12 -05:00
Refactor: Enhance activity feed filtering
This commit is contained in:
@@ -24,6 +24,8 @@ 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() {
|
||||
const {
|
||||
username
|
||||
@@ -60,6 +62,9 @@ export default function Profile() {
|
||||
|
||||
// Profile field access checking
|
||||
const { canViewField, loading: fieldAccessLoading } = useProfileFieldAccess(profile?.user_id);
|
||||
|
||||
// User role checking
|
||||
const { isModerator, loading: rolesLoading } = useUserRole();
|
||||
|
||||
// Username validation
|
||||
const usernameValidation = useUsernameValidation(editForm.username, profile?.username);
|
||||
@@ -121,6 +126,29 @@ export default function Profile() {
|
||||
try {
|
||||
const isOwnProfile = currentUser && currentUser.id === userId;
|
||||
|
||||
// Wait for role loading to complete
|
||||
if (rolesLoading) {
|
||||
setActivityLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check user privacy settings for activity visibility
|
||||
const { data: preferences } = await supabase
|
||||
.from('user_preferences')
|
||||
.select('privacy_settings')
|
||||
.eq('user_id', userId)
|
||||
.single();
|
||||
|
||||
const privacySettings = preferences?.privacy_settings as { activity_visibility?: string } | null;
|
||||
const activityVisibility = privacySettings?.activity_visibility || 'public';
|
||||
|
||||
// If activity is not public and viewer is not owner or moderator, show empty
|
||||
if (activityVisibility !== 'public' && !isOwnProfile && !isModerator()) {
|
||||
setRecentActivity([]);
|
||||
setActivityLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// Fetch last 10 reviews
|
||||
let reviewsQuery = supabase
|
||||
.from('reviews')
|
||||
@@ -129,7 +157,8 @@ export default function Profile() {
|
||||
.order('created_at', { ascending: false })
|
||||
.limit(10);
|
||||
|
||||
if (!isOwnProfile) {
|
||||
// Regular users viewing others: show only approved reviews
|
||||
if (!isOwnProfile && !isModerator()) {
|
||||
reviewsQuery = reviewsQuery.eq('moderation_status', 'approved');
|
||||
}
|
||||
|
||||
@@ -154,7 +183,9 @@ export default function Profile() {
|
||||
.order('created_at', { ascending: false })
|
||||
.limit(10);
|
||||
|
||||
if (!isOwnProfile) {
|
||||
// Regular users viewing others: show only approved submissions
|
||||
// Moderators/Admins/Superusers see all submissions (they bypass the submission process)
|
||||
if (!isOwnProfile && !isModerator()) {
|
||||
submissionsQuery = submissionsQuery.eq('status', 'approved');
|
||||
}
|
||||
|
||||
@@ -162,14 +193,18 @@ export default function Profile() {
|
||||
if (submissionsError) throw submissionsError;
|
||||
|
||||
// Fetch last 10 rankings (public top lists)
|
||||
const { data: rankings, error: rankingsError } = await supabase
|
||||
let rankingsQuery = supabase
|
||||
.from('user_top_lists')
|
||||
.select('id, title, description, list_type, created_at')
|
||||
.eq('user_id', userId)
|
||||
.eq('is_public', true)
|
||||
.order('created_at', { ascending: false })
|
||||
.limit(10);
|
||||
|
||||
if (!isOwnProfile) {
|
||||
rankingsQuery = rankingsQuery.eq('is_public', true);
|
||||
}
|
||||
|
||||
const { data: rankings, error: rankingsError } = await rankingsQuery;
|
||||
if (rankingsError) throw rankingsError;
|
||||
|
||||
// Combine and sort by date
|
||||
|
||||
Reference in New Issue
Block a user