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: Enable flexible number of colors for themes #3482

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

joeng03
Copy link
Contributor

@joeng03 joeng03 commented Aug 4, 2023

  • instead of fixing the number of colors for a theme to 8 colors, now we are able to support a variable number of colors
  • add a new theme, 'Tequila' with 10 colors as Proof of Concept

Context

#3443

Implementation

Screenshot 2023-08-03 124401
One issue I was facing was that when shifting from themes with higher number of colors to themes with lower number of colors, some courses would get rendered as white color as their colorIndex exceeds the numOfColors of the current theme. One way to solve this would be to dispatch a new action to set the colorIndex of all courses to colorIndex % numOfColors.

Other Information

- instead of fixing the number of colors for a theme to 8 colors,
  now we are able to support a variable number of colors
- add a new theme, 'Tequila' with 10 colors as Proof of Concept
@vercel
Copy link

vercel bot commented Aug 4, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nusmods-export ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 26, 2024 11:10am
nusmods-website ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 26, 2024 11:10am

@vercel
Copy link

vercel bot commented Aug 4, 2023

@joeng03 is attempting to deploy a commit to a Personal Account owned by @nusmodifications on Vercel.

@nusmodifications first needs to authorize it.

@codecov
Copy link

codecov bot commented Aug 7, 2023

Codecov Report

Attention: Patch coverage is 43.90244% with 23 lines in your changes missing coverage. Please review.

Project coverage is 54.58%. Comparing base (988c6fd) to head (0699b0a).
Report is 21 commits behind head on master.

Files with missing lines Patch % Lines
website/src/reducers/timetables.ts 0.00% 10 Missing ⚠️
website/src/actions/timetables.ts 16.66% 5 Missing ⚠️
website/src/views/settings/SettingsContainer.tsx 0.00% 3 Missing ⚠️
website/src/entry/export/TimetableOnly.tsx 0.00% 2 Missing ⚠️
website/src/views/venues/VenueDetails.tsx 0.00% 2 Missing ⚠️
website/src/views/settings/ThemeOption.tsx 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3482      +/-   ##
==========================================
+ Coverage   54.52%   54.58%   +0.05%     
==========================================
  Files         274      274              
  Lines        6076     6119      +43     
  Branches     1455     1461       +6     
==========================================
+ Hits         3313     3340      +27     
- Misses       2763     2779      +16     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@zwliew
Copy link
Member

zwliew commented Aug 10, 2023

Hi, thanks for working on this! Is this PR still WIP as the description states or is it ready for review?

@joeng03
Copy link
Contributor Author

joeng03 commented Aug 10, 2023

It is ready for review!

website/src/reducers/timetables.ts Outdated Show resolved Hide resolved
website/src/reducers/timetables.ts Outdated Show resolved Hide resolved
website/src/reducers/timetables.ts Outdated Show resolved Hide resolved
website/src/reducers/timetables.ts Outdated Show resolved Hide resolved
Comment on lines +145 to +148
onSelectTheme={() => {
props.selectTheme(theme);
props.reassignAllModulesColor(theme.numOfColors);
}}
Copy link
Member

@zwliew zwliew Aug 11, 2023

Choose a reason for hiding this comment

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

This has the disadvantage of updating the UI twice because we are dispatching two actions here. To fix this, you could remove the reassignAllModulesColor action, and change the timetables reducer to react to the SELECT_THEME action.


return {
...state,
id: newTheme,
id: newTheme.id,
numOfColors: newTheme.numOfColors,
Copy link
Member

@zwliew zwliew Aug 11, 2023

Choose a reason for hiding this comment

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

Since this affects local storage schema, we should be more careful here. In the long run, I don't think we'll want to store numOfColors in ThemeState as it only contains user customizable data (i.e. current theme ID, should show title, orientation of timetable).

Since numOfColors is a static property of a theme, instead of storing it in Redux, we should store it in a predefined readonly map like the one that you've defined in themes.json. This has the added benefit of you no longer having to pass numOfColors around everywhere as you can just read it from the map.

That said, if/when we add user-defined themes, they should be stored in Redux, but likely in a different place instead of ThemeState.

@@ -148,6 +149,19 @@ function semColors(state: ColorMapping = defaultSemColorMap, action: Actions): C
}
}

function recolor(state: SemesterColorMap, numOfColors: number): SemesterColorMap {
Copy link
Member

Choose a reason for hiding this comment

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

Minor thought: This is a fine approach, but I wonder if it'd be better to remove this function and leave color indices as is. Instead, we could modulo the colorIndex when rendering colors. I doubt it makes any difference though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason I used an action to reassign the colors is that there are too many places where we have to modulo the colorIndex when rendering colors, which might make code changes hard to keep track of.

@zwliew
Copy link
Member

zwliew commented Aug 11, 2023

The implementation looks sound but I have a few concerns mainly regarding (1) storing numOfColors in Redux and (2) dispatching multiple actions successively. Please let me know what you think :)

@joeng03
Copy link
Contributor Author

joeng03 commented Aug 13, 2023

Thanks for taking time to review my PR :)

  1. Storing numOfColor in Redux is a temporary step as we will store all themes ( default and user defined) in a new Redux state, which uses an array of hexcodes to track all colors of a theme, then use an id in ThemeState to reference the current theme.

  2. I agree that dispatching multiple actions is suboptimal, and we can refactor the code to reassign the colorIndex in the selectTheme instead. However, since we no longer need numOfColors in the next step, it may be more efficient to move straight to the next step ( use an array of hexcodes instead of numOfColors to render colors of a theme) since we will no longer need the reassignAllColors action anymore.

Would it be better if we combine steps 1 and 2 in this PR?

@zwliew
Copy link
Member

zwliew commented Nov 26, 2024

Thanks for taking time to review my PR :)

  1. Storing numOfColor in Redux is a temporary step as we will store all themes ( default and user defined) in a new Redux state, which uses an array of hexcodes to track all colors of a theme, then use an id in ThemeState to reference the current theme.
  2. I agree that dispatching multiple actions is suboptimal, and we can refactor the code to reassign the colorIndex in the selectTheme instead. However, since we no longer need numOfColors in the next step, it may be more efficient to move straight to the next step ( use an array of hexcodes instead of numOfColors to render colors of a theme) since we will no longer need the reassignAllColors action anymore.

Would it be better if we combine steps 1 and 2 in this PR?

Really sorry for the late review! I agree with what you said -- it would be more straightforward to combine steps 1 and 2. Would you be interested in continuing with this PR? I'd like to try to get a solution merged by the end of the holidays.

@joeng03
Copy link
Contributor Author

joeng03 commented Nov 27, 2024

Yep, will be working on it in December since I’m having finals now

@zwliew
Copy link
Member

zwliew commented Nov 28, 2024

That's great to hear :) Best of luck for finals!

@zwliew zwliew self-assigned this Dec 4, 2024
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