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

Add dark mode toggle #354 #355

Merged
merged 20 commits into from
Aug 25, 2020
Merged

Add dark mode toggle #354 #355

merged 20 commits into from
Aug 25, 2020

Conversation

tswinb
Copy link
Contributor

@tswinb tswinb commented Jul 30, 2020

Description

Adds ability for user to switch in and out of a dark mode theme.

Run with ral-facilities/datagateway#357

Testing instructions

  • Review code
  • Check Travis build
  • Review changes to test coverage

Agile board tracking

connect to #354

@tswinb tswinb added the enhancement New feature or request label Jul 30, 2020
@codecov
Copy link

codecov bot commented Jul 30, 2020

Codecov Report

Merging #355 into master will increase coverage by 0.28%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #355      +/-   ##
==========================================
+ Coverage   98.61%   98.89%   +0.28%     
==========================================
  Files          32       33       +1     
  Lines         866      906      +40     
  Branches      189      195       +6     
==========================================
+ Hits          854      896      +42     
+ Misses         11        9       -2     
  Partials        1        1              
Impacted Files Coverage Δ
src/App.tsx 83.33% <ø> (-1.67%) ⬇️
src/cookieConsent/cookieConsent.component.tsx 100.00% <ø> (ø)
src/homePage/homePage.component.tsx 100.00% <ø> (ø)
src/mainAppBar/mainAppBar.component.tsx 88.88% <ø> (ø)
...rc/navigationDrawer/navigationDrawer.component.tsx 95.65% <ø> (ø)
src/pageNotFound/pageNotFound.component.tsx 100.00% <ø> (ø)
src/cookieConsent/cookiesPage.component.tsx 100.00% <100.00%> (ø)
src/mainAppBar/userProfile.component.tsx 100.00% <100.00%> (ø)
src/pageContainer.component.tsx 100.00% <100.00%> (ø)
src/preloader/preloader.component.tsx 100.00% <100.00%> (ø)
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 76b569b...34ebabe. Read the comment docs.

@tswinb tswinb linked an issue Aug 6, 2020 that may be closed by this pull request
2 tasks
@tswinb tswinb marked this pull request as ready for review August 10, 2020 14:11
Copy link
Member

@louise-davies louise-davies left a comment

Choose a reason for hiding this comment

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

The top bar goes black when in dark mode - surely this should remain coloured? It doesn't present as much as a focus point as light mode does.

Additionally, we see a "flash" of light mode when loading the page - I wonder if we can prevent this by doing the dark mode loading first thing before rendering anything.

Comment on lines 216 to 223
// load dark mode preference from local storage into store
// otherwise, intial state is false
const darkModeLocalStorage = localStorage.getItem('darkMode');
if (darkModeLocalStorage) {
const preference = darkModeLocalStorage === 'true' ? true : false;
dispatch(loadDarkModePreference(preference));
}

Copy link
Member

Choose a reason for hiding this comment

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

This should probably either be moved to the top of the settings loading, or before even doing the settings.json request to prevent the light theme "flash" if a user has a preference for dark mode. Additionally, it might also be worth using prefers-color-scheme if there is no local storage set: see https://blog.bitsrc.io/how-to-sync-your-react-app-with-the-system-color-scheme-78c0ad00074b for info on how to use this

Comment on lines 50 to 51
const darkModeLocalStorage = localStorage.getItem('darkMode');
const darkModePreference = darkModeLocalStorage === 'true' ? true : false;
Copy link
Member

Choose a reason for hiding this comment

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

Same as before, might want to use prefers-color-scheme - perhaps this tiny bit of common code could be refactored out? Or, if the prefers-color-scheme change is tiny perhaps it's not worth it

Comment on lines 156 to 158
const darkModeLocalStorage = localStorage.getItem('darkMode');
const darkModePreference = darkModeLocalStorage === 'true' ? true : false;
const theme = buildTheme(darkModePreference);
Copy link
Member

Choose a reason for hiding this comment

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

Surely if the action is of type LoadDarkModePreferenceType you can just get the preference from action.payload.preference rather than querying localstorage?

const loadDarkModePreferenceAction = {
type: LoadDarkModePreferenceType,
payload: {
preference: false,
Copy link
Member

Choose a reason for hiding this comment

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

I thought the type of LoadDarkModePreferencePayload means this should be darkMode: false? Or am I misunderstanding

@tswinb
Copy link
Contributor Author

tswinb commented Aug 14, 2020

The top bar goes black when in dark mode - surely this should remain coloured? It doesn't present as much as a focus point as light mode does.

@louise-davies , I was following material-ui.com on this (they change to to black). It's quite bright otherwise, but I can change it if you think the focus point is needed?

@tswinb
Copy link
Contributor Author

tswinb commented Aug 18, 2020

To do

  • check code coverage for changes after adding reading prefers-color-scheme
  • fix tests after latest commit

@agbeltran
Copy link
Member

@tswinb now checking accessibility standards

Copy link
Member

@louise-davies louise-davies left a comment

Choose a reason for hiding this comment

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

Looks good!

@tswinb tswinb merged commit 0763847 into master Aug 25, 2020
@tswinb tswinb deleted the feature/dark-mode-#354 branch August 25, 2020 09:26
joshuadkitenge added a commit that referenced this pull request Mar 1, 2024
joshuadkitenge added a commit that referenced this pull request Mar 1, 2024
joshuadkitenge added a commit that referenced this pull request Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement dark mode with user controlled toggle
3 participants