mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 18:11:12 -05:00
Refactor: Remove photo reordering
This commit is contained in:
@@ -13,7 +13,7 @@ import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import { useToast } from '@/hooks/use-toast';
|
||||
import { ArrowUp, ArrowDown, Trash2, Pencil } from 'lucide-react';
|
||||
import { Trash2, Pencil } from 'lucide-react';
|
||||
import { Card, CardContent } from '@/components/ui/card';
|
||||
|
||||
interface Photo {
|
||||
@@ -75,53 +75,6 @@ export function PhotoManagementDialog({
|
||||
}
|
||||
};
|
||||
|
||||
const movePhoto = async (photoId: string, direction: 'up' | 'down') => {
|
||||
const currentIndex = photos.findIndex((p) => p.id === photoId);
|
||||
if (
|
||||
(direction === 'up' && currentIndex === 0) ||
|
||||
(direction === 'down' && currentIndex === photos.length - 1)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
const newPhotos = [...photos];
|
||||
const targetIndex = direction === 'up' ? currentIndex - 1 : currentIndex + 1;
|
||||
[newPhotos[currentIndex], newPhotos[targetIndex]] = [
|
||||
newPhotos[targetIndex],
|
||||
newPhotos[currentIndex],
|
||||
];
|
||||
|
||||
// Update order_index for both photos
|
||||
const updates = [
|
||||
{ id: newPhotos[currentIndex].id, order_index: currentIndex },
|
||||
{ id: newPhotos[targetIndex].id, order_index: targetIndex },
|
||||
];
|
||||
|
||||
try {
|
||||
for (const update of updates) {
|
||||
const { error } = await supabase
|
||||
.from('photos')
|
||||
.update({ order_index: update.order_index })
|
||||
.eq('id', update.id);
|
||||
|
||||
if (error) throw error;
|
||||
}
|
||||
|
||||
setPhotos(newPhotos);
|
||||
toast({
|
||||
title: 'Success',
|
||||
description: 'Photo order updated',
|
||||
});
|
||||
onUpdate?.();
|
||||
} catch (error) {
|
||||
console.error('Error updating photo order:', error);
|
||||
toast({
|
||||
title: 'Error',
|
||||
description: 'Failed to update photo order',
|
||||
variant: 'destructive',
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const deletePhoto = async (photoId: string) => {
|
||||
@@ -227,7 +180,7 @@ export function PhotoManagementDialog({
|
||||
<DialogHeader>
|
||||
<DialogTitle>Manage Photos</DialogTitle>
|
||||
<DialogDescription>
|
||||
Reorder, edit, or delete photos for this entity
|
||||
Edit or delete photos for this entity
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
@@ -262,45 +215,24 @@ export function PhotoManagementDialog({
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 sm:flex sm:flex-wrap gap-2">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={() => movePhoto(photo.id, 'up')}
|
||||
disabled={index === 0}
|
||||
className="justify-start sm:justify-center"
|
||||
>
|
||||
<ArrowUp className="w-4 h-4 mr-2" />
|
||||
<span className="sm:hidden">Move Up</span>
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={() => movePhoto(photo.id, 'down')}
|
||||
disabled={index === photos.length - 1}
|
||||
className="justify-start sm:justify-center"
|
||||
>
|
||||
<ArrowDown className="w-4 h-4 mr-2" />
|
||||
<span className="sm:hidden">Move Down</span>
|
||||
</Button>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={() => setEditingPhoto(photo)}
|
||||
className="justify-start sm:justify-center"
|
||||
className="flex-1 sm:flex-initial"
|
||||
>
|
||||
<Pencil className="w-4 h-4 mr-2" />
|
||||
<span className="sm:hidden">Edit Caption</span>
|
||||
<span className="hidden sm:inline">Edit</span>
|
||||
Edit
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="destructive"
|
||||
onClick={() => deletePhoto(photo.id)}
|
||||
className="justify-start sm:justify-center"
|
||||
className="flex-1 sm:flex-initial"
|
||||
>
|
||||
<Trash2 className="w-4 h-4 mr-2" />
|
||||
<span className="sm:hidden">Delete Photo</span>
|
||||
Delete
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user