Show checked theme in color scheme menu (#4184)

This PR accounts (in the UI) for a default case where the `colorScheme`
value is undefined.

### Change type

- [x] `bugfix`

### Test plan

1. Open the editor an incognito tab
2. The Menu > Preferences > Color scheme should have a ticked selection

### Release notes

- Fixed a bug where the user's color scheme was not shown in the menu by
default.
This commit is contained in:
Steve Ruiz 2024-07-16 11:39:37 +01:00 committed by GitHub
parent bc20b2a418
commit 593c51065f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 4 additions and 1 deletions

View file

@ -711,6 +711,7 @@ export const defaultTldrawOptions: {
export const defaultUserPreferences: Readonly<{ export const defaultUserPreferences: Readonly<{
animationSpeed: 0 | 1; animationSpeed: 0 | 1;
color: "#02B1CC" | "#11B3A3" | "#39B178" | "#55B467" | "#7B66DC" | "#9D5BD2" | "#BD54C6" | "#E34BA9" | "#EC5E41" | "#F04F88" | "#F2555A" | "#FF802B"; color: "#02B1CC" | "#11B3A3" | "#39B178" | "#55B467" | "#7B66DC" | "#9D5BD2" | "#BD54C6" | "#E34BA9" | "#EC5E41" | "#F04F88" | "#F2555A" | "#FF802B";
colorScheme: "system";
edgeScrollSpeed: 1; edgeScrollSpeed: 1;
isDynamicSizeMode: false; isDynamicSizeMode: false;
isPasteAtCursorMode: false; isPasteAtCursorMode: false;

View file

@ -138,6 +138,7 @@ export const defaultUserPreferences = Object.freeze({
isWrapMode: false, isWrapMode: false,
isDynamicSizeMode: false, isDynamicSizeMode: false,
isPasteAtCursorMode: false, isPasteAtCursorMode: false,
colorScheme: 'system',
}) satisfies Readonly<Omit<TLUserPreferences, 'id'>> }) satisfies Readonly<Omit<TLUserPreferences, 'id'>>
/** @public */ /** @public */

View file

@ -44,6 +44,7 @@ export class UserPreferencesManager {
isDynamicResizeMode: this.getIsDynamicResizeMode(), isDynamicResizeMode: this.getIsDynamicResizeMode(),
} }
} }
@computed getIsDarkMode() { @computed getIsDarkMode() {
switch (this.user.userPreferences.get().colorScheme) { switch (this.user.userPreferences.get().colorScheme) {
case 'dark': case 'dark':

View file

@ -16,7 +16,7 @@ export function ColorSchemeMenu() {
const trackEvent = useUiEvents() const trackEvent = useUiEvents()
const currentColorScheme = useValue( const currentColorScheme = useValue(
'colorScheme', 'colorScheme',
() => editor.user.getUserPreferences().colorScheme, () => editor.user.getUserPreferences().colorScheme ?? 'system',
[editor] [editor]
) )