diff --git a/src/App.jsx b/src/App.jsx index 1f766f1..2744b03 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -44,6 +44,7 @@ export default function App() { // Estado para criação de Looks const [selectedForLook, setSelectedForLook] = useState([]); + const [editingLook, setEditingLook] = useState(null); // Perfil do Utilizador const [userProfile, setUserProfile] = useState({}); @@ -295,19 +296,27 @@ export default function App() { } }; - const createLook = async (e) => { + const saveLook = async (e) => { e.preventDefault(); if (selectedForLook.length < 2) return; setLoading(true); const fd = new FormData(e.target); + const lookData = { + name: fd.get('lookName'), + items: selectedForLook, + updatedAt: new Date().getTime() + }; try { - const looksCol = collection(db, 'artifacts', appId, 'users', user.uid, 'looks'); - await addDoc(looksCol, { - name: fd.get('lookName'), - items: selectedForLook, - createdAt: new Date().getTime() - }); + if (editingLook) { + const docRef = doc(db, 'artifacts', appId, 'users', user.uid, 'looks', editingLook.id); + await updateDoc(docRef, lookData); + } else { + lookData.createdAt = new Date().getTime(); + const looksCol = collection(db, 'artifacts', appId, 'users', user.uid, 'looks'); + await addDoc(looksCol, lookData); + } setSelectedForLook([]); + setEditingLook(null); setView('outfits'); } catch (e) { console.error(e); } finally { setLoading(false); } @@ -370,6 +379,49 @@ export default function App() { finally { setLoading(false); } }; + const handleProfileImageUpload = (e) => { + const file = e.target.files[0]; + if (!file || !user) return; + + const reader = new FileReader(); + reader.onload = (event) => { + const img = new Image(); + img.onload = async () => { + const canvas = document.createElement('canvas'); + const MAX_SIZE = 400; + let width = img.width; + let height = img.height; + + if (width > height) { + if (width > MAX_SIZE) { + height *= MAX_SIZE / width; + width = MAX_SIZE; + } + } else { + if (height > MAX_SIZE) { + width *= MAX_SIZE / height; + height = MAX_SIZE; + } + } + + canvas.width = width; + canvas.height = height; + const ctx = canvas.getContext('2d'); + ctx.drawImage(img, 0, 0, width, height); + const base64Data = canvas.toDataURL('image/jpeg', 0.8); + + try { + const profileDoc = doc(db, 'artifacts', appId, 'users', user.uid, 'profile', 'data'); + await setDoc(profileDoc, { avatar: base64Data }, { merge: true }); + } catch (err) { + console.error("Error uploading image:", err); + } + }; + img.src = event.target.result; + }; + reader.readAsDataURL(file); + }; + const saveProfile = async (e) => { e.preventDefault(); setSavingProfile(true); @@ -478,8 +530,12 @@ export default function App() {
- @@ -629,22 +685,22 @@ export default function App() { {item.name} -
-
- - - +
+
+ + +
-
{item.category}
-
+
{item.category}
+
-
+

{item.name}

@@ -695,9 +751,11 @@ export default function App() {
-

{t('createNewLook')}

-
- +

+ {editingLook ? t('editLook') || 'Editar Look' : t('createNewLook')} +

+ +

{t('selectedPieces')} ({selectedForLook.length})

@@ -706,16 +764,21 @@ export default function App() { return (
- +
); })} {selectedForLook.length === 0 &&

{t('selectPieces')}

}
- +
+ {editingLook && ( + + )} + +
@@ -742,7 +805,10 @@ export default function App() {

{look.name}

{look.items.length} {t('pieces')} • {new Date(look.createdAt).toLocaleDateString()}

- +
+ + +
{look.items.map(itemId => { @@ -811,8 +877,17 @@ export default function App() {
-
- {(userProfile?.fullName?.[0] || userProfile?.username?.[0] || user?.email?.[0] || 'U').toUpperCase()} +
+ {userProfile?.avatar ? ( + Profile + ) : ( + {(userProfile?.fullName?.[0] || userProfile?.username?.[0] || user?.email?.[0] || 'U').toUpperCase()} + )} +

{userProfile?.fullName || t('yourAccount')}