Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions src/app/messages/components/ChatWindow.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"use client"
import React, { useEffect, useRef } from 'react';
import React, { useEffect, useRef, useCallback } from 'react';
import { useAppDispatch, useAppSelector } from '@/store/hooks';
import { setMessages, setActiveConversation, markMessagesAsRead } from '@/store/slices/chatSlice';
import { messagingAPI } from '@/lib/api/messaging.api';
Expand All @@ -16,7 +16,7 @@ export const ChatWindow: React.FC<ChatWindowProps> = ({ conversationId }) => {
const dispatch = useAppDispatch();
const scrollRef = useRef<HTMLDivElement>(null);

const { messages, conversations, activeConversationId } = useAppSelector((state) => state.chat);
const { messages, conversations, latestIncomingMessage, activeConversationId } = useAppSelector((state) => state.chat);
const { user: currentUser } = useAppSelector((state) => state.auth);

// `/messages` sets active chat via Redux only; `/messages/[conversationId]` passes the id prop.
Expand Down
5 changes: 5 additions & 0 deletions src/components/layout/Dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ export default function DashboardLayout({ children }: { children: React.ReactNod
const initAuthAndFetch = async () => {
// Hydrate Redux Token from LocalStorage for apiClient
const savedToken = localStorage.getItem('accessToken');

if (!savedToken && !token) {
router.push("/auth/signin");
return;
}
if (savedToken && !token) {
dispatch(setToken(savedToken));
}
Expand Down
12 changes: 6 additions & 6 deletions src/components/profile/PlatformUsernameInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ export function PlatformUsernameInput({
);

const handleBlur = () => {
if (validateOnBlur && value.trim()) {
// if (validateOnBlur && value.trim()) {
setShouldValidate(true);
}
// }
};
Comment on lines 53 to 57
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handleBlur currently ignores validateOnBlur and whether the input is non-empty, because the guard is commented out. This changes behavior for callers that pass validateOnBlur={false} and also triggers validation state even when the field is blank. Please restore the conditional (or implement an equivalent) so validation only enables when intended.

Copilot uses AI. Check for mistakes.

const handleChange = (newValue: string) => {
Expand Down Expand Up @@ -139,7 +139,7 @@ export function PlatformUsernameInput({
</div>

{/* Status message */}
<AnimatePresence mode="wait">
{/* <AnimatePresence mode="wait">
{shouldValidate && getStatusMessage() && (
<motion.div
initial={{ opacity: 0, y: -5 }}
Comment on lines 141 to 145
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Large UI blocks (status message + preview card) are commented out in JSX. Keeping dead/commented UI in production code reduces maintainability and also tends to create unused imports/props over time. Prefer either re-enabling these blocks, removing them entirely, or gating them behind a real feature/debug flag so the component remains clean.

Copilot uses AI. Check for mistakes.
Expand All @@ -157,10 +157,10 @@ export function PlatformUsernameInput({
<span>{getStatusMessage()}</span>
</motion.div>
)}
</AnimatePresence>
</AnimatePresence> */}

{/* Clean Preview Card */}
<AnimatePresence>
{/* <AnimatePresence>
{showPreview && data && (
<motion.div
initial={{ opacity: 0, y: -10 }}
Expand Down Expand Up @@ -203,7 +203,7 @@ export function PlatformUsernameInput({
</div>
</motion.div>
)}
</AnimatePresence>
</AnimatePresence> */}
</div>
);
}
Expand Down
9 changes: 9 additions & 0 deletions src/hooks/features/useChatSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useAppDispatch, useAppSelector } from '@/store/hooks';
import { messagingSocketService } from '@/lib/socket/messagingSocket';
import {
addMessage,
setLatestIncomingMessage,
setTypingStatus,
markMessagesAsRead,
deleteMessageLocal,
Expand Down Expand Up @@ -72,6 +73,14 @@ export const useChatSocket = () => {
dispatch(addMessage(message));

const isFromMe = message.sender._id === currentUserId;
if (!isFromMe) {
dispatch(setLatestIncomingMessage({
conversationId,
messageId: message._id,
createdAt: message.createdAt,
}));
}

const isInActiveChat = conversationId === activeId;

if (!isFromMe && !isInActiveChat && currentUserId) {
Expand Down
Loading