Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud AMBROSELLI committed May 7, 2024
1 parent cb78d5f commit 2a8410c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
14 changes: 9 additions & 5 deletions api/src/controllers/goal.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,15 @@ router.get(
where: { id: currentGoal.id },
});
if (!thisWeekGoal) {
thisWeekGoal = await prisma.goal.upsert({
where: { id: currentGoal.id },
create: currentGoal,
data: currentGoal,
});
try {
thisWeekGoal = await prisma.goal.upsert({
where: { id: currentGoal.id },
create: currentGoal,
data: currentGoal,
});
} catch (e) {
console.error("error while creating goal because created somewhere else", e);
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion app/src/scenes/Gains/Goal.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useRef, useMemo, useState, useEffect } from 'react';
import { useRecoilState, useRecoilValue } from 'recoil';
import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil';
import { useIsFocused } from '@react-navigation/native';
import styled from 'styled-components';
import { v4 as uuidv4 } from 'uuid';
Expand Down Expand Up @@ -31,6 +31,9 @@ import { storage } from '../../services/storage';
const Goal = ({ navigation }) => {
const [daysWithGoalNoDrink, setDaysWithGoalNoDrink] = useRecoilState(daysWithGoalNoDrinkState);
const previousDaysWithGoalNoDrink = useRef(daysWithGoalNoDrink);
const dosesByDrinkingDay = useRecoilValue(totalDrinksByDrinkingDaySelector);
const setGoals = useSetRecoilState(goalsState);

const toggleDayWithGoalNoDrink = (day) => {
const newState = daysWithGoalNoDrink.includes(day)
? daysWithGoalNoDrink.filter((d) => d !== day)
Expand Down
12 changes: 0 additions & 12 deletions app/src/scenes/Gains/Sevrage.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
import React from 'react';
import styled from 'styled-components';
import { useRecoilValue, useSetRecoilState } from 'recoil';
import { SafeAreaView } from 'react-native';
import ButtonPrimary from '../../components/ButtonPrimary';
import { logEvent } from '../../services/logEventsWithMatomo';
import WrapperContainer from '../../components/WrapperContainer';
import TextStyled from '../../components/TextStyled';
import {
daysWithGoalNoDrinkState,
goalsState,
maxDrinksPerWeekSelector,
totalDrinksByDrinkingDaySelector,
} from '../../recoil/gains';

const Sevrage = ({ navigation, route }) => {
const daysWithGoalNoDrink = useRecoilValue(daysWithGoalNoDrinkState);
const dosesByDrinkingDay = useRecoilValue(totalDrinksByDrinkingDaySelector);
const dosesPerWeek = useRecoilValue(maxDrinksPerWeekSelector);
const setGoals = useSetRecoilState(goalsState);

return (
<>
<SafeAreaView className="bg-[#39CEC0]" />
Expand Down

0 comments on commit 2a8410c

Please sign in to comment.