Moved categories to its own configuration file
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import AsyncStorage from "@react-native-async-storage/async-storage";
|
||||
import * as Notifications from "expo-notifications";
|
||||
import { useEffect } from "react";
|
||||
import { Category, categoryKeys } from "types/Category";
|
||||
import { Item } from "types/Item";
|
||||
|
||||
const STORAGE_KEY = "notifications-data";
|
||||
@@ -50,10 +51,12 @@ export function useNotificationListener(onItems: (items: Item[]) => void) {
|
||||
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";
|
||||
|
||||
return {
|
||||
timestamp: Date.now(), // could use backend timestamp if provided
|
||||
category: (content.data?.category as Item["category"]) ?? "home",
|
||||
category,
|
||||
title: content.title ?? "No title",
|
||||
info: content.body ?? "No details",
|
||||
link: (content.data?.link as string) ?? "",
|
||||
@@ -64,6 +67,8 @@ function mapNotificationToItem(notification: Notifications.Notification): Item |
|
||||
}
|
||||
}
|
||||
|
||||
export { mapNotificationToItem };
|
||||
|
||||
// Save a new item into storage and update state
|
||||
async function addItem(item: Item, onItems: (items: Item[]) => void) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user