-
Notifications
You must be signed in to change notification settings - Fork 12
View Poster's Profile #95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -288,9 +288,18 @@ const ItemDetailPage = () => { | |||||
| <span className="font-medium">Posted:</span> | ||||||
| {` ${new Date(item.date).toLocaleString()}`} | ||||||
| </p> | ||||||
| <p> | ||||||
| <p className="flex items-center gap-1"> | ||||||
| <span className="font-medium">Reporter:</span> | ||||||
| {` ${userInfo?.name || 'Unknown User'}`} | ||||||
| {userInfo?.id ? ( | ||||||
| <Link | ||||||
| to={`/profile/${userInfo.id}`} | ||||||
| className="text-emerald-600 hover:text-emerald-700 hover:underline transition-colors font-medium" | ||||||
| > | ||||||
| {userInfo.name} | ||||||
|
||||||
| {userInfo.name} | |
| {userInfo?.name || 'Unknown User'} |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,177 @@ | ||||||||
| import React, { useState, useEffect } from 'react' | ||||||||
| import { useParams, useNavigate } from 'react-router-dom' | ||||||||
| import { doc, getDoc, collection, query, where, onSnapshot, orderBy } from 'firebase/firestore' | ||||||||
| import { db } from '../firebase/config' | ||||||||
| import { Card, CardContent, CardHeader, CardTitle } from '../components/ui/card' | ||||||||
| import { ArrowLeft } from 'lucide-react' | ||||||||
| import ItemCard from '../components/ItemCard' | ||||||||
| import { normalizeFirestoreItem } from '../lib/utils' | ||||||||
|
|
||||||||
| const PublicProfile = () => { | ||||||||
| const { userId } = useParams() | ||||||||
| const navigate = useNavigate() | ||||||||
| const [userData, setUserData] = useState(null) | ||||||||
| const [userPosts, setUserPosts] = useState([]) | ||||||||
| const [loading, setLoading] = useState(true) | ||||||||
| const [error, setError] = useState(null) | ||||||||
|
|
||||||||
| // Fetch user data | ||||||||
| useEffect(() => { | ||||||||
| if (!userId) { | ||||||||
| setError('No user ID provided') | ||||||||
| setLoading(false) | ||||||||
| return | ||||||||
| } | ||||||||
|
|
||||||||
| const fetchUserData = async () => { | ||||||||
| try { | ||||||||
| const userDocRef = doc(db, 'users', userId) | ||||||||
| const userDocSnap = await getDoc(userDocRef) | ||||||||
|
|
||||||||
| if (!userDocSnap.exists()) { | ||||||||
| setError('User not found') | ||||||||
| setLoading(false) | ||||||||
| return | ||||||||
| } | ||||||||
|
|
||||||||
| const data = userDocSnap.data() | ||||||||
| setUserData(data) | ||||||||
| } catch (err) { | ||||||||
| console.error('Error fetching user data:', err) | ||||||||
| setError('Failed to load user profile') | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| fetchUserData() | ||||||||
| }, [userId]) | ||||||||
|
|
||||||||
| // Fetch user posts with real-time listener (exactly like Feed page) | ||||||||
| useEffect(() => { | ||||||||
| if (!userId) return | ||||||||
|
|
||||||||
| setLoading(true) | ||||||||
| setError(null) | ||||||||
|
|
||||||||
| try { | ||||||||
| const itemsRef = collection(db, 'items') | ||||||||
| const userDocRef = doc(db, 'users', userId) | ||||||||
| const itemsQuery = query( | ||||||||
| itemsRef, | ||||||||
| where('postedBy', '==', userDocRef), | ||||||||
| orderBy('date', 'desc') | ||||||||
| ) | ||||||||
|
Comment on lines
+56
to
+62
|
||||||||
|
|
||||||||
| const unsubscribe = onSnapshot( | ||||||||
| itemsQuery, | ||||||||
| (snapshot) => { | ||||||||
| const fetchedItems = snapshot.docs.map((doc) => | ||||||||
| normalizeFirestoreItem(doc.data() || {}, doc.id) | ||||||||
| ) | ||||||||
| setUserPosts(fetchedItems) | ||||||||
|
||||||||
| setUserPosts(fetchedItems) | |
| const filteredItems = fetchedItems.filter(item => item.status !== 'resolved') | |
| setUserPosts(filteredItems) |
Copilot
AI
Oct 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If userData.name is missing, the alt text becomes "undefined's profile". Provide a meaningful fallback, e.g., alt={userData?.name ? ${userData.name}'s profile : 'Profile picture'}.
| alt={`${userData.name}'s profile`} | |
| alt={userData?.name ? `${userData.name}'s profile` : 'Profile picture'} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] status?.toLowerCase() is computed multiple times. Cache it once to simplify and avoid repeated calls, e.g., const status = itemData.status?.toLowerCase(); then compare against status in both the filter and normalization.