MCPcopy Create free account
hub / github.com/OneBitCodeBlog/onebitlife / HabitPage

Function HabitPage

src/Pages/HabitPage/index.jsx:31–235  ·  view source on GitHub ↗
({ route })

Source from the content-addressed store, hash-verified

29});
30
31export default function HabitPage({ route }) {
32 const navigation = useNavigation();
33 const [habitInput, setHabitInput] = useState();
34 const [frequencyInput, setFrequencyInput] = useState();
35 const [notificationToggle, setNotificationToggle] = useState();
36 const [dayNotification, setDayNotification] = useState();
37 const [timeNotification, setTimeNotification] = useState();
38
39 const { create, habit } = route.params;
40
41 const habitCreated = new Date();
42 const formatDate = `${habitCreated.getFullYear()}-${habitCreated.getMonth()}-${habitCreated.getDate()}`;
43
44 const [notification, setNotification] = useState(false);
45 const notificationListener = useRef();
46 const responseListener = useRef();
47
48 function handleCreateHabit() {
49 if (habitInput === undefined || frequencyInput === undefined) {
50 Alert.alert(
51 "Você precisa selecionar um hábito e frequência para continuar"
52 );
53 } else if (
54 notificationToggle === true &&
55 frequencyInput === "Diário" &&
56 timeNotification === undefined
57 ) {
58 Alert.alert("Você precisa dizer o horário da notificação!");
59 } else if (
60 notificationToggle === true &&
61 frequencyInput === "Diário" &&
62 dayNotification === undefined &&
63 timeNotification === undefined
64 ) {
65 Alert.alert(
66 "Você precisa dizer a frequência e o horário da notificação!"
67 );
68 } else {
69 if (notificationToggle) {
70 NotificationService.createNotification(
71 habitInput,
72 frequencyInput,
73 dayNotification,
74 timeNotification
75 );
76 }
77
78 HabitsService.createHabit({
79 habitArea: habit?.habitArea,
80 habitName: habitInput,
81 habitFrequency: frequencyInput,
82 habitHasNotification: notificationToggle,
83 habitNotificationFrequency: dayNotification,
84 habitNotificationTime: timeNotification,
85 lastCheck: formatDate,
86 daysWithoutChecks: 0,
87 habitIsChecked: 0,
88 progressBar: 1,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected