Skip to content

Refactor LanguageSelectionGrid component to include loading state - #265

Open
VishnuKrishnathu wants to merge 4 commits into
ELEVATE-Project:release-1.0.6from
VishnuKrishnathu:hotfix/language-loader
Open

Refactor LanguageSelectionGrid component to include loading state#265
VishnuKrishnathu wants to merge 4 commits into
ELEVATE-Project:release-1.0.6from
VishnuKrishnathu:hotfix/language-loader

Conversation

@VishnuKrishnathu

@VishnuKrishnathu VishnuKrishnathu commented Apr 7, 2026

Copy link
Copy Markdown
  • Reintroduced useChatStorage and useSiteStorage hooks.
  • Added loading indicators for flow languages while data is being fetched.
  • Improved conditional rendering logic for language options based on loading state.

Summary by CodeRabbit

  • UI Improvements
    • Enhanced language selection experience: animated skeleton placeholders now display during loading, providing clearer visual feedback and better distinction between loading, available, and unavailable content states.

- Reintroduced useChatStorage and useSiteStorage hooks.
- Added loading indicators for flow languages while data is being fetched.
- Improved conditional rendering logic for language options based on loading state.
@coderabbitai

coderabbitai Bot commented Apr 7, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ee413913-6f5b-4d7c-818e-2c381ddb4ef1

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The pull request modifies the language selection grid component to implement loading state handling. It captures the loading status from a query hook and implements conditional rendering: skeleton placeholders display during loading, fetched flow languages appear when ready, and a fallback language list shows only if no flow languages exist after loading completes.

Changes

Cohort / File(s) Summary
Loading State Implementation
src/components/LanguageSelectionGrid.jsx
Added isFlowLanguagesLoading capture from useQuery hook and refactored render logic to display animated skeleton tiles during loading, flow languages when available, and fallback content only when loading is complete with no results.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Feature/admin flow control #244: Modifies the same component to add flow-aware language loading via react-query with loading state and conditional rendering logic.

Suggested reviewers

  • Vinod-V3

Poem

🐰 The skeletons shimmer while languages load,
No empty screens upon the road,
Loading states dance with grace so divine,
The grid glows bright—what UX design!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main change: adding a loading state to the LanguageSelectionGrid component, which is the primary focus of the modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 Apr 7, 2026

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

🧹 Nitpick comments (1)
src/components/LanguageSelectionGrid.jsx (1)

79-89: Consider reducing duplicated skeleton markup.

The four identical placeholder blocks are maintainable now, but a tiny map-based render keeps this cleaner for future style/layout tweaks.

♻️ Optional cleanup
-          isFlowLanguagesLoading && (
-            <>
-              <div className="bg-[`#e3e9f0`] animate-pulse w-full text-center vertical-center m-0 h-[100px] flex items-center justify-center">
-              </div>
-              <div className="bg-[`#e3e9f0`] animate-pulse w-full text-center vertical-center m-0 h-[100px] flex items-center justify-center">
-              </div>
-              <div className="bg-[`#e3e9f0`] animate-pulse w-full text-center vertical-center m-0 h-[100px] flex items-center justify-center">
-              </div>
-              <div className="bg-[`#e3e9f0`] animate-pulse w-full text-center vertical-center m-0 h-[100px] flex items-center justify-center">
-              </div>
-            </>
-          )
+          isFlowLanguagesLoading &&
+            Array.from({ length: 4 }).map((_, idx) => (
+              <div
+                key={`lang-skeleton-${idx}`}
+                className="bg-[`#e3e9f0`] animate-pulse w-full text-center vertical-center m-0 h-[100px] flex items-center justify-center"
+              />
+            ))
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/LanguageSelectionGrid.jsx` around lines 79 - 89, Replace the
four duplicated skeleton placeholder divs in LanguageSelectionGrid.jsx (rendered
when isFlowLanguagesLoading is true) with a concise map-based render: create an
array of four items and map over it to return the same placeholder div for each
item, ensure you pass a unique key (e.g., index) and preserve the existing
className/structure so styles and animation remain unchanged; update the JSX
inside the isFlowLanguagesLoading conditional to use this mapped array instead
of repeating the markup.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/components/LanguageSelectionGrid.jsx`:
- Around line 92-99: The current render checks only !isFlowLanguagesLoading and
flowLanguages, which fails when flowLanguages is {languages: []} or missing
languages; update the conditional rendering to first guard that
flowLanguages.languages is a non-empty array (e.g., use
flowLanguages?.languages?.length > 0) before mapping in the JSX where
flowLanguages.languages.map(...) is used (refer to flowLanguages,
flowLanguages.languages, isFlowLanguagesLoading, languageList,
handleLanguageClick, languageValueMap), and add a fallback branch that renders
languageList when flowLanguages is falsy or when flowLanguages.languages is
empty to avoid runtime errors and an empty grid.

---

Nitpick comments:
In `@src/components/LanguageSelectionGrid.jsx`:
- Around line 79-89: Replace the four duplicated skeleton placeholder divs in
LanguageSelectionGrid.jsx (rendered when isFlowLanguagesLoading is true) with a
concise map-based render: create an array of four items and map over it to
return the same placeholder div for each item, ensure you pass a unique key
(e.g., index) and preserve the existing className/structure so styles and
animation remain unchanged; update the JSX inside the isFlowLanguagesLoading
conditional to use this mapped array instead of repeating the markup.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cd838192-4835-454f-843f-8e2c110fe0fe

📥 Commits

Reviewing files that changed from the base of the PR and between 2df5453 and 7ac0c08.

📒 Files selected for processing (1)
  • src/components/LanguageSelectionGrid.jsx

Comment on lines +92 to 99
{!isFlowLanguagesLoading && flowLanguages &&
flowLanguages.languages.map(lang => (
<div key={lang} className="div14-lang w-full text-center vertical-center m-0 h-[100px] flex items-center justify-center" onClick={() => handleLanguageClick(lang)}>
<button className="w-full">{languageValueMap[lang]}</button>
</div>
))}
{!flowLanguages &&
{!isFlowLanguagesLoading && !flowLanguages &&
languageList

@coderabbitai coderabbitai Bot Apr 7, 2026

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 | 🟠 Major

Fallback condition misses empty-language responses.

Line 98 only checks !flowLanguages. If API returns { languages: [] }, neither list renders and users get an empty grid. Also, flowLanguages truthy with missing languages can break mapping at Line 93.

✅ Suggested fix
-        {!isFlowLanguagesLoading && flowLanguages &&
-          flowLanguages.languages.map(lang => (
+        {!isFlowLanguagesLoading && (flowLanguages?.languages?.length ?? 0) > 0 &&
+          flowLanguages.languages.map(lang => (
             <div key={lang} className="div14-lang w-full text-center vertical-center m-0 h-[100px] flex items-center justify-center" onClick={() => handleLanguageClick(lang)}>
               <button className="w-full">{languageValueMap[lang]}</button>
             </div>
           ))}
-        {!isFlowLanguagesLoading && !flowLanguages &&
+        {!isFlowLanguagesLoading && (flowLanguages?.languages?.length ?? 0) === 0 &&
           languageList
             .filter(lang => !lang.excludeFor.includes(urlFlow || usecaseType))
             .map(lang => (
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{!isFlowLanguagesLoading && flowLanguages &&
flowLanguages.languages.map(lang => (
<div key={lang} className="div14-lang w-full text-center vertical-center m-0 h-[100px] flex items-center justify-center" onClick={() => handleLanguageClick(lang)}>
<button className="w-full">{languageValueMap[lang]}</button>
</div>
))}
{!flowLanguages &&
{!isFlowLanguagesLoading && !flowLanguages &&
languageList
{!isFlowLanguagesLoading && (flowLanguages?.languages?.length ?? 0) > 0 &&
flowLanguages.languages.map(lang => (
<div key={lang} className="div14-lang w-full text-center vertical-center m-0 h-[100px] flex items-center justify-center" onClick={() => handleLanguageClick(lang)}>
<button className="w-full">{languageValueMap[lang]}</button>
</div>
))}
{!isFlowLanguagesLoading && (flowLanguages?.languages?.length ?? 0) === 0 &&
languageList
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/LanguageSelectionGrid.jsx` around lines 92 - 99, The current
render checks only !isFlowLanguagesLoading and flowLanguages, which fails when
flowLanguages is {languages: []} or missing languages; update the conditional
rendering to first guard that flowLanguages.languages is a non-empty array
(e.g., use flowLanguages?.languages?.length > 0) before mapping in the JSX where
flowLanguages.languages.map(...) is used (refer to flowLanguages,
flowLanguages.languages, isFlowLanguagesLoading, languageList,
handleLanguageClick, languageValueMap), and add a fallback branch that renders
languageList when flowLanguages is falsy or when flowLanguages.languages is
empty to avoid runtime errors and an empty grid.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Languages will never be empty

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@VishnuKrishnathu, understood! If the API contract guarantees that the languages array is always non-empty, then the empty-grid concern doesn't apply. I'll note this for future reviews.

(The optional chaining on flowLanguages?.languages is still a low-cost defensive guard against unexpected API shape changes, but I leave that to your discretion.)

(^ο½₯ω・^)


🧠 Learnings used
Learnt from: VishnuKrishnathu
Repo: ELEVATE-Project/mohini-app-frontend PR: 244
File: src/components/LanguageSelectionGrid.jsx:47-68
Timestamp: 2026-02-16T06:38:02.503Z
Learning: In LanguageSelectionGrid.jsx (src/components/LanguageSelectionGrid.jsx), the `setPreviousUrl` and `setStorageFlow` calls are intentionally only set for specific route_mapping flows (ParentPerceptionSurvey, ListeningActivity) before navigation. For the COMMON_CHAT navigation path, these should NOT be set, as users should not be able to navigate back to /home or the current page. This is expected behavior.

- Introduced 'StudyTeacherInterview' and 'BiharTeachersBot' session flows in session constants.
- Updated dynamic voice chat logic to include 'BiharTeachersBot' in conditions for showing confirm and new session buttons.
…oice chat logic to reflect changes in session flow conditions.
- Changed background styles of loading indicators to improve visual appearance with shadow and rounded corners.
- Ensured consistent styling across multiple loading divs for better user experience during data fetching.
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.

1 participant