Refactor code structure and remove redundant changes

This commit is contained in:
pacnpal
2025-11-09 16:31:34 -05:00
parent 2884bc23ce
commit eb68cf40c6
1080 changed files with 27361 additions and 56687 deletions

View File

@@ -0,0 +1,103 @@
import { useState } from 'react';
import { Button } from '@/components/ui/button';
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from '@/components/ui/alert-dialog';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { UserX } from 'lucide-react';
import { supabase } from '@/lib/supabaseClient';
import { useAuth } from '@/hooks/useAuth';
import { useToast } from '@/hooks/use-toast';
import { getErrorMessage } from '@/lib/errorHandler';
interface UserBlockButtonProps {
targetUserId: string;
targetUsername: string;
variant?: 'default' | 'outline' | 'ghost';
size?: 'default' | 'sm' | 'lg';
}
export function UserBlockButton({ targetUserId, targetUsername, variant = 'outline', size = 'sm' }: UserBlockButtonProps) {
const { user } = useAuth();
const { toast } = useToast();
const [reason, setReason] = useState('');
const [loading, setLoading] = useState(false);
const handleBlock = async () => {
if (!user) return;
setLoading(true);
try {
const { error } = await supabase
.from('user_blocks')
.insert({
blocker_id: user.id,
blocked_id: targetUserId,
reason: reason.trim() || null
});
if (error) throw error;
toast({
title: 'User blocked',
description: `You have blocked @${targetUsername}. They will no longer be able to interact with your content.`
});
setReason('');
} catch (error: unknown) {
toast({
title: 'Error',
description: getErrorMessage(error),
variant: 'destructive'
});
} finally {
setLoading(false);
}
};
// Don't show block button if user is not logged in or trying to block themselves
if (!user || user.id === targetUserId) {
return null;
}
return (
<AlertDialog>
<AlertDialogTrigger asChild>
<Button variant={variant} size={size}>
<UserX className="w-4 h-4 mr-2" />
Block User
</Button>
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Block @{targetUsername}</AlertDialogTitle>
<AlertDialogDescription>
This user will no longer be able to see your content or interact with you.
You can unblock them at any time from your privacy settings.
</AlertDialogDescription>
</AlertDialogHeader>
<div className="space-y-2">
<Label htmlFor="reason">Reason (optional)</Label>
<Input
id="reason"
placeholder="Why are you blocking this user?"
value={reason}
onChange={(e) => setReason(e.target.value)}
maxLength={200}
/>
</div>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction
onClick={handleBlock}
disabled={loading}
className="bg-destructive hover:bg-destructive/90"
>
{loading ? 'Blocking...' : 'Block User'}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
);
}