Skip to content

Refactor chat functionality for message tracking and fetching optimization#14

Closed
Prolomon wants to merge 2 commits intomainfrom
debug
Closed

Refactor chat functionality for message tracking and fetching optimization#14
Prolomon wants to merge 2 commits intomainfrom
debug

Conversation

@Prolomon
Copy link
Copy Markdown
Collaborator

@Prolomon Prolomon commented Apr 1, 2026

Messaging and Chat Improvements:

  • The ChatWindow component now listens for the latest incoming message and automatically fetches new messages for the active conversation, ensuring real-time updates without manual refresh. This is achieved by adding a latestIncomingMessage field to the Redux store and updating the relevant useEffect hooks to trigger message fetching when new messages arrive.

Authentication Handling:

  • The dashboard layout now redirects unauthenticated users to the sign-in page if neither a saved token nor a Redux token is present, improving security and user flow. (src/components/layout/Dashboard/Dashboard.tsx)

Platform Data Hooks Refactor and Debugging:

  • The usePlatformData and useMultiplePlatformData hooks have been refactored for improved code style, error handling, and debugging. Many API calls and logging lines are now commented out, and placeholder data is returned for development purposes. Error handling for API quota and endpoint availability has been enhanced, with more descriptive logging and error states.

UI/UX Adjustments (Temporary):

  • In the PlatformUsernameInput component, status message and preview card animations have been commented out, likely for debugging or development purposes.

Copilot AI review requested due to automatic review settings April 1, 2026 21:46
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 1, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
hyperbuds-app Ready Ready Preview, Comment Apr 1, 2026 9:51pm

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors messaging to better track incoming socket messages and trigger conversation refreshes, while also tightening authentication redirects and adjusting platform data fetching behavior.

Changes:

  • Added latestIncomingMessage to the chat Redux slice and dispatch it on incoming socket messages; ChatWindow now refetches messages when a new message arrives for the active conversation.
  • Updated DashboardLayout to redirect unauthenticated users to /auth/signin when no saved token and no Redux token are present.
  • Adjusted API/socket infrastructure (Axios timeout + error code exposure, socket URL change) and refactored platform data hooks with placeholder behavior and commented-out UI/animations.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/store/slices/chatSlice.ts Adds latestIncomingMessage field + setter action to Redux chat state.
src/hooks/features/useChatSocket.ts Dispatches setLatestIncomingMessage on inbound (non-self) messages.
src/app/messages/components/ChatWindow.tsx Adds fetchMessages callback and refetches when latestIncomingMessage matches the active conversation.
src/components/layout/Dashboard/Dashboard.tsx Redirects to sign-in when no token exists (localStorage + Redux).
src/hooks/features/usePlatformData.ts Refactors hooks; single-platform hook currently returns placeholder data instead of fetching.
src/components/profile/PlatformUsernameInput.tsx Disables blur guard + comments out status/preview animations (temporary UI changes).
src/lib/api/client.ts Adds Axios timeout and includes error.code in normalized errors.
src/lib/socket/events.ts Changes socket base URL (currently hardcoded).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +99 to +104
console.log(`✅ Successfully fetched ${platform} data:`);
setData({
platform: platform,
username: username,
displayName: username, // Placeholder - replace with actual display name from API
profileImage: "string",
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.

usePlatformData no longer performs any network request and unconditionally sets placeholder UnifiedPlatformData (e.g., verified: true, profileImage: "string"). This will make username validation always succeed and can lead to incorrect UI/logic downstream. Please restore the real fetch (or gate placeholder behavior behind an explicit dev flag) and ensure the hook returns an error/null data when the username can’t be verified.

Copilot uses AI. Check for mistakes.
Comment on lines 53 to 57
const handleBlur = () => {
if (validateOnBlur && value.trim()) {
// if (validateOnBlur && value.trim()) {
setShouldValidate(true);
}
// }
};
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.
Comment on lines 141 to 145
{/* Status message */}
<AnimatePresence mode="wait">
{/* <AnimatePresence mode="wait">
{shouldValidate && getStatusMessage() && (
<motion.div
initial={{ opacity: 0, y: -5 }}
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.
Comment on lines 58 to 64
(a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime()
);

useEffect(() => {
if (scrollRef.current) {
scrollRef.current.scrollTop = scrollRef.current.scrollHeight;
}
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.

The latestIncomingMessage effect can trigger an immediate second fetchMessages() on mount (or on conversation switch) when latestIncomingMessage.conversationId === activeId, duplicating the initial fetch effect. Consider tracking the last fetched/processed messageId per conversation (or clearing latestIncomingMessage after handling) to avoid redundant network calls.

Copilot uses AI. Check for mistakes.

const URL = 'http://localhost:4000';
// const URL = 'http://localhost:4000';
const URL = 'https://app.hyperbuds.com';
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.

Socket server URL is hardcoded to https://app.hyperbuds.com (and localhost is commented out). This makes local/dev/staging configuration brittle and risks pointing the client at the wrong host. Please switch to an environment variable (e.g., NEXT_PUBLIC_SOCKET_URL) with a sensible fallback.

Suggested change
const URL = 'https://app.hyperbuds.com';
const URL = process.env.NEXT_PUBLIC_SOCKET_URL ?? 'https://app.hyperbuds.com';

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants