-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
92 lines (81 loc) · 2.56 KB
/
App.js
File metadata and controls
92 lines (81 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import React, { useEffect, useState } from "react";
import { StatusBar } from "expo-status-bar";
import { StyleSheet, Text, View } from "react-native";
import * as Notifications from "expo-notifications";
import AppProvider, { AppContext } from "./context/AppProvider";
import { APP_PAGES, COLORS } from "./context/Settings";
import HomeScreen from "./components/Screens/HomeScreen";
import CreateTaskScreen from "./components/Screens/CreateTaskScreen";
import SpecTaskScreen from "./components/Screens/SpecTaskScreen";
// Function to request permissions and schedule notifications
const handleNotifications = async () => {
// Request notification permissions
const { status } = await Notifications.requestPermissionsAsync();
if (status !== "granted") {
console.log("Permission for notifications not granted.");
return;
}
// Example: Fetch tasks due today (you'll need to implement this part)
const tasksDueToday = await fetchTasksDueToday();
// Schedule notifications for tasks due today
tasksDueToday.forEach(async (task) => {
await Notifications.scheduleNotificationAsync({
content: {
title: "Task Due Today!",
body: `You have a task due today:`,
sound: true, // Optional
priority: Notifications.AndroidNotificationPriority.HIGH, // Optional for Android
},
trigger: {
// Schedule for today at 12 PM
hour: 9,
minute: 0,
repeats: true,
},
});
});
};
// Mock function to fetch tasks due today
const fetchTasksDueToday = async () => {
// Replace with your actual logic to fetch tasks from your database or state
return [
{ title: "Complete React Native project" },
{ title: "Meeting with team" },
];
};
function App() {
useEffect(() => {
handleNotifications();
}, []);
return (
<AppProvider>
<NavWrapper />
</AppProvider>
);
}
const NavWrapper = () => {
const { navPage, setNavPage } = React.useContext(AppContext);
React.useEffect(() => {
console.log("App Nav: ", navPage);
}, [navPage]);
return (
<View style={styles.container}>
<StatusBar
animated={true}
backgroundColor={COLORS.MAIN_BACKGROUND}
barStyle={"light-content"}
style="light"
/>
{navPage === APP_PAGES.APP.HOME && <HomeScreen />}
{navPage === APP_PAGES.APP.CREATE && <CreateTaskScreen />}
{navPage === APP_PAGES.APP.SPECTASK && <SpecTaskScreen />}
</View>
);
};
export default App;
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: COLORS.MAIN_BACKGROUND,
},
});