mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-24 22:11:13 -05:00
Refactor: Implement logging and JSONB cleanup
This commit is contained in:
@@ -3,6 +3,7 @@ import { UserTopList, UserTopListItem, Park, Ride, Company } from "@/types/datab
|
||||
import { supabase } from "@/integrations/supabase/client";
|
||||
import { Link } from "react-router-dom";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { handleError } from "@/lib/errorHandler";
|
||||
|
||||
interface ListDisplayProps {
|
||||
list: UserTopList;
|
||||
@@ -31,7 +32,10 @@ export function ListDisplay({ list }: ListDisplayProps) {
|
||||
.order("position", { ascending: true });
|
||||
|
||||
if (itemsError) {
|
||||
console.error("Error fetching items:", itemsError);
|
||||
handleError(itemsError, {
|
||||
action: 'Fetch List Items',
|
||||
metadata: { listId: list.id }
|
||||
});
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import { Plus, Trash2, Edit, Eye, EyeOff } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
import { ListItemEditor } from "./ListItemEditor";
|
||||
import { ListDisplay } from "./ListDisplay";
|
||||
import { handleError } from "@/lib/errorHandler";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
@@ -62,8 +63,10 @@ export function UserListManager() {
|
||||
.order("created_at", { ascending: false });
|
||||
|
||||
if (error) {
|
||||
toast.error("Failed to load lists");
|
||||
console.error(error);
|
||||
handleError(error, {
|
||||
action: 'Load User Lists',
|
||||
userId: user.id
|
||||
});
|
||||
} else {
|
||||
// Map Supabase data to UserTopList interface
|
||||
const mappedLists: UserTopList[] = (data || []).map((list: any) => ({
|
||||
@@ -101,8 +104,11 @@ export function UserListManager() {
|
||||
.single();
|
||||
|
||||
if (error) {
|
||||
toast.error("Failed to create list");
|
||||
console.error(error);
|
||||
handleError(error, {
|
||||
action: 'Create List',
|
||||
userId: user.id,
|
||||
metadata: { title: newListTitle }
|
||||
});
|
||||
} else {
|
||||
toast.success("List created successfully");
|
||||
const newList: UserTopList = {
|
||||
@@ -132,8 +138,11 @@ export function UserListManager() {
|
||||
.eq("id", listId);
|
||||
|
||||
if (error) {
|
||||
toast.error("Failed to delete list");
|
||||
console.error(error);
|
||||
handleError(error, {
|
||||
action: 'Delete List',
|
||||
userId: user?.id,
|
||||
metadata: { listId }
|
||||
});
|
||||
} else {
|
||||
toast.success("List deleted");
|
||||
setLists(lists.filter(l => l.id !== listId));
|
||||
@@ -147,8 +156,11 @@ export function UserListManager() {
|
||||
.eq("id", list.id);
|
||||
|
||||
if (error) {
|
||||
toast.error("Failed to update list");
|
||||
console.error(error);
|
||||
handleError(error, {
|
||||
action: 'Toggle List Visibility',
|
||||
userId: user?.id,
|
||||
metadata: { listId: list.id }
|
||||
});
|
||||
} else {
|
||||
toast.success(`List is now ${!list.is_public ? "public" : "private"}`);
|
||||
setLists(lists.map(l =>
|
||||
|
||||
Reference in New Issue
Block a user