From e4fcb1894ce7e3ffbf9506b708d1a6946271e32a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20LUDWIG?= Date: Fri, 5 Apr 2024 00:08:40 +0200 Subject: [PATCH] feat: habit create use case --- app/_layout.tsx | 5 +- app/application/habits/index.tsx | 3 +- domain/entities/Goal.ts | 12 +- domain/entities/Habit.ts | 6 +- domain/entities/HabitProgress.ts | 6 +- domain/entities/HabitsTracker.ts | 12 +- domain/repositories/HabitCreate.ts | 9 + domain/use-cases/HabitCreate.ts | 23 + infrastructure/instances.ts | 9 + .../supabase/repositories/HabitCreate.ts | 42 ++ infrastructure/supabase/seed.sql | 3 + infrastructure/supabase/supabase.ts | 8 +- package-lock.json | 596 ++++++++---------- package.json | 26 +- presentation/presenters/HabitsTracker.ts | 61 +- .../HabitCreateForm/HabitCreateForm.tsx | 329 +++++----- .../HabitsHistory/HabitsHistory.tsx | 4 +- 17 files changed, 648 insertions(+), 506 deletions(-) create mode 100644 domain/repositories/HabitCreate.ts create mode 100644 domain/use-cases/HabitCreate.ts create mode 100644 infrastructure/supabase/repositories/HabitCreate.ts diff --git a/app/_layout.tsx b/app/_layout.tsx index 2abb980..5130169 100644 --- a/app/_layout.tsx +++ b/app/_layout.tsx @@ -6,6 +6,7 @@ import { } from "react-native-paper" import { StatusBar } from "expo-status-bar" import { useEffect } from "react" +import { GestureHandlerRootView } from "react-native-gesture-handler" import { HabitsTrackerProvider } from "@/presentation/react/contexts/HabitsTracker" import { @@ -61,7 +62,9 @@ const RootLayout: React.FC = () => { }, }} > - + + + diff --git a/app/application/habits/index.tsx b/app/application/habits/index.tsx index daeb46d..1a8f487 100644 --- a/app/application/habits/index.tsx +++ b/app/application/habits/index.tsx @@ -30,7 +30,8 @@ const HabitsPage: React.FC = () => { ) : retrieveHabitsTracker.state === "error" ? ( <> - Error: There was an issue while retrieving habits, please try again. + Error: There was an issue while retrieving habits, please try again + later. + - { - return ( - - ) - }} - name="icon" - /> - - { - return ( - <> - Habit frequency - { - return { - label: capitalize(frequency), - value: frequency, - icon: frequenciesIcons[frequency], - } - })} - /> - - ) - }} - name="goal.frequency" - /> - - { - return ( - <> - Habit type - { - return { - label: habitTypesTranslations[type].label, - value: type, - icon: habitTypesTranslations[type].icon, - } - })} - /> - - ) - }} - name="goal.target.type" - /> - - + ✅ Habit created successfully! + ) } -const styles = { - input: { - margin: 8, +const styles = StyleSheet.create({ + spacing: { + marginVertical: 16, }, -} +}) diff --git a/presentation/react/components/HabitsHistory/HabitsHistory.tsx b/presentation/react/components/HabitsHistory/HabitsHistory.tsx index 952ff1d..b9e7ac4 100644 --- a/presentation/react/components/HabitsHistory/HabitsHistory.tsx +++ b/presentation/react/components/HabitsHistory/HabitsHistory.tsx @@ -1,7 +1,7 @@ +import { useRouter } from "expo-router" +import { useMemo, useState } from "react" import { FlatList, View } from "react-native" import { Button, List, Text } from "react-native-paper" -import { useMemo, useState } from "react" -import { useRouter } from "expo-router" import type { GoalFrequency } from "@/domain/entities/Goal" import { GOAL_FREQUENCIES } from "@/domain/entities/Goal"