This shit aint working but juuuust incase I need the code I'll keep it here

This commit is contained in:
2025-10-16 11:25:03 +02:00
parent 8895bc9c9d
commit c6b952bfb5
10 changed files with 209 additions and 149 deletions

View File

@@ -48,26 +48,30 @@ export function useNotificationListener(onItems: (items: Item[]) => void) {
}
// Convert Expo notification → Item
function mapNotificationToItem(notification: Notifications.Notification): Item | null {
export function mapNotificationToItem(notification: Notifications.Notification): Item | null {
try {
const content = notification.request.content;
const rawCategory = content.data?.category as Category | undefined;
const category: Category = rawCategory && categoryKeys.includes(rawCategory) ? rawCategory : "home";
const data = content.data || {};
const rawCategory = data.category as string | undefined;
const category: Category = categoryKeys.includes(rawCategory as Category)
? (rawCategory as Category)
: "utility";
return {
timestamp: Date.now(), // could use backend timestamp if provided
timestamp: data.timestamp ? Number(data.timestamp) : Date.now(),
category,
title: content.title ?? "No title",
info: content.body ?? "No details",
link: (content.data?.link as string) ?? "",
info: content.body ?? "No description",
link: typeof data.link === "string" ? data.link : "#",
};
} catch (e) {
console.error("Failed to map notification to Item:", e);
} catch (err) {
console.error("Failed to map notification to Item:", err);
return null;
}
}
export { mapNotificationToItem };
//export { mapNotificationToItem };
// Save a new item into storage and update state
async function addItem(item: Item, onItems: (items: Item[]) => void) {