Skip to content

FEATURE: User selectable color schemes - #10544

Merged
pmusaraj merged 6 commits into
masterfrom
user-selectable-color-schemes
Aug 28, 2020
Merged

FEATURE: User selectable color schemes#10544
pmusaraj merged 6 commits into
masterfrom
user-selectable-color-schemes

Conversation

@pmusaraj

Copy link
Copy Markdown
Contributor

This lets administrators mark color schemes as user_selectable, which then are displayed as options in the user's Preferences > Interface screen. Users can pick a regular color scheme and (if dark color schemes are available) a dark mode color scheme.

screencast 2020-08-21 14-52-30

Behind the scenes this PR:

  • adds a user_selectable column to the color_schemes table
  • adds a color_scheme_id column to user_options (a dark_scheme_id column was already added a few weeks ago)
  • allows the regular/dark scheme preference to be stored in a cookie or in the user_options table (similar to theme/text size choices)
  • adds a color-scheme-picker.js library that can be used to build similar widgets in plugins/theme components (for example, to toggle color scheme choices in the hamburger menu)
  • adds a new color-scheme-stylesheet route that facilitates previewing users' color scheme choices on-the-fly

@eviltrout eviltrout left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm mostly concerned about the two set operations that do nothing. Otherwise this is in pretty good shape.

return I18n.t("user.color_schemes.default_description");
},

selectedColorSchemeId: computed({

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is this set up to do a no-op here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, no good reason. My goal was to have selectedColorSchemeId take the value from the session as its default without updating the source, but it wasn't done right.

I have refactored this now, with help from @jjaffeux, it's much cleaner, the values are set in the controller's init(). Another nicety: the session values don't need to be transiting via the preferences-interface route.

textSize: user.get("currentTextSize"),
themeId: currentThemeId(),
userColorSchemeId:
parseInt(Session.currentProp("userColorSchemeId"), 10) || null,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You should be able to say this.session.userColorSchemeId without importing it.

return listColorSchemes(this.site);
},

@discourseComputed("userSelectableColorSchemes")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

pretty sure you can one line it:

showColorSchemeSelector: reads("userSelectableColorSchemes.length")

return value;
},
get() {
return this.get("userColorSchemeId");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

do we need the get here ?

return colorSchemes && colorSchemes.length;
},

@discourseComputed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

selectedColorSchemeNoneLabel: i18n("user.color_schemes.default_description"),

return value;
},
get() {
return this.get("userDarkSchemeId");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

think we can get rid of the get here

});

if (colorSchemeId < 0) {
const defaultTheme = this.userSelectableThemes.find(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

findBy("id", this.themeId)

"model.user_option.dark_scheme_id",
this.enableDarkMode ? null : -1
);
const makeColorSchemeDefault = this.makeColorSchemeDefault;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's a nitpick and up to you, but I tend to avoid creating a variable in this case, I think the fact that you have to grep for two cases instead of one now largely surpasses the 5 chars

@pmusaraj
pmusaraj merged commit b7cfc9e into master Aug 28, 2020
@pmusaraj
pmusaraj deleted the user-selectable-color-schemes branch August 28, 2020 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants