Skip to content

Commit

Permalink
Merge pull request #38 from SocialGouv/feat--savings
Browse files Browse the repository at this point in the history
feat: savings in euro and kcal
  • Loading branch information
arnaudambro authored May 13, 2022
2 parents 231d8dc + 53123b4 commit c66bb52
Show file tree
Hide file tree
Showing 7 changed files with 258 additions and 192 deletions.
6 changes: 6 additions & 0 deletions App.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import * as Sentry from '@sentry/react-native';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { Provider } from 'react-redux';
import { RecoilRoot } from 'recoil';
import dayjs from 'dayjs';
import 'dayjs/locale/fr';
import isSameOrAfter from 'dayjs/plugin/isSameOrAfter';
import { PersistGate } from 'redux-persist/integration/react';
import { InteractionManager } from 'react-native';
import { persistor, store } from './src/redux/store';
Expand All @@ -14,6 +17,9 @@ import { ToastProvider } from './src/services/toast';
import './src/styles/theme';
import { hasMigratedFromAsyncStorage, migrateFromAsyncStorage } from './src/services/storage';

dayjs.extend(isSameOrAfter);
dayjs.locale('fr');

if (!__DEV__) {
Sentry.init({ dsn: SENTRY_XXX });
}
Expand Down
16 changes: 8 additions & 8 deletions src/scenes/ConsoFollowUp/consoDuck.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,16 @@ const formatHtmlTable = (drinks, catalog) => {
<th>Quantité</th>
</tr>
${sortDrinksByDate(drinks)
.map((drink) => {
const doses = mapDrinkToDose(drink, catalog);
const name = getDisplayName(drink.drinkKey, drink.quantity, catalog);
const time = new Date(drink.timestamp).getLocaleDateAndTime('fr');
return `<tr>
.map((drink) => {
const doses = mapDrinkToDose(drink, catalog);
const name = getDisplayName(drink.drinkKey, drink.quantity, catalog);
const time = new Date(drink.timestamp).getLocaleDateAndTime('fr');
return `<tr>
<td>${time}</td>
<td>${drink.quantity} ${name} (${doses} dose${doses > 1 ? 's' : ''})</td>
</tr>`;
})
.join('')}
})
.join('')}
</tbody>
</table>
</body>
Expand Down Expand Up @@ -138,7 +138,7 @@ export const getConsolidatedCatalog = createSelector(getOwnDrinks, (ownDrinks) =
export const checkIfThereIsDrinks = createSelector(getDrinksState, (drinks) => drinks.length > 0);
export const getModalTimestamp = createSelector(getConsoState, (conso) => conso.modalTimestamp);
const getStartDate = createSelector(getConsoState, (conso) => conso.startDate);
const getDays = createSelector([getDrinksState, getStartDate], (drinks, startDate) => {
export const getDays = createSelector([getDrinksState, getStartDate], (drinks, startDate) => {
const lastDayOfDrinks = Math.max(...drinks.map(({ timestamp }) => timestamp));
const days = [];
const amplitudeOfRecords = differenceOfDays(startDate, lastDayOfDrinks);
Expand Down
8 changes: 6 additions & 2 deletions src/scenes/Gains/CategorieGain.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import H1 from '../../components/H1';
import TextStyled from '../../components/TextStyled';
import { screenWidth } from '../../styles/theme';

const CategorieGain = ({ children, icon = null, value = '?', unit = '', description }) => {
const CategorieGain = ({ children, icon = null, value = '?', unit = '', description, maximize }) => {
return (
<Categorie>
<ComponentCategorie>
Expand Down Expand Up @@ -42,9 +42,10 @@ const ComponentCategorie = styled.View`
border: 1px solid #4030a5;
border-radius: 5px;
width: ${width * 0.85}px;
height: ${width * 0.85}px;
min-height: ${width * 0.85}px;
justify-content: center;
align-items: center;
overflow: hidden;
`;

const IconCategorie = styled.View`
Expand All @@ -59,6 +60,9 @@ const UnitCategorie = styled.View`
flex-direction: row;
align-items: flex-end;
height: ${width * 0.85 * 0.5}px;
align-items: baseline;
flex-wrap: wrap;
`;

const CategorieUnit = styled(H1)``;
Expand Down
36 changes: 18 additions & 18 deletions src/scenes/Gains/Estimation.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ButtonPrimary from '../../components/ButtonPrimary';
import H1 from '../../components/H1';
import TextStyled from '../../components/TextStyled';
import { screenHeight } from '../../styles/theme';
import { estimationDrinksPerWeekState, maxDrinksPerWeekSelector } from './recoil';
import { previousDrinksPerWeekState, maxDrinksPerWeekSelector } from './recoil';
import DrinksCategory from '../../components/DrinksCategory';
import { drinksCatalog } from '../ConsoFollowUp/drinksCatalog';
import { Container, MarginBottom, ModalContent } from '../AddDrink/styles';
Expand All @@ -20,24 +20,24 @@ const Estimation = () => {
const complete = () => {
navigation.navigate('GAINS');
};
const [estimationDrinksPerWeek, setEstimationDrinksPerWeek] = useRecoilState(estimationDrinksPerWeekState);
const [previousDrinksPerWeek, setEstimationDrinksPerWeek] = useRecoilState(previousDrinksPerWeekState);

const scrollRef = useRef(null);

const setDrinkQuantityRequest = (drinkKey, quantity) => {
const oldDrink = estimationDrinksPerWeek.find((drink) => drink.drinkKey === drinkKey);
const oldDrink = previousDrinksPerWeek.find((drink) => drink.drinkKey === drinkKey);

if (oldDrink) {
setEstimationDrinksPerWeek([
...estimationDrinksPerWeek.filter((drink) => drink.drinkKey !== drinkKey),
...previousDrinksPerWeek.filter((drink) => drink.drinkKey !== drinkKey),
{
...estimationDrinksPerWeek.find((drink) => drink.drinkKey === drinkKey),
...previousDrinksPerWeek.find((drink) => drink.drinkKey === drinkKey),
quantity,
},
]);
} else {
setEstimationDrinksPerWeek([
...estimationDrinksPerWeek,
...previousDrinksPerWeek,
{
drinkKey,
quantity,
Expand All @@ -47,8 +47,6 @@ const Estimation = () => {
}
};

console.log({ estimationDrinksPerWeek });

return (
<ScreenBgStyled>
<GoBack onPress={navigation.goBack}>
Expand All @@ -60,23 +58,25 @@ const Estimation = () => {
</TopTitle>
<TopDescription>
<DescriptionText>
<TextStyled>Sur une semaine type, combien de verres consommez-vous ?</TextStyled>
<TextStyled>Sur une semaine type, actuellement, combien de verres consommez-vous ?</TextStyled>
</DescriptionText>
<DescriptionText>
<TextStyled>
<TextStyled bold>Vos réponses sont anonymes, </TextStyled>répondez avec le plus de transparence possible.
Cette estimation sera comparée à ce que vous consommerez par la suite, pour calculer vos gains en&nbsp;€
et kCal.
</TextStyled>
</DescriptionText>
<DescriptionText>
<TextStyled>
Pour rappel votre objectif est de
<Bold>
{' '}
ne pas dépasser
<TextStyled color={'#4030a5'}> {maxDrinksPerWeekGoal}&nbsp;verres par semaine.</TextStyled>
</Bold>
<TextStyled bold>Vos réponses sont anonymes, </TextStyled>répondez avec le plus de transparence possible.
</TextStyled>
</DescriptionText>
{/* <DescriptionText>
<TextStyled>
Pour rappel votre objectif est de ne pas dépasser
<TextStyled color={'#4030a5'}> {maxDrinksPerWeekGoal}&nbsp;verres par semaine.</TextStyled>
</TextStyled>
</DescriptionText> */}
</TopDescription>
</TopContainer>
<Container>
Expand All @@ -90,15 +90,15 @@ const Estimation = () => {
drinksCatalog={drinksCatalog}
category={category}
index={index}
drinks={estimationDrinksPerWeek}
drinks={previousDrinksPerWeek}
setDrinkQuantity={setDrinkQuantityRequest}
/>
))}
<MarginBottom />
</ModalContent>
</Container>
<CTAButtonContainer>
<ButtonPrimary disabled={estimationDrinksPerWeek.length <= 0} content="Je finalise" onPress={complete} />
<ButtonPrimary disabled={previousDrinksPerWeek.length <= 0} content="Je finalise" onPress={complete} />
</CTAButtonContainer>
</ScreenBgStyled>
);
Expand Down
Loading

0 comments on commit c66bb52

Please sign in to comment.