From 232c64081b790113c24e8d9c47aef5cc436c9b3f Mon Sep 17 00:00:00 2001 From: dougfabris Date: Wed, 15 Feb 2023 20:19:54 -0300 Subject: [PATCH] chore: refactor useThemeMode to save in userPreferences MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: JĂșlia Jaeger Foresti <60678893+juliajforesti@users.noreply.github.com> --- .../meteor/app/lib/server/startup/settings.ts | 19 +++++++++++++++++ .../client/sidebar/header/UserDropdown.tsx | 6 +++--- .../preferences/PreferencesGlobalSection.tsx | 21 ++++++++++++++++--- .../rocketchat-i18n/i18n/en.i18n.json | 3 ++- .../ui-theming/src/hooks/useThemeMode.ts | 14 +++++++++---- .../v1/users/UsersSetPreferenceParamsPOST.ts | 5 +++++ .../methods/saveUserPreferences.ts | 1 + 7 files changed, 58 insertions(+), 11 deletions(-) diff --git a/apps/meteor/app/lib/server/startup/settings.ts b/apps/meteor/app/lib/server/startup/settings.ts index e8419471040a..364c31741a8c 100644 --- a/apps/meteor/app/lib/server/startup/settings.ts +++ b/apps/meteor/app/lib/server/startup/settings.ts @@ -375,6 +375,25 @@ settingsRegistry.addGroup('Accounts', function () { public: true, i18nLabel: 'Group_by_Type', }); + this.add('Accounts_Default_User_Preferences_themeAppearence', 'auto', { + type: 'select', + values: [ + { + key: 'auto', + i18nLabel: 'Theme_match_system', + }, + { + key: 'light', + i18nLabel: 'Theme_light', + }, + { + key: 'dark', + i18nLabel: 'Theme_dark', + }, + ], + public: true, + i18nLabel: 'Theme_Appearence', + }); this.add('Accounts_Default_User_Preferences_sidebarViewMode', 'medium', { type: 'select', values: [ diff --git a/apps/meteor/client/sidebar/header/UserDropdown.tsx b/apps/meteor/client/sidebar/header/UserDropdown.tsx index 6bb57cdccfc2..ce74cf4945ee 100644 --- a/apps/meteor/client/sidebar/header/UserDropdown.tsx +++ b/apps/meteor/client/sidebar/header/UserDropdown.tsx @@ -192,21 +192,21 @@ const UserDropdown = ({ user, onClose }: UserDropdownProps): ReactElement => { {t('Theme_light')} - setTheme('light')} m='x4' /> + diff --git a/apps/meteor/client/views/account/preferences/PreferencesGlobalSection.tsx b/apps/meteor/client/views/account/preferences/PreferencesGlobalSection.tsx index 7c2410deb9fb..edc7e64b9dc8 100644 --- a/apps/meteor/client/views/account/preferences/PreferencesGlobalSection.tsx +++ b/apps/meteor/client/views/account/preferences/PreferencesGlobalSection.tsx @@ -1,5 +1,5 @@ import type { SelectOption } from '@rocket.chat/fuselage'; -import { Accordion, Field, FieldGroup, MultiSelect } from '@rocket.chat/fuselage'; +import { Select, Accordion, Field, FieldGroup, MultiSelect } from '@rocket.chat/fuselage'; import { useUserPreference, useTranslation } from '@rocket.chat/ui-contexts'; import type { ReactElement } from 'react'; import React, { useMemo } from 'react'; @@ -11,6 +11,7 @@ const PreferencesGlobalSection = ({ onChange, commitRef, ...props }: FormSection const t = useTranslation(); const userDontAskAgainList = useUserPreference<{ action: string; label: string }[]>('dontAskAgainList'); + const themePreference = useUserPreference<'light' | 'dark' | 'auto'>('themeAppearence'); const options = useMemo( () => (userDontAskAgainList || []).map(({ action, label }) => [action, label]) as SelectOption[], @@ -22,18 +23,26 @@ const PreferencesGlobalSection = ({ onChange, commitRef, ...props }: FormSection const { values, handlers, commit } = useForm( { dontAskAgainList: selectedOptions, + themeAppearence: themePreference, }, onChange, ); - const { dontAskAgainList } = values as { + const { dontAskAgainList, themeAppearence } = values as { dontAskAgainList: string[]; + themeAppearence: string; }; - const { handleDontAskAgainList } = handlers; + const { handleDontAskAgainList, handleThemeAppearence } = handlers; commitRef.current.global = commit; + const themeOptions: SelectOption[] = [ + ['auto', t('Theme_match_system')], + ['light', t('Theme_light')], + ['dark', t('Theme_dark')], + ]; + return ( @@ -48,6 +57,12 @@ const PreferencesGlobalSection = ({ onChange, commitRef, ...props }: FormSection /> + + {t('Theme_Appearence')} + +