Notifications + AsyncStorage
This commit is contained in:
@@ -1,12 +1,40 @@
|
||||
import { supabase } from "@/lib/supabase";
|
||||
import { Session } from "@supabase/supabase-js";
|
||||
import { Redirect, Tabs } from "expo-router";
|
||||
import * as Notifications from 'expo-notifications';
|
||||
import { Redirect, router, Tabs } from "expo-router";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
function UseNotificationObserver() {
|
||||
useEffect(() => {
|
||||
function redirect(notification: Notifications.Notification) {
|
||||
const aId = notification.request.content.data?.aId;
|
||||
|
||||
if (typeof aId === 'string') {
|
||||
router.push({pathname: "/assignment/viewDetailsAssignment", params: { aId }});
|
||||
}
|
||||
}
|
||||
|
||||
const response = Notifications.getLastNotificationResponse();
|
||||
if (response?.notification) {
|
||||
redirect(response.notification);
|
||||
}
|
||||
|
||||
const subscription = Notifications.addNotificationResponseReceivedListener(response => {
|
||||
redirect(response.notification);
|
||||
});
|
||||
|
||||
return () => {
|
||||
subscription.remove();
|
||||
};
|
||||
}, []);
|
||||
}
|
||||
|
||||
export default function TabLayout() {
|
||||
const [session, SetSession] = useState<Session | null>(null)
|
||||
const [loading, SetLoading] = useState(true);
|
||||
|
||||
UseNotificationObserver();
|
||||
|
||||
useEffect(() => {
|
||||
const loadSession = async () => {
|
||||
const { data } = await supabase.auth.getSession();
|
||||
@@ -38,18 +66,6 @@ export default function TabLayout() {
|
||||
<Tabs.Screen name="assignments" options={{title: "Assignments"}} />
|
||||
<Tabs.Screen name="subjects" options={{title: "Subjects"}} />
|
||||
<Tabs.Screen name="timer" options={{title: "Timer"}} />
|
||||
|
||||
<Tabs.Screen name="subject/createSubject" options={{ href: null }} />
|
||||
<Tabs.Screen name="subject/editSubject" options={{ href: null }} />
|
||||
<Tabs.Screen name="subject/viewDetailsSubject" options={{ href: null }} />
|
||||
|
||||
<Tabs.Screen name="assignment/createAssignment" options={{ href: null }} />
|
||||
<Tabs.Screen name="assignment/editAssignment" options={{ href: null }} />
|
||||
<Tabs.Screen name="assignment/viewDetailsAssignment" options={{ href: null }} />
|
||||
|
||||
<Tabs.Screen name="task/createTask" options={{ href: null }} />
|
||||
<Tabs.Screen name="task/editTask" options={{ href: null }} />
|
||||
<Tabs.Screen name="task/viewDetailsTask" options={{ href: null }} />
|
||||
</Tabs>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user