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

Fetch dark mode settings from system settings #3016

Merged
merged 14 commits into from
May 10, 2023
Merged

Fetch dark mode settings from system settings #3016

merged 14 commits into from
May 10, 2023

Conversation

yomete
Copy link
Contributor

@yomete yomete commented Apr 20, 2023

Description

🤖 Generated by Copilot at 72f5b0c

This pull request improves the theme mode switching functionality in the UI. It adds a new ThemeToggle component that replaces the DarkModeToggle component and supports more theme options. It also updates the ThemeProvider and the Dropdown components to work with the new theme logic and enhance the UI consistency.

Changes made

🤖 Generated by Copilot at 72f5b0c

  • Rename DarkModeToggle component to ThemeToggle and add functionality to switch between light, dark, or system theme modes (link, link, link)
  • Modify ThemeProvider component to use redux store and local storage for theme mode and listen to media query for system theme changes (link)
  • Adjust Dropdown component to allow rendering button with only an element and no text, and to fit the content and position of the ThemeToggle component (link, link, link)
  • Delete unused DarkModeToggle.tsx file (link)

Fixes #2895

@yomete yomete marked this pull request as ready for review April 24, 2023 07:22
@yomete yomete requested a review from a team as a code owner April 24, 2023 07:22
}
};

if (localStorage['parcaDarkModeSystemSettings']) dispatch(setDarkMode(mediaQuery.matches));
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of manually manipulating the state in localStorage, should we move this to the ui redux state so that it gets persisted automatically?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm so I am manipulating the localStorage because we need to know on the next visit to the Parca app, if a user had previously set that they would like to use the system settings to determine the theme mode.

If I were to use the redux state, doesn't that mean, it wouldn't get remembered on the next visit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I see what you mean, Redux's persistence already utilizes localStorage, and I should just use that instead of the localStorage API right?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, I meant not to interact with localStorage at all.
From this code:

const slicesToPersist = ['ui'];

If I'm not mistaken, we've configured Redux to persist the ui slice. So internally, Redux should handle the localStorage saving and restoring logic.
And if we move parcaDarkModeSystemSettings field to the ui slice then, we don't have to interact with the localStorage no? Just save it to redux state and it takes care of the persistence.

Yes, that's right, missing the second part of our reply.

Copy link
Contributor Author

@yomete yomete Apr 27, 2023

Choose a reason for hiding this comment

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

yeah that makes total sense. Thanks for catching that. I'll refactor that bit.

@yomete
Copy link
Contributor Author

yomete commented May 4, 2023

@manojVivek this is ready for another review.

Copy link
Contributor

@manojVivek manojVivek 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 couple of minor questions, looks good otherwise.

setSystemSettingsDarkMode(false);
}
};
});
Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose the dependency array [] is missed here? Or thats intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added that bit 👍🏾

};

if (isSystemSettingsTheme) dispatch(setDarkMode(mediaQuery.matches));
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above

Copy link
Contributor

@manojVivek manojVivek left a comment

Choose a reason for hiding this comment

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

Lgtm!

@yomete yomete merged commit da4ac3f into main May 10, 2023
37 checks passed
@maxbrunet maxbrunet deleted the dark-mode-settings branch May 17, 2023 21:45
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.

Read dark mode state from system settings
2 participants