Skip to content

Enhance IP data handling in ShikshalokamChat and ShikshalokamVoiceChat components - #207

Merged
Vinod-V3 merged 1 commit into
ELEVATE-Project:release-1.0.4from
VishnuKrishnathu:feature/ip-socket
Dec 5, 2025
Merged

Enhance IP data handling in ShikshalokamChat and ShikshalokamVoiceChat components#207
Vinod-V3 merged 1 commit into
ELEVATE-Project:release-1.0.4from
VishnuKrishnathu:feature/ip-socket

Conversation

@VishnuKrishnathu

@VishnuKrishnathu VishnuKrishnathu commented Dec 5, 2025

Copy link
Copy Markdown

Enhance IP data handling in ShikshalokamChat and ShikshalokamVoiceChat components by introducing ipFetched state management

Summary by CodeRabbit

  • Improvements
    • Refined app initialization to display more accurate loading indicators during location data setup
    • Enhanced state management for location-based feature initialization, ensuring more reliable completion tracking

✏️ Tip: You can customize this high-level summary in your review settings.

…t components by introducing ipFetched state management
@coderabbitai

coderabbitai Bot commented Dec 5, 2025

Copy link
Copy Markdown

Walkthrough

The changes introduce an ipFetched state flag to track completion of IP/location data retrieval. This flag replaces direct checks of individual IP components (ipCity, ipState, ipZipCode) and controls loader visibility during initialization. The websocket authentication payload is refactored to send address as an object instead of a concatenated string, with dependency arrays updated accordingly.

Changes

Cohort / File(s) Summary
State Management
src/store/slices/userData/state.js
Added new state property ipFetched (initialized to false) and setter setIpFetched() to track IP/location data retrieval completion.
Chat Component Initialization
src/pages/shikshalokamChat.js
Refactored setup effect to use ipFetched flag; added try/finally block to ensure setIpFetched(true) is called after initialization; updated loader visibility to depend on both isLoading and ipFetched; added useUserStorage hooks for ipFetched and setIpFetched.
Voice Chat Authentication
src/pages/ShikshalokamVoiceChat/voice-chat.js
Updated websocket guard to check ipFetched instead of individual IP properties; modified authenticate payload to send address as an object with ipCity, ipState, ipZipCode; updated dependency array to depend on ipFetched.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Pay special attention to initialization sequencing in shikshalokamChat.js, particularly the try/finally block and loader state logic
  • Verify websocket authentication payload changes in voice-chat.js work correctly with backend expectations
  • Ensure state synchronization between user storage and component initialization flow

Possibly related PRs

Suggested reviewers

  • Vinod-V3

Poem

🐰 With flags unfurled, the bunny hops with glee,
IP tracked with care, initialization flows so free,
Address objects dance, authentication's dance,
State synced and true—no more did we prance! 🌐✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: introducing ipFetched state management to enhance IP data handling across the two components mentioned.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ast-grep (0.40.0)
src/pages/ShikshalokamVoiceChat/voice-chat.js

[]


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@VishnuKrishnathu

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Dec 5, 2025

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d3ff524 and e086e59.

📒 Files selected for processing (3)
  • src/pages/ShikshalokamVoiceChat/voice-chat.js (3 hunks)
  • src/pages/shikshalokamChat.js (4 hunks)
  • src/store/slices/userData/state.js (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
src/store/slices/userData/state.js (2)
src/pages/ShikshalokamVoiceChat/voice-chat.js (2)
  • ipZipCode (173-173)
  • ipFetched (174-174)
src/pages/shikshalokamChat.js (1)
  • ipFetched (40-40)
src/pages/ShikshalokamVoiceChat/voice-chat.js (1)
src/pages/shikshalokamChat.js (2)
  • ipFetched (40-40)
  • useUserStorage (18-18)
src/pages/shikshalokamChat.js (7)
src/pages/ShikshalokamVoiceChat/voice-chat.js (7)
  • useUserStorage (180-180)
  • useChatStorage (177-177)
  • useChatStorage (181-181)
  • storageFlow (167-167)
  • ipFetched (174-174)
  • sessionId (158-158)
  • isLoading (94-94)
src/hooks/useStorage.js (4)
  • useUserStorage (24-26)
  • useUserStorage (24-26)
  • useChatStorage (20-22)
  • useChatStorage (20-22)
src/pages/UnifiedChat/UnifiedChat.jsx (5)
  • useUserStorage (18-18)
  • useChatStorage (19-19)
  • storageFlow (22-22)
  • sessionId (23-23)
  • isLoading (15-15)
src/pages/Login/commonPage.jsx (2)
  • storageFlow (31-31)
  • setFlow (32-32)
src/pages/UnifiedChat/StoryActionsModule.js (6)
  • storageFlow (32-32)
  • storageFlow (284-284)
  • sessionId (31-31)
  • sessionId (283-283)
  • isLoading (281-281)
  • isLoading (563-563)
src/pages/ShikshalokamVoiceChat/shikshaChatSidebar.js (1)
  • storageFlow (18-18)
src/services/api.service.js (2)
  • getIpLocation (63-66)
  • getIpLocation (63-66)
🔇 Additional comments (7)
src/store/slices/userData/state.js (1)

12-12: LGTM! Clean state addition.

The new ipFetched flag and setter follow the existing patterns in this state file and provide a clear way to track IP data fetch completion.

Also applies to: 20-21

src/pages/ShikshalokamVoiceChat/voice-chat.js (3)

210-210: Good refactor of dependency array.

Replacing individual IP field dependencies with ipFetched correctly reflects that authentication should only occur once after IP data is available, rather than re-authenticating when individual IP fields change.


191-193: Verify WebSocket connection sequencing and authentication flow.

The early return when !ipFetched prevents sending authentication, which could leave the WebSocket connected but unauthenticated. Confirm that the WebSocket connection is only attempted after ipFetched becomes true, or verify that retry/deferred authentication logic handles this scenario appropriately.


204-209: Verify backend API compatibility with address object structure.

The address field uses an object format with ipCity, ipState, and ipZipCode keys. Confirm the backend WebSocket authentication endpoint supports this structure and that these fields are reliably populated before deployment.

src/pages/shikshalokamChat.js (3)

10-10: Good cleanup of unused import.

Removing useSiteStorage from the imports appears to be a valid cleanup since it's not used in this file.


34-34: LGTM! Correct state access.

The new setIpFetched and ipFetched accessors are correctly retrieved from state following existing patterns.

Also applies to: 40-40


167-167: Loader condition depends on correct ipFetched state.

The loader visibility now depends on both isLoading and ipFetched states. Ensure the critical issue in lines 127-154 is resolved so that ipFetched accurately reflects initialization success, not just completion.

Comment on lines +127 to 154
try {
// if (accessToken) return

if (!sessionId) {
// clearFromStorage(false, ["local_route"])
setIsLoading(true)
// setHasAcceptedTnc("ONGOING")
setIsNewChatOpen(true)

const locationData = await getIpLocation()
if (locationData && locationData?.location) {
setIpState(locationData?.location?.regionName)
setIpCity(locationData?.location?.city)
setIpCountry(locationData?.location?.country)
setIpZipCode(locationData?.location?.zip)
}
setFlow(type)
getUserFingerPrint()
await setFinalLanguage()

setIsLoading(false)
}
setFlow(type)
getUserFingerPrint()
await setFinalLanguage()

setIsLoading(false)
// else if (storageFlow && !accessToken){
// window.location.reload();
// }
} finally {
setIpFetched(true)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Fix error handling: ipFetched set to true even on failure.

The finally block sets ipFetched = true regardless of whether the IP location fetch succeeds or fails. This means:

  1. If getIpLocation() fails, the loader will still disappear (line 167)
  2. Failed initialization will be masked from users
  3. The WebSocket may attempt to authenticate with undefined IP values

Consider setting ipFetched = true only after successful completion, or add a separate error state to handle failures properly.

Apply this diff to fix the error handling:

     const runSetup = async () => {
-      try {
-        // if (accessToken) return
-
-        if (!sessionId) {
-          // clearFromStorage(false, ["local_route"])
-          setIsLoading(true)
-          // setHasAcceptedTnc("ONGOING")
-          setIsNewChatOpen(true)
-
-          const locationData = await getIpLocation()
-          if (locationData && locationData?.location) {
-            setIpState(locationData?.location?.regionName)
-            setIpCity(locationData?.location?.city)
-            setIpCountry(locationData?.location?.country)
-            setIpZipCode(locationData?.location?.zip)
-          }
-          setFlow(type)
-          getUserFingerPrint()
-          await setFinalLanguage()
-
-          setIsLoading(false)
+      if (!sessionId) {
+        try {
+          setIsLoading(true)
+          setIsNewChatOpen(true)
+
+          const locationData = await getIpLocation()
+          if (locationData && locationData?.location) {
+            setIpState(locationData?.location?.regionName)
+            setIpCity(locationData?.location?.city)
+            setIpCountry(locationData?.location?.country)
+            setIpZipCode(locationData?.location?.zip)
+          }
+          setFlow(type)
+          getUserFingerPrint()
+          await setFinalLanguage()
+          
+          // Only set ipFetched to true on successful completion
+          setIpFetched(true)
+        } catch (error) {
+          console.error("Error during IP location fetch:", error)
+          // Consider showing error to user or setting error state
+        } finally {
+          setIsLoading(false)
         }
-        // else if (storageFlow && !accessToken){
-        // 	window.location.reload();
-        // }
-      } finally {
-        setIpFetched(true)
       }
     }
🤖 Prompt for AI Agents
In src/pages/shikshalokamChat.js around lines 127 to 154, the finally block
unconditionally sets ipFetched=true which hides the loader and allows downstream
flows to proceed even if getIpLocation() fails; instead move setIpFetched(true)
into the successful path (after IP values are set) and add a catch block that
sets an explicit error state (e.g., setIpError or setIpFetched(false)) and
ensures setIsLoading(false) so failures are visible; also guard later
WebSocket/auth logic to not use undefined IP values (or set sensible defaults)
when ipFetch failed.

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.

2 participants