diff --git a/backend/user/src/user_config.py b/backend/user/src/user_config.py index 470f0072..42dfa2ef 100644 --- a/backend/user/src/user_config.py +++ b/backend/user/src/user_config.py @@ -25,6 +25,7 @@ class UserConfigType(TypedDict, total=False): hide_watched: bool show_ignored_only: bool show_subed_only: bool + show_help_text: bool class UserConfig: @@ -43,6 +44,7 @@ class UserConfig: hide_watched=False, show_ignored_only=False, show_subed_only=False, + show_help_text=True, ) VALID_STYLESHEETS = get_stylesheets() @@ -83,14 +85,12 @@ class UserConfig: def set_value(self, key: str, value: str | bool | int): """Set or replace a configuration value for the user""" self._validate(key, value) - old = self.get_value(key) - data = {"doc": {"config": {key: value}}} response, status = ElasticWrap(self.es_update_url).post(data) if status < 200 or status > 299: raise ValueError(f"Failed storing user value {status}: {response}") - print(f"User {self._user_id} value '{key}' change: {old} -> {value}") + print(f"User {self._user_id} value '{key}' change: to {value}") def _validate(self, key, value): """validate key and value""" @@ -115,6 +115,7 @@ class UserConfig: "hide_watched": bool, "show_ignored_only": bool, "show_subed_only": bool, + "show_help_text": bool, } validation_value = valid_values.get(key) @@ -138,7 +139,7 @@ class UserConfig: self.sync_defaults() config = self._DEFAULT_USER_SETTINGS else: - config = response["_source"]["config"] + config = self.sync_new_defaults(response["_source"]["config"]) return config @@ -148,3 +149,12 @@ class UserConfig: {"config": self._DEFAULT_USER_SETTINGS} ) print(f"set default config for user {self._user_id}: {response}") + + def sync_new_defaults(self, config): + """sync new defaults""" + for key, value in self._DEFAULT_USER_SETTINGS.items(): + if key not in config: + self.set_value(key, value) + config.update({key: value}) + + return config diff --git a/frontend/src/api/actions/updateUserConfig.ts b/frontend/src/api/actions/updateUserConfig.ts index c0ff4a5d..c091741e 100644 --- a/frontend/src/api/actions/updateUserConfig.ts +++ b/frontend/src/api/actions/updateUserConfig.ts @@ -27,6 +27,7 @@ export type UserConfigType = { hide_watched: boolean; show_ignored_only: boolean; show_subed_only: boolean; + show_help_text: boolean; }; const updateUserConfig = async (config: Partial): Promise => { diff --git a/frontend/src/pages/SettingsUser.tsx b/frontend/src/pages/SettingsUser.tsx index 47cf64e4..c8f2087a 100644 --- a/frontend/src/pages/SettingsUser.tsx +++ b/frontend/src/pages/SettingsUser.tsx @@ -7,6 +7,7 @@ import Button from '../components/Button'; import useIsAdmin from '../functions/useIsAdmin'; import { useUserConfigStore } from '../stores/UserConfigStore'; import { useEffect, useState } from 'react'; +import ToggleConfig from '../components/ToggleConfig'; const SettingsUser = () => { const { userConfig, setPartialConfig } = useUserConfigStore(); @@ -16,13 +17,15 @@ const SettingsUser = () => { const [styleSheet, setStyleSheet] = useState(userConfig.config.stylesheet); const [styleSheetRefresh, setStyleSheetRefresh] = useState(false); const [pageSize, setPageSize] = useState(userConfig.config.page_size); + const [showHelpText, setShowHelpText] = useState(userConfig.config.show_help_text); useEffect(() => { (async () => { setStyleSheet(userConfig.config.stylesheet); setPageSize(userConfig.config.page_size); + setShowHelpText(userConfig.config.show_help_text); })(); - }, [userConfig.config.page_size, userConfig.config.stylesheet]); + }, [userConfig.config.page_size, userConfig.config.stylesheet, userConfig.config.show_help_text]); const handleStyleSheetChange = async (selectedStyleSheet: ColourVariants) => { setPartialConfig({ stylesheet: selectedStyleSheet }); @@ -34,6 +37,10 @@ const SettingsUser = () => { setPartialConfig({ page_size: pageSize }); }; + const handleShowHelpTextChange = async (configKey: string, configValue: boolean) => { + setPartialConfig({ [configKey]: configValue }); + }; + const handlePageRefresh = () => { navigate(0); setStyleSheetRefresh(false); @@ -103,6 +110,16 @@ const SettingsUser = () => { +
+
+

Show help text

+
+ +
{isAdmin && ( diff --git a/frontend/src/stores/UserConfigStore.ts b/frontend/src/stores/UserConfigStore.ts index 632f97f5..d3cec6b7 100644 --- a/frontend/src/stores/UserConfigStore.ts +++ b/frontend/src/stores/UserConfigStore.ts @@ -29,6 +29,7 @@ export const useUserConfigStore = create(set => ({ hide_watched: false, show_ignored_only: false, show_subed_only: false, + show_help_text: true, }, }, setUserConfig: userConfig => set({ userConfig }),