Skip to content

Commit

Permalink
refactor: move header band to auth header actions hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
lme-axelor committed Feb 28, 2024
1 parent bba3ade commit 6fe03b5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
14 changes: 0 additions & 14 deletions packages/core/src/app/RootNavigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {useTranslator} from '../i18n';
import {showToastMessage} from '../utils';
import {logout} from '../features/authSlice';
import {useSessionExpired} from '../apiProviders/config';
import {useLoaderListener} from '../components';

const {Navigator, Screen} = createNativeStackNavigator();

Expand All @@ -50,7 +49,6 @@ const RootNavigator = ({

const {sessionExpired} = useSessionExpired();
const {registerHeaderBand} = useHeaderBand();
const {numberProcesses} = useLoaderListener();

const {logged} = useSelector(state => state.auth);

Expand Down Expand Up @@ -123,18 +121,6 @@ const RootNavigator = ({
}
}, [handleSessionExpired, sessionExpired]);

useEffect(() => {
registerHeaderBand({
key: 'loader',
text: I18n.t('Base_Loader_ProccessesInBackground', {
numberProcesses,
}),
color: Colors.cautionColor,
order: 15,
showIf: numberProcesses > 0,
});
}, [I18n, Colors, registerHeaderBand, numberProcesses]);

return (
<Navigator screenOptions={{headerShown: false}}>
{!logged ? (
Expand Down
22 changes: 22 additions & 0 deletions packages/core/src/auth/hooks/use-auth-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ import {useTranslator} from '../../i18n';
import {useNavigation} from '../../hooks/use-navigation';
import {useOnline} from '../../features/onlineSlice';
import {formatDateTime} from '../../utils/formatters';
import {useLoaderListener} from '../../components';

export const useAuthHeaders = () => {
useUserProfileActions();
useAuthHeaderBands();
useLoaderHeaderBand();
};

const useUserProfileActions = () => {
Expand Down Expand Up @@ -94,3 +96,23 @@ const useAuthHeaderBands = () => {
});
}, [I18n, Colors, registerHeaderBand, online.isEnabled]);
};

const useLoaderHeaderBand = () => {
const Colors = useThemeColor();
const I18n = useTranslator();

const {registerHeaderBand} = useHeaderBand();
const {numberProcesses} = useLoaderListener();

useEffect(() => {
registerHeaderBand({
key: 'loader',
text: I18n.t('Base_Loader_ProccessesInBackground', {
numberProcesses,
}),
color: Colors.cautionColor,
order: 15,
showIf: numberProcesses > 0,
});
}, [I18n, Colors, registerHeaderBand, numberProcesses]);
};
2 changes: 1 addition & 1 deletion packages/core/src/i18n/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
"Base_Loader_DoNotCloseTheApp": "Do not close the application until the process is done.",
"Base_Loader_NotifyMe": "Notify me when it's ready",
"Base_Loader_LoadingInProgress": "Loading in progress",
"Base_Loader_ProccessesInBackground": "{{numberProcesses}} processes are running in background. Do not close the application.",
"Base_Loader_ProccessesInBackground": "{{numberProcesses}} process(es) running in background, do not close the application.",
"Base_SliceAction_FetchAttachedFiles": "fetch attached files",
"Base_SliceAction_FetchFilesDetails": "fetch file details",
"Base_SliceAction_FetchMetaModule": "fetch meta modules",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/i18n/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
"Base_Loader_DoNotCloseTheApp": "Veuillez ne pas fermer l'application avant que le processus soit terminé.",
"Base_Loader_NotifyMe": "M'avertir lorsqu'il est prêt",
"Base_Loader_LoadingInProgress": "Chargement en cours",
"Base_Loader_ProccessesInBackground": "{{numberProcesses}} processus sont en cours d'exécution en arrière-plan. Veuillez ne pas fermer l'application.",
"Base_Loader_ProccessesInBackground": "{{numberProcesses}} traitement(s) en cours d'exécution en arrière-plan, veuillez ne pas fermer l'application.",
"Base_SliceAction_FetchAttachedFiles": "récupération des fichiers joints",
"Base_SliceAction_FetchFilesDetails": "récupération des détails du fichier",
"Base_SliceAction_FetchMetaModule": "récupération des modules",
Expand Down

0 comments on commit 6fe03b5

Please sign in to comment.