From c724ec677fda1e926b8460f766cbb2748e4bf94b Mon Sep 17 00:00:00 2001 From: Arnaud AMBROSELLI Date: Sat, 2 Nov 2024 12:51:48 +0100 Subject: [PATCH] fix: je nai pas bu depuis x jours --- expo/src/scenes/ConsoFollowUp/Feed.js | 89 +++++++++++---------------- 1 file changed, 35 insertions(+), 54 deletions(-) diff --git a/expo/src/scenes/ConsoFollowUp/Feed.js b/expo/src/scenes/ConsoFollowUp/Feed.js index 07ae54e0c..85c73aeb8 100644 --- a/expo/src/scenes/ConsoFollowUp/Feed.js +++ b/expo/src/scenes/ConsoFollowUp/Feed.js @@ -70,8 +70,7 @@ const Header = ({ onScrollToDate, tab, setTab, selectedMonth, setSelectedMonth } const showNoConsoSinceLongTime = useMemo( // the last day entered is before today () => { - const date = - dayjs(dateLastEntered).format("YYYY-MM-DD") < dayjs().add(-1, "day").format("YYYY-MM-DD"); + const date = dayjs(dateLastEntered).format("YYYY-MM-DD") < dayjs().add(-1, "day").format("YYYY-MM-DD"); return date; }, [dateLastEntered] @@ -81,6 +80,7 @@ const Header = ({ onScrollToDate, tab, setTab, selectedMonth, setSelectedMonth } const differenceDay = dayjs().diff(dayjs(dateLastEntered), "d"); const matomoId = storage.getString("@UserIdv2"); setNoConsoLoading(true); + const noConsos = []; for (let i = 1; i <= differenceDay; i++) { const currentDate = dayjs(dateLastEntered).add(i, "d"); const noConso = { @@ -88,6 +88,7 @@ const Header = ({ onScrollToDate, tab, setTab, selectedMonth, setSelectedMonth } quantity: 1, timestamp: makeSureTimestamp(currentDate), id: uuidv4(), + isSyncedWithDB: false, }; logEvent({ category: "CONSO", @@ -104,23 +105,16 @@ const Header = ({ onScrollToDate, tab, setTab, selectedMonth, setSelectedMonth } quantity: Number(noConso.quantity), date: noConso.timestamp, }, - }).then((response) => { - if (response.ok) { - setDrinks((state) => { - return state.map((drink) => { - if (drink.id === noConso.id) { - return { - ...drink, - isSyncedWithDB: true, - }; - } - return drink; - }); - }); - } - }); + }) + .then((response) => { + if (response.ok) { + noConso.isSyncedWithDB = true; + } + noConsos.push(noConso); + }) + .catch((err) => console.log("Post no consos err", err)); } - setDrinks((state) => sortConsosByTimestamp(state)); + setDrinks((state) => sortConsosByTimestamp([...state, ...noConsos])); setNoConsoLoading(false); API.get({ path: "/goal/list", @@ -139,9 +133,7 @@ const Header = ({ onScrollToDate, tab, setTab, selectedMonth, setSelectedMonth } }, [dateLastEntered, setDrinks, goals, setGoals]); return ( <> - +

Calendrier

@@ -152,17 +144,17 @@ const Header = ({ onScrollToDate, tab, setTab, selectedMonth, setSelectedMonth } hitSlop={hitSlop(15)} onPress={() => { setSelectedMonth(selectedMonth.subtract(1, "month")); - }}> + }} + > - - {selectedMonth.format("MMMM YYYY").capitalize()} - + {selectedMonth.format("MMMM YYYY").capitalize()} { setSelectedMonth(selectedMonth.add(1, "month")); - }}> + }} + > @@ -198,7 +190,8 @@ const Header = ({ onScrollToDate, tab, setTab, selectedMonth, setSelectedMonth } category: "CONSO", action: "CONSO_OPEN_CONSO_ADDSCREEN", }); - }}> + }} + > Ajoutez une conso @@ -219,14 +212,13 @@ const Header = ({ onScrollToDate, tab, setTab, selectedMonth, setSelectedMonth } }); navigation.navigate("GAINS_ESTIMATE_PREVIOUS_CONSUMPTION"); }} - className="flex flex-row items-center justify-around bg-[#E8E8F3] rounded-lg py-4 px-8 border border-[#4030a5]"> + className="flex flex-row items-center justify-around bg-[#E8E8F3] rounded-lg py-4 px-8 border border-[#4030a5]" + > Complétez l' - estimation de votre consommation initiale et - fixez-vous un - objectif pour calculer vos gains dans le - temps ! + estimation de votre consommation initiale et fixez-vous un + objectif pour calculer vos gains dans le temps ! @@ -346,13 +338,7 @@ const Feed = () => { ); }; -const FeedDayItem = ({ - date, - index, - addDrinksRequest, - deleteDrinkRequest, - updateDrinksContextsRequest, -}) => { +const FeedDayItem = ({ date, index, addDrinksRequest, deleteDrinkRequest, updateDrinksContextsRequest }) => { const days = useRecoilValue(feedDaysSelector); const drinksContexts = useRecoilValue(drinksContextsState); const { drinksByDay } = useRecoilValue(derivedDataFromDrinksState); @@ -363,9 +349,7 @@ const FeedDayItem = ({ const noDrinksYet = !drinksOfTheDay.length; const isContext = drinksContexts[date] && - (drinksContexts[date].note || - drinksContexts[date].emotion || - drinksContexts[date].context.length > 0); + (drinksContexts[date].note || drinksContexts[date].emotion || drinksContexts[date].context.length > 0); const noDrinksConfirmed = drinksOfTheDay.length === 1 && drinksOfTheDay[0].drinkKey === NO_CONSO; const [timestampSelected, setTimestampSelected] = useState(null); @@ -393,19 +377,19 @@ const FeedDayItem = ({ return ( + style={{ paddingHorizontal: defaultPaddingFontScale() }} + > { setTimestampSelected(null); - }}> + }} + > <> {!!isFirst && } - {!!noDrinksYet && ( - - )} + {!!noDrinksYet && } {noDrinksConfirmed ? ( ) : ( @@ -464,9 +448,7 @@ const FeedDayItem = ({ ) : ( )} - - Note et contexte - + Note et contexte { @@ -475,7 +457,8 @@ const FeedDayItem = ({ category: "CONTEXT", action: "USED_MODIFY_CONTEXT", }); - }}> + }} + > @@ -489,9 +472,7 @@ const FeedDayItem = ({ const contextName = contextsCatalogObject[_drinksContext].displayFeed; return ( - + {contextName} );