diff --git a/components/CollectionSelectionModal.js b/components/CollectionSelectionModal.js index c5691f5..5014ee4 100644 --- a/components/CollectionSelectionModal.js +++ b/components/CollectionSelectionModal.js @@ -23,7 +23,7 @@ export default function CollectionSelectionModal({ const fetchCollections = async () => { setLoading(true); try { - const response = await fetch('/api/collections'); + const response = await fetch('/api/collections?excludeSystem=true'); if (response.ok) { const data = await response.json(); diff --git a/pages/api/cards/[id]/ownership.js b/pages/api/cards/[id]/ownership.js index cf1405e..0dff046 100644 --- a/pages/api/cards/[id]/ownership.js +++ b/pages/api/cards/[id]/ownership.js @@ -73,12 +73,11 @@ export default async function handler(req, res) { // Sync with "All My Cards" collection const collectionCardResult = await sql` - INSERT INTO collection_cards (collection_id, card_id, quantity, created_at, updated_at) - VALUES (${collectionId}, ${cardId}, ${cardQuantity}, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP) + INSERT INTO collection_cards (collection_id, card_id, quantity, created_at) + VALUES (${collectionId}, ${cardId}, ${cardQuantity}, CURRENT_TIMESTAMP) ON CONFLICT (collection_id, card_id) DO UPDATE SET - quantity = ${cardQuantity}, - updated_at = CURRENT_TIMESTAMP + quantity = ${cardQuantity} RETURNING * `; diff --git a/pages/api/collections.js b/pages/api/collections.js index 17f026d..f567e02 100644 --- a/pages/api/collections.js +++ b/pages/api/collections.js @@ -23,6 +23,7 @@ export default async function handler(req, res) { } const currentUserId = user.userId; + const { excludeSystem } = req.query; // New parameter to exclude system collections // Get collections based on ownership, collaboration, or shared access (no public discovery) const result = await sql` @@ -43,8 +44,8 @@ export default async function handler(req, res) { LEFT JOIN cards ON cc.card_id = cards.id LEFT JOIN collection_permissions cp ON c.id = cp.collection_id AND cp.user_id = ${currentUserId} AND cp.status = 'active' WHERE - c.user_id = ${currentUserId} OR - cp.id IS NOT NULL + (c.user_id = ${currentUserId} OR cp.id IS NOT NULL) + ${excludeSystem === 'true' ? sql`AND (c.is_system_collection IS NULL OR c.is_system_collection = false)` : sql``} GROUP BY c.id, u.email, cp.role ORDER BY c.updated_at DESC `; diff --git a/pages/collections.js b/pages/collections.js index 23b814e..41e46a9 100644 --- a/pages/collections.js +++ b/pages/collections.js @@ -497,9 +497,20 @@ export default function Collections() { {/* System collection indicator */} {collection.isSystemCollection && ( - - 🔒 System - +