From 6089ba11d54f48d75378c626b1f58d0f3a312a75 Mon Sep 17 00:00:00 2001 From: 230419 <230419@epvc.pt> Date: Tue, 12 May 2026 17:11:54 +0100 Subject: [PATCH] save --- src/App.jsx | 199 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 164 insertions(+), 35 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 17933fc..c9c8c52 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -7,7 +7,7 @@ import { PanelLeftClose, PanelLeftOpen, Sparkles, CloudSun, ArrowRight, Droplets, CheckCircle2, PieChart, History, X, Download, Bell, Globe, Filter, ShoppingBag, Share2, - FolderOpen, Tag, Link, Calendar, ChevronLeft, ChevronRight, Users + FolderOpen, Tag, Link, Calendar, ChevronLeft, ChevronRight, ChevronDown, Users, MapPin, Copy } from 'lucide-react'; import { @@ -69,8 +69,11 @@ export default function App() { // Estado da Comunidade const [communitySearchTerm, setCommunitySearchTerm] = useState(''); + const [showRecommended, setShowRecommended] = useState(false); const [communityUsers, setCommunityUsers] = useState([]); const [selectedCommunityUser, setSelectedCommunityUser] = useState(null); + const [selectedUserProfile, setSelectedUserProfile] = useState(null); + const [showInspectModal, setShowInspectModal] = useState(false); const [selectedUserClothes, setSelectedUserClothes] = useState([]); const [selectedUserLooks, setSelectedUserLooks] = useState([]); @@ -433,7 +436,8 @@ export default function App() { username: userProfile.username || '', fullName: userProfile.fullName || '', avatar: userProfile.avatar || null, - isPrivate: userProfile.settings?.isPrivate || false + isPrivate: userProfile.settings?.isPrivate || false, + location: userProfile.location || '' }, { merge: true }).catch(err => { console.error("Erro ao sincronizar perfil público:", err); if (err.code === 'permission-denied') { @@ -441,7 +445,7 @@ export default function App() { } }); } - }, [user, userProfile?.username, userProfile?.fullName, userProfile?.avatar, userProfile?.settings?.isPrivate]); + }, [user, userProfile?.username, userProfile?.fullName, userProfile?.avatar, userProfile?.settings?.isPrivate, userProfile?.location]); // Fetch utilizadores da comunidade useEffect(() => { @@ -452,16 +456,25 @@ export default function App() { const snap = await getDocs(profilesRef); const users = snap.docs.map(d => d.data()).filter(u => u.uid !== user?.uid); - if (communitySearchTerm.trim()) { + if (showRecommended) { + const normalizeLoc = (str) => str ? str.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().trim() : ""; + const myLocation = normalizeLoc(userProfile?.location); + if (myLocation) { + setCommunityUsers(users.filter(u => + normalizeLoc(u.location) === myLocation + )); + } else { + setCommunityUsers([]); + } + } else if (communitySearchTerm.trim()) { let term = communitySearchTerm.trim().toLowerCase(); if (term.startsWith('@')) term = term.substring(1); setCommunityUsers(users.filter(u => { const uname = u.username ? u.username.toLowerCase() : ''; - const fname = u.fullName ? u.fullName.toLowerCase() : ''; - return uname.includes(term) || fname.includes(term); + return uname.includes(term); })); } else { - setCommunityUsers(users); + setCommunityUsers([]); } } catch (err) { console.error("Erro ao buscar comunidade", err); @@ -469,13 +482,14 @@ export default function App() { } }; fetchUsers(); - }, [view, communitySearchTerm, user?.uid]); + }, [view, communitySearchTerm, showRecommended, user?.uid, userProfile?.location]); const viewCommunityUser = async (targetUser) => { setSelectedCommunityUser(targetUser); if (targetUser.isPrivate) { setSelectedUserClothes([]); setSelectedUserLooks([]); + setSelectedUserProfile(null); return; } @@ -489,6 +503,15 @@ export default function App() { const looksCol = collection(db, 'artifacts', appId, 'users', targetUser.uid, 'looks'); const snapLooks = await getDocs(looksCol); setSelectedUserLooks(snapLooks.docs.map(d => ({id: d.id, ...d.data()}))); + + // Profile + const profileDocRef = doc(db, 'artifacts', appId, 'users', targetUser.uid, 'profile', 'data'); + const snapProfile = await getDoc(profileDocRef); + if (snapProfile.exists()) { + setSelectedUserProfile(snapProfile.data()); + } else { + setSelectedUserProfile({}); + } } catch (err) { console.error("Erro ao carregar perfil do utilizador", err); } @@ -1094,7 +1117,8 @@ export default function App() { fullName: fd.get('fullName') || '', dob: dob, bio: fd.get('bio') || '', - location: fd.get('location') || '' + location: fd.get('location') || '', + createdAt: userProfile?.createdAt || new Date().getTime() }, { merge: true }).catch(err => { console.error(err); }); @@ -2126,7 +2150,21 @@ export default function App() {
@{userProfile?.username || user?.email?.split('@')[0] || t('papMode')}
+@{userProfile?.username || user?.email?.split('@')[0] || t('papMode')}
+ +