( habitInput, frequencyInput, dayNotification, timeNotification )
| 1 | import * as Notifications from "expo-notifications"; |
| 2 | async function createNotification( |
| 3 | habitInput, |
| 4 | frequencyInput, |
| 5 | dayNotification, |
| 6 | timeNotification |
| 7 | ) { |
| 8 | const habitHour = Number(timeNotification.slice(0, 2)); |
| 9 | const habitMinutes = Number(timeNotification.slice(3, 5)); |
| 10 | |
| 11 | let weekDay; |
| 12 | |
| 13 | if (dayNotification === "Domingo") { |
| 14 | weekDay = 1; |
| 15 | } else if (dayNotification === "Segunda") { |
| 16 | weekDay = 2; |
| 17 | } else if (dayNotification === "Terça") { |
| 18 | weekDay = 3; |
| 19 | } else if (dayNotification === "Quarta") { |
| 20 | weekDay = 4; |
| 21 | } else if (dayNotification === "Quinta") { |
| 22 | weekDay = 5; |
| 23 | } else if (dayNotification === "Sexta") { |
| 24 | weekDay = 6; |
| 25 | } else if (dayNotification === "Sábado") { |
| 26 | weekDay = 7; |
| 27 | } |
| 28 | |
| 29 | let triggerNotification; |
| 30 | if (frequencyInput === "Diário") { |
| 31 | triggerNotification = { |
| 32 | hour: habitHour, |
| 33 | minute: habitMinutes, |
| 34 | repeats: true, |
| 35 | }; |
| 36 | } else if (frequencyInput === "Semanal") { |
| 37 | triggerNotification = { |
| 38 | repeats: true, |
| 39 | weekday: weekDay, |
| 40 | hour: habitHour, |
| 41 | minute: habitMinutes, |
| 42 | }; |
| 43 | } |
| 44 | |
| 45 | await Notifications.scheduleNotificationAsync({ |
| 46 | content: { |
| 47 | title: "Lembrete de hábito:", |
| 48 | body: `${habitInput}`, |
| 49 | }, |
| 50 | identifier: `${habitInput}`, |
| 51 | trigger: triggerNotification, |
| 52 | }).then((id) => { |
| 53 | console.log(id); |
| 54 | }); |
| 55 | } |
| 56 | |
| 57 | async function deleteNotification(habitInput) { |
| 58 | await Notifications.cancelScheduledNotificationAsync(habitInput).then(() => { |
nothing calls this directly
no outgoing calls
no test coverage detected