Browse Source
- Add static daily reminders to README.md core features and API reference - Create detailed usage guide in USAGE.md with examples and best practices - Add version 2.1.0 changelog entry documenting new reminder functionality - Create examples/static-daily-reminders.ts with complete usage examples - Update test-apps README to include reminder testing capabilities The static daily reminder feature provides simple daily notifications without network content dependency, supporting cross-platform scheduling with rich customization options.master
21 changed files with 2120 additions and 0 deletions
@ -0,0 +1,342 @@ |
|||
/** |
|||
* Static Daily Reminders Examples |
|||
* |
|||
* Examples demonstrating the static daily reminder functionality |
|||
* that works without network content or content caching. |
|||
* |
|||
* @author Matthew Raymer |
|||
* @version 1.0.0 |
|||
*/ |
|||
|
|||
import { DailyNotification } from '@timesafari/daily-notification-plugin'; |
|||
|
|||
/** |
|||
* Basic Daily Reminder |
|||
* |
|||
* Schedule a simple daily reminder with default settings |
|||
*/ |
|||
export async function scheduleBasicReminder() { |
|||
try { |
|||
await DailyNotification.scheduleDailyReminder({ |
|||
id: 'morning_checkin', |
|||
title: 'Good Morning!', |
|||
body: 'Time to check your TimeSafari community updates', |
|||
time: '09:00' |
|||
}); |
|||
|
|||
console.log('✅ Basic reminder scheduled for 9:00 AM daily'); |
|||
} catch (error) { |
|||
console.error('❌ Failed to schedule basic reminder:', error); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Customized Daily Reminder |
|||
* |
|||
* Schedule a reminder with custom sound, vibration, and priority |
|||
*/ |
|||
export async function scheduleCustomizedReminder() { |
|||
try { |
|||
await DailyNotification.scheduleDailyReminder({ |
|||
id: 'evening_reflection', |
|||
title: 'Evening Reflection', |
|||
body: 'Take a moment to reflect on your day and plan for tomorrow', |
|||
time: '20:00', |
|||
sound: true, |
|||
vibration: true, |
|||
priority: 'high', |
|||
repeatDaily: true |
|||
}); |
|||
|
|||
console.log('✅ Customized reminder scheduled for 8:00 PM daily'); |
|||
} catch (error) { |
|||
console.error('❌ Failed to schedule customized reminder:', error); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Multiple Daily Reminders |
|||
* |
|||
* Schedule multiple reminders throughout the day |
|||
*/ |
|||
export async function scheduleMultipleReminders() { |
|||
const reminders = [ |
|||
{ |
|||
id: 'morning_motivation', |
|||
title: 'Morning Motivation', |
|||
body: 'Start your day with positive energy!', |
|||
time: '07:00', |
|||
priority: 'high' as const |
|||
}, |
|||
{ |
|||
id: 'lunch_break', |
|||
title: 'Lunch Break', |
|||
body: 'Time for a well-deserved break', |
|||
time: '12:30', |
|||
priority: 'normal' as const |
|||
}, |
|||
{ |
|||
id: 'evening_gratitude', |
|||
title: 'Evening Gratitude', |
|||
body: 'What are you grateful for today?', |
|||
time: '19:00', |
|||
priority: 'normal' as const |
|||
} |
|||
]; |
|||
|
|||
try { |
|||
for (const reminder of reminders) { |
|||
await DailyNotification.scheduleDailyReminder(reminder); |
|||
console.log(`✅ Scheduled reminder: ${reminder.id} at ${reminder.time}`); |
|||
} |
|||
|
|||
console.log('✅ All reminders scheduled successfully'); |
|||
} catch (error) { |
|||
console.error('❌ Failed to schedule multiple reminders:', error); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Get All Scheduled Reminders |
|||
* |
|||
* Retrieve and display all currently scheduled reminders |
|||
*/ |
|||
export async function getAllScheduledReminders() { |
|||
try { |
|||
const result = await DailyNotification.getScheduledReminders(); |
|||
|
|||
if (result.reminders && result.reminders.length > 0) { |
|||
console.log(`📋 Found ${result.reminders.length} scheduled reminders:`); |
|||
|
|||
result.reminders.forEach((reminder, index) => { |
|||
console.log(`${index + 1}. ${reminder.title} (${reminder.id})`); |
|||
console.log(` Time: ${reminder.time}`); |
|||
console.log(` Priority: ${reminder.priority}`); |
|||
console.log(` Repeat Daily: ${reminder.repeatDaily}`); |
|||
console.log(` Scheduled: ${reminder.isScheduled ? 'Yes' : 'No'}`); |
|||
console.log(''); |
|||
}); |
|||
} else { |
|||
console.log('📋 No scheduled reminders found'); |
|||
} |
|||
} catch (error) { |
|||
console.error('❌ Failed to get scheduled reminders:', error); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Update Existing Reminder |
|||
* |
|||
* Update an existing reminder with new settings |
|||
*/ |
|||
export async function updateExistingReminder() { |
|||
try { |
|||
// Update the morning check-in reminder
|
|||
await DailyNotification.updateDailyReminder('morning_checkin', { |
|||
title: 'Updated Morning Check-in', |
|||
body: 'Time to check your TimeSafari community updates and plan your day', |
|||
time: '08:30', |
|||
priority: 'high' |
|||
}); |
|||
|
|||
console.log('✅ Morning check-in reminder updated to 8:30 AM with high priority'); |
|||
} catch (error) { |
|||
console.error('❌ Failed to update reminder:', error); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Cancel Specific Reminder |
|||
* |
|||
* Cancel a specific reminder by ID |
|||
*/ |
|||
export async function cancelSpecificReminder() { |
|||
try { |
|||
await DailyNotification.cancelDailyReminder('evening_reflection'); |
|||
console.log('✅ Evening reflection reminder cancelled'); |
|||
} catch (error) { |
|||
console.error('❌ Failed to cancel reminder:', error); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Cancel All Reminders |
|||
* |
|||
* Cancel all scheduled reminders |
|||
*/ |
|||
export async function cancelAllReminders() { |
|||
try { |
|||
const result = await DailyNotification.getScheduledReminders(); |
|||
|
|||
if (result.reminders && result.reminders.length > 0) { |
|||
for (const reminder of result.reminders) { |
|||
await DailyNotification.cancelDailyReminder(reminder.id); |
|||
console.log(`✅ Cancelled reminder: ${reminder.id}`); |
|||
} |
|||
|
|||
console.log('✅ All reminders cancelled successfully'); |
|||
} else { |
|||
console.log('📋 No reminders to cancel'); |
|||
} |
|||
} catch (error) { |
|||
console.error('❌ Failed to cancel all reminders:', error); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Reminder Management Workflow |
|||
* |
|||
* Complete workflow demonstrating reminder management |
|||
*/ |
|||
export async function reminderManagementWorkflow() { |
|||
console.log('🚀 Starting reminder management workflow...\n'); |
|||
|
|||
try { |
|||
// 1. Schedule initial reminders
|
|||
console.log('1. Scheduling initial reminders...'); |
|||
await scheduleMultipleReminders(); |
|||
console.log(''); |
|||
|
|||
// 2. Get all reminders
|
|||
console.log('2. Getting all scheduled reminders...'); |
|||
await getAllScheduledReminders(); |
|||
console.log(''); |
|||
|
|||
// 3. Update a reminder
|
|||
console.log('3. Updating morning check-in reminder...'); |
|||
await updateExistingReminder(); |
|||
console.log(''); |
|||
|
|||
// 4. Get updated reminders
|
|||
console.log('4. Getting updated reminders...'); |
|||
await getAllScheduledReminders(); |
|||
console.log(''); |
|||
|
|||
// 5. Cancel a specific reminder
|
|||
console.log('5. Cancelling evening reflection reminder...'); |
|||
await cancelSpecificReminder(); |
|||
console.log(''); |
|||
|
|||
// 6. Final reminder list
|
|||
console.log('6. Final reminder list...'); |
|||
await getAllScheduledReminders(); |
|||
|
|||
console.log('🎉 Reminder management workflow completed successfully!'); |
|||
} catch (error) { |
|||
console.error('❌ Reminder management workflow failed:', error); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Time Format Validation Examples |
|||
* |
|||
* Examples of valid and invalid time formats |
|||
*/ |
|||
export function timeFormatExamples() { |
|||
console.log('⏰ Time Format Examples:'); |
|||
console.log(''); |
|||
|
|||
const validTimes = [ |
|||
'00:00', // Midnight
|
|||
'06:30', // 6:30 AM
|
|||
'12:00', // Noon
|
|||
'18:45', // 6:45 PM
|
|||
'23:59' // 11:59 PM
|
|||
]; |
|||
|
|||
const invalidTimes = [ |
|||
'24:00', // Invalid hour
|
|||
'12:60', // Invalid minute
|
|||
'9:00', // Missing leading zero
|
|||
'12:0', // Missing trailing zero
|
|||
'12', // Missing minutes
|
|||
'abc' // Non-numeric
|
|||
]; |
|||
|
|||
console.log('✅ Valid time formats:'); |
|||
validTimes.forEach(time => { |
|||
console.log(` "${time}" - Valid`); |
|||
}); |
|||
|
|||
console.log(''); |
|||
console.log('❌ Invalid time formats:'); |
|||
invalidTimes.forEach(time => { |
|||
console.log(` "${time}" - Invalid`); |
|||
}); |
|||
|
|||
console.log(''); |
|||
console.log('📝 Time format rules:'); |
|||
console.log(' - Use HH:mm format (24-hour)'); |
|||
console.log(' - Hours: 00-23'); |
|||
console.log(' - Minutes: 00-59'); |
|||
console.log(' - Always use leading zeros'); |
|||
} |
|||
|
|||
/** |
|||
* Platform-Specific Considerations |
|||
* |
|||
* Important notes for different platforms |
|||
*/ |
|||
export function platformConsiderations() { |
|||
console.log('📱 Platform-Specific Considerations:'); |
|||
console.log(''); |
|||
|
|||
console.log('🤖 Android:'); |
|||
console.log(' - Uses AlarmManager for precise scheduling'); |
|||
console.log(' - Requires POST_NOTIFICATIONS permission'); |
|||
console.log(' - May be affected by battery optimization'); |
|||
console.log(' - Survives device reboots'); |
|||
console.log(''); |
|||
|
|||
console.log('🍎 iOS:'); |
|||
console.log(' - Uses UNUserNotificationCenter'); |
|||
console.log(' - Requires notification permissions'); |
|||
console.log(' - Limited to 64 scheduled notifications'); |
|||
console.log(' - May be affected by Background App Refresh'); |
|||
console.log(''); |
|||
|
|||
console.log('🌐 Web:'); |
|||
console.log(' - Uses setTimeout for scheduling'); |
|||
console.log(' - Requires notification permissions'); |
|||
console.log(' - Limited by browser tab lifecycle'); |
|||
console.log(' - May not persist across browser restarts'); |
|||
console.log(''); |
|||
|
|||
console.log('💡 Best Practices:'); |
|||
console.log(' - Always request notification permissions first'); |
|||
console.log(' - Handle permission denials gracefully'); |
|||
console.log(' - Test on actual devices, not just simulators'); |
|||
console.log(' - Consider platform limitations in your app design'); |
|||
} |
|||
|
|||
// Export all functions for easy importing
|
|||
export const StaticReminderExamples = { |
|||
scheduleBasicReminder, |
|||
scheduleCustomizedReminder, |
|||
scheduleMultipleReminders, |
|||
getAllScheduledReminders, |
|||
updateExistingReminder, |
|||
cancelSpecificReminder, |
|||
cancelAllReminders, |
|||
reminderManagementWorkflow, |
|||
timeFormatExamples, |
|||
platformConsiderations |
|||
}; |
|||
|
|||
// Example usage
|
|||
if (require.main === module) { |
|||
console.log('📚 Static Daily Reminders Examples'); |
|||
console.log('=====================================\n'); |
|||
|
|||
// Show time format examples
|
|||
timeFormatExamples(); |
|||
console.log(''); |
|||
|
|||
// Show platform considerations
|
|||
platformConsiderations(); |
|||
console.log(''); |
|||
|
|||
console.log('💡 To run the examples, import and call the functions:'); |
|||
console.log(' import { StaticReminderExamples } from "./static-daily-reminders";'); |
|||
console.log(' await StaticReminderExamples.reminderManagementWorkflow();'); |
|||
} |
Loading…
Reference in new issue