Skip to content

Commit

Permalink
fix(app): refraichit les données à chaque foit que les actions/person…
Browse files Browse the repository at this point in the history
…nes/territoires, ou qu'une personne, reviennent à l'écran (#1638)

* fix(app): refraichit les données à chaque foit que les actions/personnes/territoires, ou qu'une personne, reviennent à l'écran

* update numbers and phrase
  • Loading branch information
arnaudambro authored Sep 4, 2023
1 parent e367698 commit ecefc52
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 47 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Mano

![Mobile version](https://img.shields.io/badge/mobile%20app%20version-2.36.0-blue)
![Mobile version](https://img.shields.io/badge/mobile%20app%20version-2.36.1-blue)
[![Maintainability](https://api.codeclimate.com/v1/badges/223e4185a3e13f1ef5d0/maintainability)](https://codeclimate.com/github/SocialGouv/mano/maintainability)

Code source de [Mano](https://mano-app.fabrique.social.gouv.fr/), organisé en plusieurs services :
Expand Down
2 changes: 1 addition & 1 deletion api/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "api_mano",
"mobileAppVersion": "2.36.0",
"version": "1.283.0",
"mobileAppVersion": "2.36.1",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions api/src/controllers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ router.get("/version", async (req, res) => {
`La nouvelle version ${MOBILE_APP_VERSION} de Mano est disponible !`,
`Vous avez la version ${req.headers.version} actuellement sur votre téléphone.
Cette nouvelle version :
- Permet la compatibilité avec la nouvelle organisation des dossiers sur le navigateur
- Affiche le nome de la personne concernée dans les commentaires d'actions des comptes-rendus"
- Rafraichit les données automatiquement plus souvent pour une meilleure cohérence des données entre différents utilisateurs simultanés
- Accélère le chargement initial des données
`,
[
{ text: "Télécharger", link: `https://mano-app.fabrique.social.gouv.fr/download?ts=${Date.now()}` },
Expand Down
4 changes: 2 additions & 2 deletions app/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ android {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
multiDexEnabled true
versionCode 14
versionName "2.36.0"
versionCode 15
versionName "2.36.1"
testBuildType System.getProperty('testBuildType', 'debug') // This will later be used to control the test apk build type
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
Expand Down
4 changes: 2 additions & 2 deletions app/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "mano",
"displayName": "Mano",
"version": {
"buildNumber": 14,
"buildName": "2.36.0"
"buildNumber": 15,
"buildName": "2.36.1"
},
"bundle": {
"android": "com.mano",
Expand Down
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mano",
"version": "2.36.0",
"version": "2.36.1",
"private": true,
"scripts": {
"get-ip": "./get-ip.sh",
Expand Down
52 changes: 24 additions & 28 deletions app/src/components/Loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { reportsState } from '../recoil/reports';
import { consultationsState, formatConsultation } from '../recoil/consultations';
import { medicalFileState } from '../recoil/medicalFiles';
import { treatmentsState } from '../recoil/treatments';
import { sortByName } from '../utils/sortByName';
import { rencontresState } from '../recoil/rencontres';
import { passagesState } from '../recoil/passages';
import { groupsState } from '../recoil/groups';
Expand Down Expand Up @@ -69,7 +68,7 @@ export const DataLoader = () => {
const setProgress = useSetRecoilState(progressState);
const setFullScreen = useSetRecoilState(loaderFullScreenState);
const [organisation, setOrganisation] = useRecoilState(organisationState);
const setUser = useSetRecoilState(userState);
const [user, setUser] = useRecoilState(userState);
const organisationId = organisation?._id;

const [persons, setPersons] = useRecoilState(personsState);
Expand All @@ -93,6 +92,7 @@ export const DataLoader = () => {

const refresh = async () => {
const { showFullScreen, initialLoad } = refreshTrigger.options;

setLoading('Chargement...');
setFullScreen(showFullScreen);

Expand All @@ -101,18 +101,29 @@ export const DataLoader = () => {
and the latest user roles
*/
const userResponse = await API.get({ path: '/user/me' });
setOrganisation(userResponse.user.organisation);
setUser(userResponse.user);
if (userResponse.ok) {
if (JSON.stringify(userResponse.user.organisation) !== JSON.stringify(organisation)) {
setOrganisation(userResponse.user.organisation);
}
if (JSON.stringify(userResponse.user) !== JSON.stringify(user)) {
setUser(userResponse.user);
}
}

const serverDateResponse = await API.get({ path: '/now' });
const serverDate = serverDateResponse.data;

/*
Get number of data to download to show the appropriate loading progress bar
*/
const response = await API.get({
path: '/organisation/stats',
query: { organisation: organisationId, after: lastRefresh, withDeleted: true },
query: {
organisation: organisationId,
after: lastRefresh,
withDeleted: true,
// Medical data is never saved in cache so we always have to download all at every page reload.
withAllMedicalData: initialLoad,
},
});
if (!response.ok) {
capture('error getting stats', { extra: response });
Expand All @@ -130,33 +141,18 @@ export const DataLoader = () => {
response.data.territoryObservations +
response.data.places +
response.data.comments +
response.data.consultations +
response.data.treatments +
response.data.medicalFiles +
response.data.passages +
response.data.rencontres +
response.data.reports +
response.data.groups +
response.data.relsPersonPlace;

// medical data is never saved in cache
// so we always have to download all at every page reload
const medicalDataResponse = await API.get({
path: '/organisation/stats',
query: { organisation: organisationId, after: initialLoad ? 0 : lastRefresh, withDeleted: true },
});
if (!medicalDataResponse.ok) {
setRefreshTrigger({
status: false,
options: { showFullScreen: false, initialLoad: false },
});
return;
}

total = total + medicalDataResponse.data.consultations + medicalDataResponse.data.treatments + medicalDataResponse.data.medicalFiles;

if (initialLoad) {
const numberOfCollections = 9;
total = total + numberOfCollections; // for the progress bar to be beautiful
total = total + Object.keys(response.data).length; // for the progress bar to be beautiful
}

/*
Get persons
*/
Expand Down Expand Up @@ -191,7 +187,7 @@ export const DataLoader = () => {
/*
Get consultations
*/
if (medicalDataResponse.data.consultations || initialLoad) {
if (response.data.consultations || initialLoad) {
setLoading('Chargement des consultations');
const refreshedConsultations = await getData({
collectionName: 'consultation',
Expand All @@ -206,7 +202,7 @@ export const DataLoader = () => {
/*
Get treatments
*/
if (medicalDataResponse.data.treatments || initialLoad) {
if (response.data.treatments || initialLoad) {
setLoading('Chargement des traitements');
const refreshedTreatments = await getData({
collectionName: 'treatment',
Expand All @@ -221,7 +217,7 @@ export const DataLoader = () => {
/*
Get medicalFiles
*/
if (medicalDataResponse.data.medicalFiles || initialLoad) {
if (response.data.medicalFiles || initialLoad) {
setLoading('Chargement des informations médicales');
const refreshedMedicalFiles = await getData({
collectionName: 'medical-file',
Expand Down
9 changes: 7 additions & 2 deletions app/src/scenes/Actions/ActionsList.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useMemo, useState } from 'react';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import styled from 'styled-components';
import * as Sentry from '@sentry/react-native';
import { useRecoilState, useRecoilValue } from 'recoil';
Expand All @@ -11,7 +11,7 @@ import { MyText } from '../../components/MyText';
import { FlashListStyled } from '../../components/Lists';
import { TODO } from '../../recoil/actions';
import { actionsByStatusSelector, totalActionsByStatusSelector } from '../../recoil/selectors';
import { useNavigation, useRoute } from '@react-navigation/native';
import { useIsFocused, useNavigation, useRoute } from '@react-navigation/native';
import { refreshTriggerState, loadingState } from '../../components/Loader';
import Button from '../../components/Button';
import ConsultationRow from '../../components/ConsultationRow';
Expand Down Expand Up @@ -40,6 +40,11 @@ const ActionsList = ({ showActionSheetWithOptions }) => {
setRefreshTrigger({ status: true, options: { showFullScreen: false, initialLoad: false } });
}, [setRefreshTrigger]);

const isFocused = useIsFocused();
useEffect(() => {
if (isFocused && refreshTrigger.status !== true) onRefresh();
}, [isFocused]);

const onPressFloatingButton = async () => {
if (!user.healthcareProfessional) {
navigation.navigate('NewActionForm', { fromRoute: 'ActionsList' });
Expand Down
14 changes: 10 additions & 4 deletions app/src/scenes/Persons/Person.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import ScreenTitle from '../../components/ScreenTitle';
import FoldersNavigator from './FoldersNavigator';
import Tabs from '../../components/Tabs';
import colors from '../../utils/colors';
import { useFocusEffect } from '@react-navigation/native';
import { useFocusEffect, useIsFocused } from '@react-navigation/native';
import {
allowedFieldsInHistorySelector,
personsState,
Expand Down Expand Up @@ -40,7 +40,7 @@ const Person = ({ route, navigation }) => {
const flattenedCustomFieldsPersons = useRecoilValue(flattenedCustomFieldsPersonsSelector);
const allowedFieldsInHistory = useRecoilValue(allowedFieldsInHistorySelector);
const preparePersonForEncryption = usePreparePersonForEncryption();
const setRefreshTrigger = useSetRecoilState(refreshTriggerState);
const [refreshTrigger, setRefreshTrigger] = useRecoilState(refreshTriggerState);
const [persons, setPersons] = useRecoilState(personsState);
const actions = useRecoilValue(actionsState);
const groups = useRecoilValue(groupsState);
Expand All @@ -53,7 +53,14 @@ const Person = ({ route, navigation }) => {
const relsPersonPlace = useRecoilValue(relsPersonPlaceState);
const user = useRecoilValue(userState);

const [personDB, setPersonDB] = useState(() => persons.find((p) => p._id === route.params?.person?._id));
const personDB = useMemo(() => persons.find((p) => p._id === route.params?.person?._id), [persons, route.params?.person?._id]);

const isFocused = useIsFocused();
useEffect(() => {
if (isFocused && refreshTrigger.status !== true) {
setRefreshTrigger({ status: true, options: { showFullScreen: false, initialLoad: false } });
}
}, [isFocused]);

const castToPerson = useCallback(
(person = {}) => {
Expand Down Expand Up @@ -155,7 +162,6 @@ const Person = ({ route, navigation }) => {
})
);
setPerson(castToPerson(newPerson));
setPersonDB(newPerson);
if (alert) Alert.alert('Personne mise à jour !');
setUpdating(false);
setEditable(false);
Expand Down
7 changes: 6 additions & 1 deletion app/src/scenes/Persons/PersonsList.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useRef, useState } from 'react';
import React, { useCallback, useEffect, useRef, useState } from 'react';
import { Animated } from 'react-native';
import * as Sentry from '@sentry/react-native';
import SceneContainer from '../../components/SceneContainer';
Expand All @@ -13,6 +13,7 @@ import { arrayOfitemsGroupedByPersonSelector, itemsGroupedByPersonSelector } fro
import { selector, selectorFamily, useRecoilState, useRecoilValue } from 'recoil';
import { loadingState, refreshTriggerState } from '../../components/Loader';
import { filterBySearch } from '../../utils/search';
import { useIsFocused } from '@react-navigation/native';

const personsFilteredSelector = selectorFamily({
key: 'personsFilteredSelector',
Expand Down Expand Up @@ -80,6 +81,10 @@ const PersonsList = ({ navigation, route }) => {
setRefreshTrigger({ status: true, options: { showFullScreen: false, initialLoad: false } });
};

const isFocused = useIsFocused();
useEffect(() => {
if (isFocused && refreshTrigger.status !== true) onRefresh();
}, [isFocused]);
const onCreatePersonRequest = () => navigation.navigate('NewPersonForm', { toRoute: 'Person' });

const onFiltersPress = () => navigation.push('PersonsFilter', route.params);
Expand Down
8 changes: 6 additions & 2 deletions app/src/scenes/Territories/TerritoriesList.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo, useRef, useState } from 'react';
import React, { useEffect, useMemo, useRef, useState } from 'react';
import { Animated } from 'react-native';
import SceneContainer from '../../components/SceneContainer';
import ScreenTitle from '../../components/ScreenTitle';
Expand All @@ -11,7 +11,7 @@ import Row from '../../components/Row';
import { TerritoryIcon } from '../../icons';
import { useRecoilState, useRecoilValue } from 'recoil';
import { territoriesSearchSelector } from '../../recoil/selectors';
import { useNavigation } from '@react-navigation/native';
import { useIsFocused, useNavigation } from '@react-navigation/native';
import { refreshTriggerState, loadingState } from '../../components/Loader';

const TerritoriesList = () => {
Expand All @@ -26,6 +26,10 @@ const TerritoriesList = () => {
const onRefresh = async () => {
setRefreshTrigger({ status: true, options: { showFullScreen: false, initialLoad: false } });
};
const isFocused = useIsFocused();
useEffect(() => {
if (isFocused && refreshTrigger.status !== true) onRefresh();
}, [isFocused]);

const onCreateTerritoryRequest = () => navigation.navigate('NewTerritoryForm');

Expand Down
2 changes: 1 addition & 1 deletion website/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "website",
"mobileAppVersion": "2.36.0",
"version": "1.283.0",
"mobileAppVersion": "2.36.1",
"private": true,
"engines": {
"npm": "please-use-yarn",
Expand Down

0 comments on commit ecefc52

Please sign in to comment.