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

Fix theme picker text when unspecified theme #42671

Merged
merged 3 commits into from
Jun 18, 2024
Merged

Fix theme picker text when unspecified theme #42671

merged 3 commits into from
Jun 18, 2024

Conversation

avatus
Copy link
Contributor

@avatus avatus commented Jun 9, 2024

Fixes #42395
Currently, we work under the assumption that the theme is a binary decision between light/dark. The default user theme is now UNSPECIFIED which will default to the system theme. This PR adds a few utility options to get the current/next theme with this unspecified in mind. We can remove them once we add the user settings page to make "use system theme" a valid option to select.

To test, you can create a new user in an incognito window. The theme should be whatever your system theme is. Also, the theme selector should know which theme is being used a properly show text for what the next theme should be.

@avatus avatus added backport-required no-changelog Indicates that a PR does not require a changelog entry backport/branch/v16 labels Jun 9, 2024
@avatus avatus requested review from ryanclark, kimlisa and rudream and removed request for ravicious and ibeckermayer June 9, 2024 16:45
Copy link
Contributor

@ryanclark ryanclark left a comment

Choose a reason for hiding this comment

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

Can you add some tests for your new helper methods?

@@ -39,6 +39,23 @@ function themePreferenceToTheme(themePreference: Theme) {
return themePreference === Theme.LIGHT ? lightTheme : darkTheme;
}

// because unspecific can exist but only used as a fallback and not an option,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// because unspecific can exist but only used as a fallback and not an option,
// because unspecified can exist but only used as a fallback and not an option,

if (currentTheme === Theme.UNSPECIFIED) {
return getPrefersDark() ? Theme.DARK : Theme.LIGHT;
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are you intentionally not returning anything if currentTheme !== Theme.UNSPECIFIED?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. Thanks!

Comment on lines 55 to 58
if (currentTheme === Theme.UNSPECIFIED) {
return getPrefersDark() ? Theme.LIGHT : Theme.DARK;
}
return currentTheme === Theme.LIGHT ? Theme.DARK : Theme.LIGHT;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be

Suggested change
if (currentTheme === Theme.UNSPECIFIED) {
return getPrefersDark() ? Theme.LIGHT : Theme.DARK;
}
return currentTheme === Theme.LIGHT ? Theme.DARK : Theme.LIGHT;
return getCurrentTheme(currentTheme) === Theme.LIGHT ? Theme.DARK : Theme.LIGHT;

@avatus avatus requested a review from ryanclark June 11, 2024 16:26
@avatus
Copy link
Contributor Author

avatus commented Jun 14, 2024

friendly ping @ryanclark @kimlisa @rudream

// and remove the checks for unspecified
export function getCurrentTheme(currentTheme: Theme): Theme {
if (currentTheme === Theme.UNSPECIFIED) {
return getPrefersDark() ? Theme.DARK : Theme.LIGHT;
Copy link
Contributor

@kimlisa kimlisa Jun 17, 2024

Choose a reason for hiding this comment

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

how do i test this? i created a new user, and it defaulted to light theme (using brave)

nvm it worked, not sure what happened before lol.

when i do this flow:

new user -> login -> switch theme

the first click did not work, i had to click a second time to switch the theme

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't able to reproduce this first click not working in incognito or normal mode

Copy link
Contributor

@kimlisa kimlisa left a comment

Choose a reason for hiding this comment

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

just a minor comment, otherwise lgtm

@avatus
Copy link
Contributor Author

avatus commented Jun 18, 2024

friendly ping @ryanclark

Copy link
Contributor

@ryanclark ryanclark left a comment

Choose a reason for hiding this comment

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

Sorry, was waiting for the reply to Lisa's comment 🙂

@public-teleport-github-review-bot public-teleport-github-review-bot bot removed the request for review from rudream June 18, 2024 18:44
@avatus avatus added this pull request to the merge queue Jun 18, 2024
Merged via the queue into master with commit 46ba197 Jun 18, 2024
37 checks passed
@avatus avatus deleted the avatus/fix_theme branch June 18, 2024 19:35
@public-teleport-github-review-bot

@avatus See the table below for backport results.

Branch Result
branch/v16 Create PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/branch/v16 backport-required no-changelog Indicates that a PR does not require a changelog entry size/sm ui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Theme picker text is incorrect by default
4 participants