Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
9cd4e69
chnaged route
Austin616 Sep 10, 2025
0e2d0d9
updated commit form
Austin616 Sep 10, 2025
7e60fc1
feat: updated homepage as designed in the figma
Austin616 Oct 16, 2025
c1db8d5
Merge branch 'Longhorn-Developers:main' into main
Austin616 Oct 16, 2025
b6b81bd
fix: fixing stylign inconsitencies
Austin616 Oct 16, 2025
6fb9a8b
Merge branch 'main' of https://github.com/Austin616/utmarketplace
Austin616 Oct 16, 2025
d30b107
fix: fixing styling consistencies
Austin616 Oct 17, 2025
ecde1f7
fix: removed the analytics route in the admin page
Austin616 Oct 19, 2025
c4b9971
feat: updated auth page
Austin616 Oct 19, 2025
64e29ff
fix: use ut-orange color
Austin616 Oct 19, 2025
104234e
fix: build error fix
Austin616 Oct 19, 2025
e5003ae
Merge branch 'main' into main
Austin616 Oct 19, 2025
bcfee98
Merge branch 'Longhorn-Developers:main' into main
Austin616 Oct 19, 2025
f16ca1a
feat: terms and condition before sign up
Austin616 Oct 19, 2025
17d3706
feat: made terms and condition route to fetch and update through admi…
Austin616 Oct 20, 2025
460135d
feat: admin can save the new terms and post to the endpoint. Only admin
Austin616 Oct 20, 2025
8bfe983
Merge branch 'main' into main
Austin616 Oct 20, 2025
9f09df9
Merge branch 'Longhorn-Developers:main' into main
Austin616 Oct 20, 2025
2e0db22
feat: not logged in component
Austin616 Oct 23, 2025
9d6a7d5
Merge branch 'main' of https://github.com/Austin616/utmarketplace
Austin616 Oct 23, 2025
25095ed
fix:fix messaging to correctly nav to the correct place
Austin616 Nov 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 83 additions & 19 deletions app/messages/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,22 @@ const MessagesPage = () => {
setLoading(true);
const conversations = await MessageService.getConversations(user.id);
setConversations(conversations);
// Clear temporary conversation when updating conversations
setTempConversation(null);
// Only clear temporary conversation if the selected conversation is now in the list
if (selectedConversation) {
const conversationKey = selectedConversation;
const exists = conversations.some(
(c) => c.user_id + ":" + c.listing_id === conversationKey
);
if (exists) {
setTempConversation(null);
}
}
} catch (error) {
dbLogger.error('Error fetching conversations', error);
} finally {
setLoading(false);
}
}, [user]);
}, [user, selectedConversation]);

const fetchMessages = useCallback(async (conversationKey: string) => {
if (!user?.id) return;
Expand Down Expand Up @@ -202,30 +210,75 @@ const MessagesPage = () => {
fetchMessages(selectedConversation);
}, [selectedConversation, user, authLoading, fetchMessages]);

// Handle ?user= param for direct general chat
useEffect(() => {
if (!user?.id) return;
const targetUserId = searchParams.get("user");
if (targetUserId) {
(async () => {
try {
// Check if user is trying to chat with themselves
if (targetUserId === user.id) {
dbLogger.info('User trying to chat with themselves');
return;
}

// Fetch user data
const { data: userData, error: userError } = await supabase
.from("users")
.select("id, display_name, profile_image_url")
.eq("id", targetUserId)
.single();

if (userError || !userData) {
dbLogger.error('Failed to fetch user for chat', userError);
return;
}

// Check if a conversation already exists (general chat)
const existingMessages = await MessageService.getMessages({
userId: user.id,
otherUserId: targetUserId,
listingId: null
});

// Create a temporary conversation object for the chat window
const tempConv: Conversation = {
user_id: targetUserId,
user_name: userData.display_name || 'Unknown User',
user_image: userData.profile_image_url || undefined,
listing_id: "general",
listing_title: "",
last_message: existingMessages.length > 0 ? existingMessages[existingMessages.length - 1].content : '',
last_message_time: existingMessages.length > 0 ? existingMessages[existingMessages.length - 1].created_at : new Date().toISOString(),
unread_count: 0
};

setTempConversation(tempConv);
setSelectedConversation(targetUserId + ":general");
} catch (error) {
dbLogger.error('Error setting up user chat', error);
}
})();
}
}, [user, searchParams]);

// Handle ?listing= param for direct listing chat
useEffect(() => {
if (!user?.id) return;
const listingId = searchParams.get("listing");
if (listingId) {
(async () => {
try {
// We'll need to implement a listing service for this, but for now use basic query
const { data: listing, error } = await supabase
// Fetch listing data
const { data: listing, error: listingError } = await supabase
.from("listings")
.select(`
id,
user_id,
title,
user:user_settings!user_id(
display_name,
profile_image_url
)
`)
.select("id, user_id, title")
.eq("id", listingId)
.single();

if (error || !listing) {
dbLogger.error('Failed to fetch listing for chat', error);
if (listingError || !listing) {
dbLogger.error('Failed to fetch listing for chat', listingError);
return;
}

Expand All @@ -234,6 +287,18 @@ const MessagesPage = () => {
return;
}

// Fetch user data separately
const { data: userData, error: userError } = await supabase
.from("users")
.select("id, display_name, profile_image_url")
.eq("id", listing.user_id)
.single();

if (userError || !userData) {
dbLogger.error('Failed to fetch user for chat', userError);
return;
}

// Check if a conversation already exists for this listing
const existingMessages = await MessageService.getMessages({
userId: user.id,
Expand All @@ -242,11 +307,10 @@ const MessagesPage = () => {
});

// Create a temporary conversation object with user data for the chat window
const userData = Array.isArray(listing.user) ? listing.user[0] : listing.user;
const tempConv: Conversation = {
user_id: listing.user_id,
user_name: userData?.display_name || 'Unknown User',
user_image: userData?.profile_image_url || undefined,
user_name: userData.display_name || 'Unknown User',
user_image: userData.profile_image_url || undefined,
listing_id: listingId,
listing_title: listing.title,
last_message: existingMessages.length > 0 ? existingMessages[existingMessages.length - 1].content : '',
Expand Down
6 changes: 4 additions & 2 deletions app/profile/[userId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const PublicProfile = () => {
const [showRatingForm, setShowRatingForm] = useState(false);
const [userName, setUserName] = useState<string | null>(null);
const [userEmail, setUserEmail] = useState<string | null>(null);
const [profileUserId, setProfileUserId] = useState<string | null>(null);
const [userHasRated, setUserHasRated] = useState(false);
const [displayName, setDisplayName] = useState<string | null>(null);
const [profileImage, setProfileImage] = useState<string | null>(null);
Expand Down Expand Up @@ -54,6 +55,7 @@ const PublicProfile = () => {
setProfileImage(userData.profile_image_url || null);
setBio(userData.bio || null);
setUserEmail(userData.email);
setProfileUserId(userData.id);
setUserName(userData.display_name || userData.email?.split('@')[0] || 'User');

// Fetch user's listings by user_id
Expand Down Expand Up @@ -253,10 +255,10 @@ const PublicProfile = () => {
</div>
</div>
{/* Action Buttons */}
{user?.id && user.id !== userEmail && (
{user?.id && user.id !== profileUserId && (
<div className="mt-6 flex gap-3">
<button
onClick={() => router.push(`/messages?user=${userEmail}`)}
onClick={() => router.push(`/messages?user=${profileUserId}`)}
className="flex items-center gap-2 px-4 py-2 rounded-lg border border-[#bf5700] text-[#bf5700] text-sm hover:bg-[#bf5700] hover:text-white transition"
>
<MessageCircle size={16} />
Expand Down