From 2608eff482caedab5b1eb397946a302ad61aee47 Mon Sep 17 00:00:00 2001 From: 230419 <230419@epvc.pt> Date: Wed, 13 May 2026 10:30:08 +0100 Subject: [PATCH] aaa --- src/App.jsx | 205 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 202 insertions(+), 3 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index c9c8c52..db73cf7 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -76,6 +76,8 @@ export default function App() { const [showInspectModal, setShowInspectModal] = useState(false); const [selectedUserClothes, setSelectedUserClothes] = useState([]); const [selectedUserLooks, setSelectedUserLooks] = useState([]); + const [inspectingCommunityLook, setInspectingCommunityLook] = useState(null); + const [inspectingCommunityItem, setInspectingCommunityItem] = useState(null); // Estado para Partilha de Looks const sharedLookRef = useRef(''); @@ -852,6 +854,84 @@ export default function App() { } }; + const copyCommunityItem = async (item) => { + if (!user) return; + setToastMessage(t('copying') || 'A copiar...'); + try { + const clothesCol = collection(db, 'artifacts', appId, 'users', user.uid, 'clothes'); + await addDoc(clothesCol, { + name: item.name, + category: item.category, + color: item.color, + imageUrl: item.imageUrl, + status: 'active', + favorite: false, + createdAt: new Date().getTime(), + updatedAt: new Date().getTime(), + }); + setToastMessage(t('itemCopied') || 'Peça copiada para o seu armário!'); + setTimeout(() => setToastMessage(null), 3000); + } catch (err) { + console.error('Erro ao copiar peça:', err); + setToastMessage('Erro ao copiar peça.'); + setTimeout(() => setToastMessage(null), 3000); + } + }; + + const copyCommunityLook = async (look) => { + if (!user || !selectedCommunityUser) return; + setToastMessage(t('copying') || 'A copiar...'); + try { + const newItemIds = []; + for (const itemId of look.items) { + const item = selectedUserClothes.find(c => c.id === itemId); + if (item) { + const clothesCol = collection(db, 'artifacts', appId, 'users', user.uid, 'clothes'); + const newItemRef = await addDoc(clothesCol, { + name: item.name, + category: item.category, + color: item.color, + imageUrl: item.imageUrl, + status: 'active', + favorite: false, + createdAt: new Date().getTime(), + updatedAt: new Date().getTime(), + }); + newItemIds.push(newItemRef.id); + } + } + const looksCol = collection(db, 'artifacts', appId, 'users', user.uid, 'looks'); + await addDoc(looksCol, { + name: look.name, + items: newItemIds, + createdAt: new Date().getTime(), + updatedAt: new Date().getTime(), + }); + + // Notify the owner via coleção pública (inboxNotifications) + try { + const inboxCol = collection(db, 'artifacts', appId, 'inboxNotifications'); + await addDoc(inboxCol, { + type: 'look_copied', + recipientUid: selectedCommunityUser.uid, + lookName: look.name, + copiedByEmail: userProfile?.username || user.email || 'Alguém', + createdAt: new Date().getTime(), + read: false + }); + } catch (notifErr) { + console.error('Não foi possível enviar notificação ao dono do look:', notifErr); + } + + setToastMessage(t('lookCopied') || 'Look copiado para o seu armário!'); + setTimeout(() => setToastMessage(null), 3000); + } catch (err) { + console.error('Erro ao copiar look:', err); + setToastMessage('Erro ao copiar look.'); + setTimeout(() => setToastMessage(null), 3000); + } + }; + // Copiar o look partilhado para o armário do utilizador atual const copySharedLook = async () => { if (!user || !sharedLookData) return; @@ -2371,7 +2451,15 @@ export default function App() { c.id === look.items[0]).imageUrl} className="w-full h-full object-cover group-hover:scale-110 transition-transform duration-700" alt="Look" /> )}
- {look.name} + {look.name} +
+ + +
))} @@ -2382,8 +2470,16 @@ export default function App() {

{t('userCloset')} ({selectedUserClothes.length})

{selectedUserClothes.map(item => ( -
- Item +
+ Item +
+ + +
))}
@@ -3083,6 +3179,109 @@ export default function App() {
)} + + {/* Modal de Inspecionar Look da Comunidade */} + {inspectingCommunityLook && ( +
setInspectingCommunityLook(null)}> +
e.stopPropagation()} + > +
+
+
+
+
+
+ +
+ {t('inspectOutfit') || 'Inspecionar Outfit'} +
+ +
+

{inspectingCommunityLook.name}

+

{inspectingCommunityLook.items?.length || 0} peça{(inspectingCommunityLook.items?.length !== 1) ? 's' : ''}

+
+
+ +
+

{t('includedPieces') || 'Peças incluídas'}

+
+ {(inspectingCommunityLook.items || []).map((itemId, idx) => { + const item = selectedUserClothes.find(c => c.id === itemId); + if (!item) return null; + return ( +
+
+ {item.name} +
+
+ {item.name} +
+
+ ); + })} +
+ +
+ {(inspectingCommunityLook.items || []).map((itemId, idx) => { + const item = selectedUserClothes.find(c => c.id === itemId); + if (!item) return null; + return ( +
+ {item.name} + {item.category} +
+ ); + })} +
+ + +
+
+
+ )} + + {/* Modal de Inspecionar Peça da Comunidade */} + {inspectingCommunityItem && ( +
setInspectingCommunityItem(null)}> +
e.stopPropagation()} + > +
+ Item + +
+
+

{inspectingCommunityItem.name}

+
+ {inspectingCommunityItem.category} + + {inspectingCommunityItem.color} +
+ +
+
+
+ )}
); }