From 380af1f1ff944fc73d0100dd1dde4ab99450670d Mon Sep 17 00:00:00 2001 From: lme-axelor <102581501+lme-axelor@users.noreply.github.com> Date: Wed, 4 Dec 2024 13:30:24 +0100 Subject: [PATCH] fix: evaluate default values of config only when storage is empty (#825) * RM#87897 --- changelogs/unreleased/87897.json | 5 +++++ packages/core/src/auth/screens/UserScreen.js | 19 +++++-------------- packages/core/src/hooks/use-storage-config.ts | 18 ++++++++++++++++++ 3 files changed, 28 insertions(+), 14 deletions(-) create mode 100644 changelogs/unreleased/87897.json diff --git a/changelogs/unreleased/87897.json b/changelogs/unreleased/87897.json new file mode 100644 index 0000000000..6fd63147fc --- /dev/null +++ b/changelogs/unreleased/87897.json @@ -0,0 +1,5 @@ +{ + "title": "UI Configs: evaluate default values for config only when storage is empty", + "type": "fix", + "packages": "core" +} diff --git a/packages/core/src/auth/screens/UserScreen.js b/packages/core/src/auth/screens/UserScreen.js index ec9a358dd4..98dbe87900 100644 --- a/packages/core/src/auth/screens/UserScreen.js +++ b/packages/core/src/auth/screens/UserScreen.js @@ -17,14 +17,14 @@ */ import React, {useCallback, useEffect} from 'react'; -import {Dimensions, StyleSheet} from 'react-native'; -import DeviceInfo from 'react-native-device-info'; +import {StyleSheet} from 'react-native'; import {Screen, ScrollView, useConfig} from '@axelor/aos-mobile-ui'; import {useDispatch, useSelector} from '../../index'; import {fetchLocalizations} from '../features/localizationSlice'; import {fetchActiveUser} from '../features/userSlice'; import {DashboardsCard, ShortcutsCard, UserCard} from '../components'; import {PopupApplicationInformation} from '../../components'; +import {useDefaultValuesOfUser} from '../../hooks/use-storage-config'; const UserScreen = ({children}) => { const dispatch = useDispatch(); @@ -34,8 +34,9 @@ const UserScreen = ({children}) => { const {loadingUser, isUser} = useSelector(state => state.user); const {mobileSettings} = useSelector(state => state.appConfig); - const {setFilterConfig, setVirtualKeyboardConfig, setNbDecimalDigitForQty} = - useConfig(); + const {setNbDecimalDigitForQty} = useConfig(); + + useDefaultValuesOfUser(); useEffect(() => { fetchUser(); @@ -48,16 +49,6 @@ const UserScreen = ({children}) => { } }, [baseConfig, setNbDecimalDigitForQty]); - useEffect(() => { - const SMALL_SCREEN_HEIGHT = 500; - - DeviceInfo.getManufacturer().then(manufacturer => - setVirtualKeyboardConfig(manufacturer === 'Zebra Technologies'), - ); - - setFilterConfig(Dimensions.get('window').height > SMALL_SCREEN_HEIGHT); - }, [setFilterConfig, setVirtualKeyboardConfig]); - const fetchUser = useCallback(() => { dispatch(fetchActiveUser(userId)); }, [dispatch, userId]); diff --git a/packages/core/src/hooks/use-storage-config.ts b/packages/core/src/hooks/use-storage-config.ts index b99fc3509e..a3c9102a3f 100644 --- a/packages/core/src/hooks/use-storage-config.ts +++ b/packages/core/src/hooks/use-storage-config.ts @@ -17,10 +17,13 @@ */ import {useCallback, useEffect, useMemo} from 'react'; +import {Dimensions} from 'react-native'; +import DeviceInfo from 'react-native-device-info'; import {useConfig, useTheme} from '@axelor/aos-mobile-ui'; import {storage} from '../storage/Storage'; const CONFIG_STORAGE_KEY = 'ui_config'; +const SMALL_SCREEN_HEIGHT = 500; export const useStorageUpdater = () => { const {showFilter, showSubtitles, hideVirtualKeyboard} = useConfig(); @@ -70,3 +73,18 @@ export const useConfigUpdater = (): {updateConfigFromStorage: () => void} => { return useMemo(() => ({updateConfigFromStorage}), [updateConfigFromStorage]); }; + +export const useDefaultValuesOfUser = () => { + const {setFilterConfig, setVirtualKeyboardConfig} = useConfig(); + + useEffect(() => { + const _config = storage.getItem(CONFIG_STORAGE_KEY); + + if (_config == null) { + DeviceInfo.getManufacturer().then(manufacturer => + setVirtualKeyboardConfig(manufacturer === 'Zebra Technologies'), + ); + setFilterConfig(Dimensions.get('window').height > SMALL_SCREEN_HEIGHT); + } + }, [setFilterConfig, setVirtualKeyboardConfig]); +};