diff --git a/src/views/Settings/DeveloperSettings.jsx b/src/views/Settings/DeveloperSettings.jsx index 7664d62..35ef183 100644 --- a/src/views/Settings/DeveloperSettings.jsx +++ b/src/views/Settings/DeveloperSettings.jsx @@ -1,6 +1,7 @@ import { Refresh, Token } from '@mui/icons-material' import { Box, Button, Card, Chip, Divider, Typography } from '@mui/joy' import { useEffect, useState } from 'react' +import { LocalNotifications } from '@capacitor/local-notifications' import { useSSEContext } from '../../hooks/useSSEContext' import { useNotification } from '../../service/NotificationProvider' import { apiClient } from '../../utils/ApiClient' @@ -28,6 +29,8 @@ const DeveloperSettings = () => { const [timeSinceLastHeartbeat, setTimeSinceLastHeartbeat] = useState(null) const [isRefreshing, setIsRefreshing] = useState(false) const [isRefreshingDirect, setIsRefreshingDirect] = useState(false) + const [scheduledNotifications, setScheduledNotifications] = useState([]) + const [isLoadingNotifications, setIsLoadingNotifications] = useState(false) const { showNotification } = useNotification() @@ -44,7 +47,32 @@ const DeveloperSettings = () => { } } + const loadScheduledNotifications = async () => { + if (isNative()) { + setIsLoadingNotifications(true) + try { + const pending = await LocalNotifications.getPending() + // Sort by schedule time (earliest first) + const sorted = pending.notifications.sort((a, b) => { + const timeA = a.schedule?.at + ? new Date(a.schedule.at).getTime() + : 0 + const timeB = b.schedule?.at + ? new Date(b.schedule.at).getTime() + : 0 + return timeA - timeB + }) + setScheduledNotifications(sorted) + } catch (error) { + console.error('Error loading scheduled notifications:', error) + } finally { + setIsLoadingNotifications(false) + } + } + } + loadTokenData() + loadScheduledNotifications() }, []) useEffect(() => { @@ -183,6 +211,47 @@ const DeveloperSettings = () => { } } + const handleRefreshNotifications = async () => { + if (!isNativePlatform) return + + setIsLoadingNotifications(true) + try { + const pending = await LocalNotifications.getPending() + // Sort by schedule time (earliest first) + const sorted = pending.notifications.sort((a, b) => { + const timeA = a.schedule?.at ? new Date(a.schedule.at).getTime() : 0 + const timeB = b.schedule?.at ? new Date(b.schedule.at).getTime() : 0 + return timeA - timeB + }) + setScheduledNotifications(sorted) + showNotification({ + type: 'success', + message: `Loaded ${sorted.length} scheduled notifications`, + }) + } catch (error) { + console.error('Error loading scheduled notifications:', error) + showNotification({ + type: 'error', + message: `Error loading notifications: ${error.message}`, + }) + } finally { + setIsLoadingNotifications(false) + } + } + + const getNotificationStatusColor = scheduleTime => { + if (!scheduleTime) return 'neutral' + + const now = new Date() + const scheduledDate = new Date(scheduleTime) + const diffMs = scheduledDate - now + + if (diffMs < 0) return 'danger' // Past due + if (diffMs < 5 * 60 * 1000) return 'warning' // Less than 5 minutes + if (diffMs < 60 * 60 * 1000) return 'primary' // Less than 1 hour + return 'success' // More than 1 hour + } + return (