Skip to content

Conversation

@Woofer21
Copy link
Member

@Woofer21 Woofer21 commented Apr 2, 2025

Fixes the auth issues and allows the language to be switched while you are logged out through a new menu button on the nav bar.

Logged out

image

Logged In

image

Summary by CodeRabbit

  • New Features

    • Introduced a dedicated, streamlined dropdown for language and theme selection, allowing users to easily switch languages and toggle between dark and light modes.
    • Enhanced the login experience by automatically applying the correct locale after sign-in for a smoother, more personalized user interaction.
    • Added new components for language and theme switching, improving user interface modularity and functionality.
  • Bug Fixes

    • Resolved issues related to the previous language selection interface, enhancing overall user experience.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 2, 2025

Walkthrough

This update restructures internationalization and authentication. The translation file now separates language and theme options from the account settings. In the authentication module, user emails become dynamically generated using Discord IDs, and a new middleware hook sets the locale after authentication. Additionally, the Navbar import path is updated, and several navigation components are refactored—removing in-component locale management in favor of modular LanguageSwitcher and ThemeSwitcher components integrated through a new dropdown structure.

Changes

Files Change Summary
src/i18n/translations/en.json Removed "language" from the account section; added a new "dropdown" section with "language" and "theme" (with dark/light options and title).
src/lib/auth.ts Updated mapProfileToUser to generate dynamic emails using the Discord ID; added a new hooks.after with createAuthMiddleware to set the user locale post-authentication.
src/app/layout.tsx Changed the Navbar import path from "@/components/navbar" to "@/components/nav/navbar".
src/components/nav/discord-login.tsx Removed inline locale management from DiscordLoginButton; introduced LanguageSwitcher and ThemeSwitcher for modular language and theme selection.
src/components/nav/navbar.tsx Removed ThemeToggle function; added NavDropdown for theme and language selection.
src/components/nav/language-switcher.tsx New component added for language selection with locale management.
src/components/nav/theme-switcher.tsx New component added for theme selection with UI integration.
src/components/ui/dropdown-menu.tsx Modified layout of DropdownMenuRadioItem for visual alignment.
package.json Updated packageManager from "pnpm@10.6.5" to "pnpm@10.7.1".

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant A as Auth Service
    participant M as Auth Middleware
    U->>A: Initiate login
    A->>M: Call after hook on "/callback"
    M->>A: Retrieve session
    M->>A: Set user locale
    A-->>U: Return authenticated session
Loading
sequenceDiagram
    participant U as User
    participant ND as NavDropdown
    participant LS as LanguageSwitcher
    participant TS as ThemeSwitcher
    U->>ND: Click dropdown button
    ND->>LS: Display language options
    LS->>LS: Update locale (trigger updateUser)
    ND->>TS: Display theme options
    TS->>TS: Change theme (trigger setTheme)
Loading

Suggested reviewers

  • taqh
  • mezotv
  • dpaulos6

Poem

I’m hopping through code with a joyful beat,
New switches and hooks making each feature neat.
Dropdowns for language and themes now play,
In the realm of code where logic holds sway.
A bunny in bytes, happy as can be –
Celebrating these changes with a skip and a glee! 🐰✨

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/lib/auth.ts (1)

46-53: Added middleware hook to set user locale after authentication.

The middleware correctly sets the user's locale after the authentication process, but only for callback paths which might not cover all cases where locale needs to be updated.

Consider adding a comment explaining why this is only done for callback paths, or implementing a more comprehensive solution that handles locale setting in other contexts as well.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5aa71ac and aca5772.

📒 Files selected for processing (5)
  • src/components/discord-login.tsx (2 hunks)
  • src/components/language-switcher.tsx (1 hunks)
  • src/components/navbar.tsx (4 hunks)
  • src/i18n/translations/en.json (1 hunks)
  • src/lib/auth.ts (3 hunks)
🧰 Additional context used
🧬 Code Definitions (3)
src/components/discord-login.tsx (1)
src/components/language-switcher.tsx (1)
  • LanguageSwitcher (18-92)
src/lib/auth.ts (1)
src/i18n/services/locale.ts (1)
  • setUserLocale (12-14)
src/components/navbar.tsx (2)
src/components/ui/dropdown-menu.tsx (5)
  • DropdownMenu (258-258)
  • DropdownMenuTrigger (260-260)
  • DropdownMenuContent (261-261)
  • DropdownMenuGroup (262-262)
  • DropdownMenuItem (264-264)
src/components/language-switcher.tsx (1)
  • LanguageSwitcher (18-92)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Format Files
  • GitHub Check: Build Application
🔇 Additional comments (11)
src/i18n/translations/en.json (1)

169-174: Well-structured translation keys for language and theme!

The new dropdown section with language and theme translations nicely separates these options from the account settings, making them more accessible.

src/components/discord-login.tsx (1)

3-4: Imports updated correctly for new language switcher component.

The necessary imports have been added to support the LanguageSwitcher component.

Also applies to: 8-8

src/lib/auth.ts (2)

2-2: Added required imports for locale handling.

The imports for setUserLocale and createAuthMiddleware are correctly added to support the new locale functionality.

Also applies to: 6-6


33-33: Improved email generation using Discord ID.

Using the Discord ID to generate a unique email address is a good practice as it ensures unique identification for each user.

src/components/language-switcher.tsx (3)

18-22: Good initialization of LanguageSwitcher component.

The component is properly set up with the necessary hooks and state initialization.


31-40: Locale change handler looks good.

The handleLocaleChange function correctly updates both the local state and user preferences. It also has a proper conditional check before updating the user profile.


42-91: Well-structured dropdown menu for language selection.

The language selection dropdown is well-organized with proper flag icons and language names. The implementation uses the appropriate UI components for the dropdown menu.

src/components/navbar.tsx (4)

4-4: Import statements updated to support new dropdown functionality.

The imports have been updated to include the necessary components for the new navigation dropdown menu. Icons like Menu, Sun, and Moon are added for UI elements, and the new LanguageSwitcher component is imported to handle language selection functionality. The dropdown menu components are also properly imported from the UI library.

Also applies to: 11-18


83-83: Replaced ThemeToggle with NavDropdown component in mobile and desktop views.

The ThemeToggle component has been replaced with NavDropdown in both the mobile view (line 83) and desktop view (line 90). This change correctly implements the PR objective to make language switching available when logged out by placing it in the navigation bar.

Also applies to: 90-90


164-168: Function renamed from ThemeToggle to NavDropdown with updated translation hook.

The function has been renamed to better reflect its expanded functionality, now including both theme and language options. The translation hook is now used without a specific namespace, allowing access to nested translation keys used in the dropdown menu.


177-203: Implemented dropdown menu with theme toggle and language switcher functionality.

The implementation now uses a dropdown menu structure that elegantly combines theme toggling and language switching in a single UI element. The dropdown is triggered by a menu icon and includes:

  1. Theme toggle functionality that maintains the original behavior while adding localized text
  2. The new LanguageSwitcher component

This implementation effectively addresses the PR objective by making language switching available in the navigation bar, accessible to all users including those who are logged out.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
src/components/language-switcher.tsx (4)

79-79: Language name correction needed.

The Spanish language should be written as "Español" (the noun) rather than "Española" (feminine adjective).

-						Española
+						Español

86-86: Language name correction needed.

The Italian language should be written as "Italiano" (the noun) rather than "Italiana" (feminine adjective).

-						Italiana
+						Italiano

23-29: Consider adding error handling for locale fetching.

The useEffect hook doesn't include error handling if getUserLocale() fails. Consider adding a try/catch block to handle potential errors gracefully.

useEffect(() => {
  async function getLang() {
+   try {
      setLang(await getUserLocale());
+   } catch (error) {
+     console.error("Failed to get user locale:", error);
+     // Fallback to default language
+     setLang("en");
+   }
  }

  getLang();
}, []);

21-21: Consider adding a loading state.

Adding a loading state while fetching the user locale would improve the user experience, especially on slower connections.

- const [lang, setLang] = useState("en");
+ const [lang, setLang] = useState("en");
+ const [isLoading, setIsLoading] = useState(true);

useEffect(() => {
  async function getLang() {
    try {
+     setIsLoading(true);
      setLang(await getUserLocale());
    } catch (error) {
      console.error("Failed to get user locale:", error);
      // Fallback to default language
      setLang("en");
    } finally {
+     setIsLoading(false);
    }
  }

  getLang();
}, []);

Then you could use the loading state in your render method to display a loading indicator if needed.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aca5772 and d54e876.

📒 Files selected for processing (1)
  • src/components/language-switcher.tsx (1 hunks)
🔇 Additional comments (2)
src/components/language-switcher.tsx (2)

23-29: Good implementation of the useEffect dependency array.

I see you've properly implemented the empty dependency array in the useEffect hook, ensuring it only runs once when the component mounts. This fixes the performance issue noted in previous reviews.


31-40: Well-structured language change handler.

The handleLocaleChange function properly handles both UI state and user profile updates when a language is selected. The conditional check for an active session ensures that user updates are only attempted when appropriate.

taqh
taqh previously approved these changes Apr 2, 2025
@Woofer21 Woofer21 changed the title Fix auth & lang switch avail when logged out Fix auth & made lang switch available when logged out Apr 2, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/components/nav/theme-switcher.tsx (1)

16-38: Clean and accessible UI implementation

The dropdown menu structure is well-implemented with appropriate icons for visual feedback. The radio group correctly uses the theme value and handles changes properly.

One suggestion to enhance this implementation:

<DropdownMenuRadioGroup
  value={theme}
- onValueChange={(value) => setTheme(value)}
+ onValueChange={setTheme}
>

This is a minor optimization as setTheme can be passed directly as the handler since it accepts the same argument that onValueChange provides.

src/components/nav/language-switcher.tsx (1)

42-91: Well-structured language selection UI

The dropdown implementation is clean and provides a good user experience with flag icons for each language. All common languages are represented.

One minor issue to consider:

The Spanish language name should be "Español" rather than "Española" (which refers to a Spanish woman rather than the language).

<DropdownMenuRadioItem value="es">
  <Flag
    code="es"
    className="size-4"
  />
- Española
+ Español
</DropdownMenuRadioItem>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d954143 and 73f0cb0.

📒 Files selected for processing (6)
  • src/app/layout.tsx (1 hunks)
  • src/components/nav/discord-login.tsx (4 hunks)
  • src/components/nav/language-switcher.tsx (1 hunks)
  • src/components/nav/navbar.tsx (3 hunks)
  • src/components/nav/theme-switcher.tsx (1 hunks)
  • src/i18n/translations/en.json (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/app/layout.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/i18n/translations/en.json
🧰 Additional context used
🧬 Code Definitions (2)
src/components/nav/navbar.tsx (2)
src/components/nav/theme-switcher.tsx (1)
  • ThemeSwitcher (12-40)
src/components/nav/language-switcher.tsx (1)
  • LanguageSwitcher (18-92)
src/components/nav/discord-login.tsx (2)
src/components/nav/theme-switcher.tsx (1)
  • ThemeSwitcher (12-40)
src/components/nav/language-switcher.tsx (1)
  • LanguageSwitcher (18-92)
🔇 Additional comments (15)
src/components/nav/discord-login.tsx (4)

3-4: Import consolidation looks good

The updated imports for Lucide icons and next-intl are appropriate for the component's needs.


7-8: Import path updates are correct

The component import paths have been properly updated to use relative paths, which is a good practice for components in the same directory.


22-23: Good modular approach with new component imports

The imports for the new LanguageSwitcher and ThemeSwitcher components indicate a nice separation of concerns, moving functionality to dedicated components.


72-73: Well implemented component integration

The ThemeSwitcher and LanguageSwitcher components are properly integrated into the dropdown menu, replacing the previous in-component implementation. This makes the code more maintainable and follows the single responsibility principle.

src/components/nav/theme-switcher.tsx (3)

1-7: Import structure is well organized

The dropdown menu component imports are properly structured and specific to the needs of this component.


8-10: Appropriate hooks and icon imports

The necessary Lucide icons for theme representation and the required hooks for theme management and translations are correctly imported.


12-15: Well structured component initialization

The component properly uses the useTranslations hook with the correct namespace and correctly extracts theme information from the useTheme hook.

src/components/nav/navbar.tsx (5)

3-20: Appropriate imports for enhanced functionality

The imports have been updated to include authentication client, necessary UI components, and the new theme and language switchers. This sets up the component properly for the new functionality.


25-25: Good session management implementation

Adding session state retrieval from authClient enables the conditional rendering of UI elements based on authentication status.


86-86: Proper conditional rendering for mobile view

The component correctly handles showing the NavDropdown only when user is not logged in or authentication is not pending in the mobile menu.


93-93: Consistent conditional rendering for desktop view

The same conditional logic is correctly applied to the desktop view, maintaining consistency across breakpoints.


167-189: Well-implemented dropdown for user preferences

The NavDropdown function is clean, well-structured, and properly integrates both theme and language switchers. The Button component is correctly used as a trigger with appropriate styling.

src/components/nav/language-switcher.tsx (3)

1-17: Appropriate imports and setup

The necessary imports for locale management, UI components, and internationalization are correctly included.


18-30: Effective state management and initialization

The component correctly uses useState for local state management and useEffect to initialize the language setting. The async function for retrieving the user locale is properly implemented.


31-40: Proper locale change handling

The locale change handler correctly updates both the local UI state and the user's saved preference. It properly checks for an active session before attempting to update user settings.

@Woofer21 Woofer21 enabled auto-merge (squash) April 2, 2025 20:35
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

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 73f0cb0 and e2f7484.

📒 Files selected for processing (5)
  • package.json (1 hunks)
  • src/components/nav/discord-login.tsx (5 hunks)
  • src/components/nav/theme-switcher.tsx (1 hunks)
  • src/components/ui/dropdown-menu.tsx (1 hunks)
  • src/i18n/translations/en.json (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • src/components/ui/dropdown-menu.tsx
  • package.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/i18n/translations/en.json
🧰 Additional context used
🧬 Code Definitions (1)
src/components/nav/discord-login.tsx (2)
src/components/nav/theme-switcher.tsx (1)
  • ThemeSwitcher (12-45)
src/components/nav/language-switcher.tsx (1)
  • LanguageSwitcher (18-92)
🔇 Additional comments (6)
src/components/nav/discord-login.tsx (3)

1-3: Good modular component integration

The additions of LanguageSwitcher and ThemeSwitcher imports reflect a positive shift toward modular component architecture. This approach improves maintainability by separating concerns into dedicated components.


47-62: Enhanced UI with structured button trigger

Replacing the simple dropdown trigger with a fully structured Button component improves usability and accessibility. The avatar integration with proper spacing and text layout creates a more polished user experience.


80-81: LGTM - Functionality matches PR objectives

The integration of ThemeSwitcher and LanguageSwitcher components directly addresses the PR objective of making language switching available when logged out, while maintaining a consistent UX pattern for both authenticated and unauthenticated users.

src/components/nav/theme-switcher.tsx (3)

1-10: Clean imports with good component organization

The imports are well-organized, providing all necessary UI components, icons, and hooks for the theme switcher functionality.


12-15: Well-structured component with proper hook usage

Good use of the useTranslations hook with a specific namespace ("nav.dropdown.theme") and the useTheme hook for managing theme state. This ensures that the component is properly integrated with the application's i18n and theming systems.


16-44: Well-implemented theme switching UI with accessible options

The dropdown implementation provides a clean, accessible UI for theme switching. Each option includes both an icon and translated text, enhancing usability. The radio group pattern correctly maintains the current selection state.

@dpaulos6 dpaulos6 requested a review from taqh April 4, 2025 13:51
@dpaulos6 dpaulos6 deployed to Pr Builds April 4, 2025 13:58 — with GitHub Actions Active
@Woofer21 Woofer21 merged commit 1caf591 into main Apr 4, 2025
4 checks passed
@Woofer21 Woofer21 deleted the woofer/fix-auth-again branch April 4, 2025 14:00
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.

4 participants