Skip to content

Commit

Permalink
better sync
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud AMBROSELLI committed May 7, 2024
1 parent a79e899 commit 12557da
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 30 deletions.
16 changes: 16 additions & 0 deletions app/src/scenes/Gains/Goal.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import WrapperContainer from '../../components/WrapperContainer';
import GoalSetup from '../../components/illustrations/icons/GoalSetup';
import ModalGoalValidation from '../../components/ModalGoalValidation';
import ModalWrongValue from '../../components/ModalWrongValue';
import API from '../../services/api';
import { storage } from '../../services/storage';

const Goal = ({ navigation }) => {
const [daysWithGoalNoDrink, setDaysWithGoalNoDrink] = useRecoilState(daysWithGoalNoDrinkState);
Expand Down Expand Up @@ -119,6 +121,20 @@ const Goal = ({ navigation }) => {
action: 'GOAL_DRINKWEEK',
value: dosesPerWeek,
});
const matomoId = storage.getString('@UserIdv2');
API.post({
path: '/goal',
body: {
matomoId: matomoId,
daysWithGoalNoDrink,
dosesByDrinkingDay,
dosesPerWeek,
},
}).then((res) => {
if (res.ok) {
setGoals(res.data);
}
});
if (isOnboarded) {
navigation.navigate('GAINS_SEVRAGE');
return;
Expand Down
16 changes: 0 additions & 16 deletions app/src/scenes/Gains/Sevrage.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import {
maxDrinksPerWeekSelector,
totalDrinksByDrinkingDaySelector,
} from '../../recoil/gains';
import { storage } from '../../services/storage';
import API from '../../services/api';

const Sevrage = ({ navigation, route }) => {
const daysWithGoalNoDrink = useRecoilValue(daysWithGoalNoDrinkState);
Expand Down Expand Up @@ -58,20 +56,6 @@ const Sevrage = ({ navigation, route }) => {
<ButtonPrimary
content="J'ai compris et je commence "
onPress={() => {
const matomoId = storage.getString('@UserIdv2');
API.post({
path: '/goal',
body: {
matomoId: matomoId,
daysWithGoalNoDrink,
dosesByDrinkingDay,
dosesPerWeek,
},
}).then((res) => {
if (res.ok) {
setGoals(res.data);
}
});
logEvent({
category: 'GAINS',
action: 'GOAL_FINISH',
Expand Down
26 changes: 12 additions & 14 deletions app/src/services/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,20 +387,18 @@ export async function reconciliateDrinksToDB() {

const unsyncedDrinks = drinks.filter((drink) => !drink.isSyncedWithDB);

if (unsyncedDrinks.length) {
await API.post({
path: '/consommation/sync',
body: {
matomoId,
drinks: unsyncedDrinks,
drinksCatalog: [...ownDrinksCatalog, ...drinksCatalog],
},
}).then((response) => {
if (response?.ok) {
storage.set('@Drinks', JSON.stringify(drinks.map((drink) => ({ ...drink, isSyncedWithDB: true }))));
}
});
}
await API.post({
path: '/consommation/sync',
body: {
matomoId,
drinks: unsyncedDrinks,
drinksCatalog: [...ownDrinksCatalog, ...drinksCatalog],
},
}).then((response) => {
if (response?.ok) {
storage.set('@Drinks', JSON.stringify(drinks.map((drink) => ({ ...drink, isSyncedWithDB: true }))));
}
});
} catch (e) {
capture(e, {
extra: {
Expand Down

0 comments on commit 12557da

Please sign in to comment.