[#481] If user hasn't explicitly set a dark mode pref in Silverbullet, fall back to browser pref #1294
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This addresses #481.
To differentiate between a preference having been set explicitly (by toggling dark mode on or off within Silverbullet) or not, the
darkMode
property across the various components can now either be a boolean, orundefined
.The initial view state sets it to
undefined
.When loading the editor UI, the client store is inspected to find an explicitly set preference. If one is found, that preference gets applied. Otherwise, the browser setting is inspected (via a media query) and the UI theme gets set accordingly.
If/once an explicit preference has been set, subsequent changes to the browser setting no longer affect Silverbullet.
One caveat: If the user hasn't set a preference within Silverbullet and then changes their browser setting, the change only gets applied upon page reload. (Toggling the preference within Silverbullet itself already triggers a page reload, thus applying the changed setting automatically.)
As this is my first time interacting with this codebase, my approach may be suboptimal. I would be happy to iterate as feedback is received. For now, with my limited understanding, this seemed like the most straightforward path to take.