Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(settings): Turn the theme toggle into a field in the settings form. #184

Merged
merged 6 commits into from
Feb 17, 2025

Conversation

junhaoliao
Copy link
Member

@junhaoliao junhaoliao commented Feb 17, 2025

Description

  1. Turn the theme toggle into a theme field in the settings form, which also displays the current mode.
    image

Checklist

  • The PR satisfies the contribution guidelines.
  • This is a breaking change and that has been indicated in the PR title, OR this isn't a
    breaking change.
  • Necessary docs have been updated, OR no docs need to be updated.

Validation performed

  1. On Windows, set system theme mode to "Light" in the "Settings" app.
  2. Opened the settings modal in the log viewer. Observed "Current mode: system" in the "Theme" field and the log viewer was in Light mode which matched expectation.
  3. Clicked the "Light" button and observed the current mode text changed: "Current mode: light". The theme of the log viewer remain unchanged which matched expectation.
  4. Clicked the "Dark" button and observed the current mode text changed: "Current mode: dark". The log viewer changed into a dark theme which matched expectation.
  5. Clicked the "Dark" button again which toggled the button, and the current mode text changed: "Current mode: system". The log viewer changed back into a light theme which matched expectation.
  6. On Windows, set system theme mode to "Dark" in the "Settings" app. Repeated Steps 2 - 5 to ensure the theme sync with system and theme overrides are working.
  7. Verified that switching from "Light" or "Dark" back to "System" to use system theme mode was working as expected.

Summary by CodeRabbit

  • New Features
    • Introduced a refreshed theme selection interface offering Light, Dark, and System options.
  • Refactor
    • Streamlined the settings dialog by replacing the previous theme toggle with a new theme selection form field.
  • Style
    • Enhanced the title text appearance for improved readability in the settings dialog.

Copy link

coderabbitai bot commented Feb 17, 2025

Walkthrough

The changes update the settings dialog interface by replacing the previous theme selection component with a new one. The SettingsDialog.tsx component now incorporates the new ThemeSwitchFormField component instead of the removed ThemeSwitchToggle. A new file has been introduced for the form field, while the old toggle component file has been removed. Additionally, a CSS update refines the title style by removing a flex property and enforcing a larger font size with higher specificity. The underlying form submission, reset handling, and configuration management logic remain unchanged.

Changes

Files Change Summary
src/components/modals/SettingsModal/SettingsDialog.tsx, src/components/modals/SettingsModal/ThemeSwitchFormField.tsx, src/components/modals/SettingsModal/ThemeSwitchToggle.tsx In the settings dialog, replaced the ThemeSwitchToggle component with the new ThemeSwitchFormField for theme selection. Added ThemeSwitchFormField and removed ThemeSwitchToggle. The dialog title was simplified.
src/components/modals/SettingsModal/index.css Updated the .settings-dialog-title-text class by removing flex-grow: 1; and applying font-size: 2rem !important; to override existing styles.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant SD as SettingsDialog
    participant TSF as ThemeSwitchFormField
    participant MUI as useColorScheme Hook

    U->>SD: Open settings dialog
    SD->>TSF: Render theme switch component
    TSF->>MUI: Retrieve current theme mode
    U->>TSF: Select theme mode (Light/Dark/System)
    TSF->>MUI: Invoke setMode() with selected mode
    MUI-->>TSF: Return updated theme mode
    TSF->>U: Display current theme in helper text
Loading

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0039993 and d697ef9.

📒 Files selected for processing (1)
  • src/components/modals/SettingsModal/ThemeSwitchFormField.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/modals/SettingsModal/ThemeSwitchFormField.tsx

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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.

@davemarco
Copy link
Contributor

davemarco commented Feb 17, 2025

@junhaoliao - is there a technical reason for this change? Or is it just aesthetic?

@junhaoliao
Copy link
Member Author

@junhaoliao - is there a technical reason for this change? Or is it just aesthetic?

mostly aesthetic. We need to find a place for the button group when we move the setting options into a tab.

@davemarco
Copy link
Contributor

what do you mean by this We need to find a place for the button group when we move the setting options into a tab.

@junhaoliao
Copy link
Member Author

what do you mean by this We need to find a place for the button group when we move the setting options into a tab.

The (toggle) buttons might not be suitable to show up as tab titleButtons. I figured the best way is to make it a field like other setting options, and here's how the button group would look like when the setting options are moved into a tab:
image

@davemarco
Copy link
Contributor

davemarco commented Feb 17, 2025

Ah I get it now. Is there a reason you dropped the system option? I guess the current mode:light is slightly repetitive vs just keeping the system setting

@junhaoliao
Copy link
Member Author

Ah I get it now. Is there a reason you dropped the system option?

One of the reasons is to make the button group narrower to avoid x-direction overflow issues in the tab.

another reason is to make the purpose of the field, which is to "override a theme mode", more explicit. this can be subjective lol. feel free to object

@davemarco
Copy link
Contributor

davemarco commented Feb 17, 2025

Yes it is subjective. I think it's better with the system (as without helper) , as long as it fits in the default tab width.

I think the double click is slightly less intuitive, to go back to system

I would rename the title to theme as well. Then will approve

@junhaoliao junhaoliao changed the title feat(settings): Turn the theme toggle into a theme override field in the settings form. feat(settings): Turn the theme toggle into a field in the settings form. Feb 17, 2025
@junhaoliao junhaoliao requested review from davemarco and removed request for davemarco February 17, 2025 19:31
Copy link

@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 (1)
src/components/modals/SettingsModal/index.css (1)

7-7: Consider alternative to !important.

The use of !important should be avoided as it makes styles harder to maintain. Consider increasing selector specificity instead.

-    font-size: 2rem !important;
+    font-size: 2rem;

If you need to override MUI styles, consider using a more specific selector:

.MuiDialog-root .settings-dialog-title {
    font-size: 2rem;
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 97f4c39 and 0039993.

📒 Files selected for processing (4)
  • src/components/modals/SettingsModal/SettingsDialog.tsx (2 hunks)
  • src/components/modals/SettingsModal/ThemeSwitchFormField.tsx (1 hunks)
  • src/components/modals/SettingsModal/ThemeSwitchToggle.tsx (0 hunks)
  • src/components/modals/SettingsModal/index.css (1 hunks)
💤 Files with no reviewable changes (1)
  • src/components/modals/SettingsModal/ThemeSwitchToggle.tsx
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}`: - Prefer `false == ...

**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}: - Prefer false == <expression> rather than !<expression>.

  • src/components/modals/SettingsModal/ThemeSwitchFormField.tsx
  • src/components/modals/SettingsModal/SettingsDialog.tsx
🔇 Additional comments (3)
src/components/modals/SettingsModal/ThemeSwitchFormField.tsx (2)

1-15: LGTM! Well-organized imports.

The imports are logically grouped and all are utilized in the component.


23-62: Consider PR discussion points about theme options.

Based on the PR discussion:

  1. The "System" option was suggested to be retained for better user experience
  2. The title could be simplified to just "Theme" (already implemented)
  3. The current mode display might be redundant

Would you like to:

  1. Keep the current implementation with the "System" option as suggested in the discussion?
  2. Remove the FormHelperText displaying the current mode if it's deemed redundant?
src/components/modals/SettingsModal/SettingsDialog.tsx (1)

32-32: LGTM! Clean integration of the new theme switch component.

The ThemeSwitchFormField is well-placed within the DialogContent, providing a more consistent form layout.

Also applies to: 144-144, 147-147

Copy link
Contributor

@davemarco davemarco left a comment

Choose a reason for hiding this comment

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

See small nits

Comment on lines 57 to 59
<FormHelperText>
{`Current mode: ${mode}`}
</FormHelperText>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
<FormHelperText>
{`Current mode: ${mode}`}
</FormHelperText>

Copy link
Member Author

Choose a reason for hiding this comment

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

For visual consistency with other fields, how about:

Suggested change
<FormHelperText>
{`Current mode: ${mode}`}
</FormHelperText>
<FormHelperText>
{"When \"System\" mode is selected, the theme adapts to your operating system or" +
" individual user agent's preference."}
</FormHelperText>

Copy link
Contributor

@davemarco davemarco Feb 17, 2025

Choose a reason for hiding this comment

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

Maybe something simpler. Log viewer color theme. System theme will match your system settings.

import {
Button,
FormControl,
FormHelperText,
Copy link
Contributor

Choose a reason for hiding this comment

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

Related to later comment

Suggested change
FormHelperText,

Copy link
Contributor

Choose a reason for hiding this comment

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

Believe there is an extra space above font-size that's not neccesary

Copy link
Member Author

Choose a reason for hiding this comment

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

hmm.. Do you mean an extra line above font-size? That was added by the linter (stylelint-config-clean-order)

@junhaoliao junhaoliao requested a review from davemarco February 17, 2025 20:53
@junhaoliao junhaoliao merged commit 0e64e3a into y-scope:main Feb 17, 2025
4 checks passed
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