@umituz/react-native-notifications 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +93 -0
- package/lib/index.d.ts +13 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +15 -0
- package/lib/index.js.map +1 -0
- package/lib/infrastructure/config/notificationsConfig.d.ts +20 -0
- package/lib/infrastructure/config/notificationsConfig.d.ts.map +1 -0
- package/lib/infrastructure/config/notificationsConfig.js +81 -0
- package/lib/infrastructure/config/notificationsConfig.js.map +1 -0
- package/lib/infrastructure/hooks/actions/useNotificationActions.d.ts +17 -0
- package/lib/infrastructure/hooks/actions/useNotificationActions.d.ts.map +1 -0
- package/lib/infrastructure/hooks/actions/useNotificationActions.js +141 -0
- package/lib/infrastructure/hooks/actions/useNotificationActions.js.map +1 -0
- package/lib/infrastructure/hooks/state/useNotificationsState.d.ts +12 -0
- package/lib/infrastructure/hooks/state/useNotificationsState.d.ts.map +1 -0
- package/lib/infrastructure/hooks/state/useNotificationsState.js +30 -0
- package/lib/infrastructure/hooks/state/useNotificationsState.js.map +1 -0
- package/lib/infrastructure/hooks/types.d.ts +87 -0
- package/lib/infrastructure/hooks/types.d.ts.map +1 -0
- package/lib/infrastructure/hooks/types.js +8 -0
- package/lib/infrastructure/hooks/types.js.map +1 -0
- package/lib/infrastructure/hooks/useNotificationSettings.d.ts +10 -0
- package/lib/infrastructure/hooks/useNotificationSettings.d.ts.map +1 -0
- package/lib/infrastructure/hooks/useNotificationSettings.js +43 -0
- package/lib/infrastructure/hooks/useNotificationSettings.js.map +1 -0
- package/lib/infrastructure/hooks/useNotifications.d.ts +23 -0
- package/lib/infrastructure/hooks/useNotifications.d.ts.map +1 -0
- package/lib/infrastructure/hooks/useNotifications.js +51 -0
- package/lib/infrastructure/hooks/useNotifications.js.map +1 -0
- package/lib/infrastructure/hooks/utils/useNotificationRefresh.d.ts +13 -0
- package/lib/infrastructure/hooks/utils/useNotificationRefresh.d.ts.map +1 -0
- package/lib/infrastructure/hooks/utils/useNotificationRefresh.js +82 -0
- package/lib/infrastructure/hooks/utils/useNotificationRefresh.js.map +1 -0
- package/lib/infrastructure/services/NotificationManager.d.ts +138 -0
- package/lib/infrastructure/services/NotificationManager.d.ts.map +1 -0
- package/lib/infrastructure/services/NotificationManager.js +284 -0
- package/lib/infrastructure/services/NotificationManager.js.map +1 -0
- package/lib/infrastructure/services/NotificationService.d.ts +30 -0
- package/lib/infrastructure/services/NotificationService.d.ts.map +1 -0
- package/lib/infrastructure/services/NotificationService.js +41 -0
- package/lib/infrastructure/services/NotificationService.js.map +1 -0
- package/lib/infrastructure/services/channels/ChannelManager.d.ts +18 -0
- package/lib/infrastructure/services/channels/ChannelManager.d.ts.map +1 -0
- package/lib/infrastructure/services/channels/ChannelManager.js +87 -0
- package/lib/infrastructure/services/channels/ChannelManager.js.map +1 -0
- package/lib/infrastructure/services/delivery/NotificationDelivery.d.ts +16 -0
- package/lib/infrastructure/services/delivery/NotificationDelivery.d.ts.map +1 -0
- package/lib/infrastructure/services/delivery/NotificationDelivery.js +57 -0
- package/lib/infrastructure/services/delivery/NotificationDelivery.js.map +1 -0
- package/lib/infrastructure/services/preferences/PreferencesManager.d.ts +18 -0
- package/lib/infrastructure/services/preferences/PreferencesManager.d.ts.map +1 -0
- package/lib/infrastructure/services/preferences/PreferencesManager.js +65 -0
- package/lib/infrastructure/services/preferences/PreferencesManager.js.map +1 -0
- package/lib/infrastructure/services/types.d.ts +89 -0
- package/lib/infrastructure/services/types.d.ts.map +1 -0
- package/lib/infrastructure/services/types.js +7 -0
- package/lib/infrastructure/services/types.js.map +1 -0
- package/lib/infrastructure/storage/NotificationsStore.d.ts +23 -0
- package/lib/infrastructure/storage/NotificationsStore.d.ts.map +1 -0
- package/lib/infrastructure/storage/NotificationsStore.js +25 -0
- package/lib/infrastructure/storage/NotificationsStore.js.map +1 -0
- package/package.json +62 -0
- package/src/index.ts +34 -0
- package/src/infrastructure/config/notificationsConfig.ts +98 -0
- package/src/infrastructure/hooks/actions/useNotificationActions.ts +233 -0
- package/src/infrastructure/hooks/state/useNotificationsState.ts +46 -0
- package/src/infrastructure/hooks/types.ts +83 -0
- package/src/infrastructure/hooks/useNotificationSettings.ts +45 -0
- package/src/infrastructure/hooks/useNotifications.ts +70 -0
- package/src/infrastructure/hooks/utils/useNotificationRefresh.ts +107 -0
- package/src/infrastructure/services/NotificationManager.ts +326 -0
- package/src/infrastructure/services/NotificationService.ts +50 -0
- package/src/infrastructure/services/channels/ChannelManager.ts +111 -0
- package/src/infrastructure/services/delivery/NotificationDelivery.ts +65 -0
- package/src/infrastructure/services/preferences/PreferencesManager.ts +77 -0
- package/src/infrastructure/services/types.ts +81 -0
- package/src/infrastructure/storage/NotificationsStore.ts +39 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Ümit UZ
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# @umituz/react-native-notifications
|
|
2
|
+
|
|
3
|
+
Offline-first local notifications system for React Native apps using expo-notifications.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @umituz/react-native-notifications
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Peer Dependencies
|
|
12
|
+
|
|
13
|
+
- `react` >= 18.2.0
|
|
14
|
+
- `react-native` >= 0.74.0
|
|
15
|
+
- `expo-notifications` ~0.28.0
|
|
16
|
+
- `expo-device` ~6.0.2
|
|
17
|
+
- `@react-native-async-storage/async-storage` >= 1.21.0
|
|
18
|
+
- `zustand` >= 5.0.2
|
|
19
|
+
|
|
20
|
+
## Features
|
|
21
|
+
|
|
22
|
+
- ✅ Offline-first local notifications
|
|
23
|
+
- ✅ Schedule notifications for specific dates/times
|
|
24
|
+
- ✅ Repeating notifications (daily, weekly, monthly)
|
|
25
|
+
- ✅ Android notification channels
|
|
26
|
+
- ✅ Permission handling
|
|
27
|
+
- ✅ Cancel individual or all notifications
|
|
28
|
+
- ✅ Works completely offline (no backend required)
|
|
29
|
+
- ✅ Zustand state management
|
|
30
|
+
|
|
31
|
+
## Usage
|
|
32
|
+
|
|
33
|
+
### Basic Usage
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { NotificationService, useNotificationSettings } from '@umituz/react-native-notifications';
|
|
37
|
+
|
|
38
|
+
// Request permissions
|
|
39
|
+
const hasPermissions = await NotificationService.getInstance().requestPermissions();
|
|
40
|
+
|
|
41
|
+
// Schedule a notification
|
|
42
|
+
const notificationId = await notificationService.notifications.scheduleNotification({
|
|
43
|
+
title: 'Reminder',
|
|
44
|
+
body: 'Don\'t forget to check your tasks!',
|
|
45
|
+
trigger: { type: 'date', date: new Date('2025-01-15T09:00:00') }
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// Daily reminder
|
|
49
|
+
const dailyId = await notificationService.notifications.scheduleNotification({
|
|
50
|
+
title: 'Daily Workout',
|
|
51
|
+
body: 'Time for your morning workout!',
|
|
52
|
+
trigger: { type: 'daily', hour: 7, minute: 0 }
|
|
53
|
+
});
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Using Hooks
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
import { useNotificationSettings, useNotificationsStore } from '@umituz/react-native-notifications';
|
|
60
|
+
|
|
61
|
+
const MyComponent = () => {
|
|
62
|
+
const { notificationsEnabled, setNotificationsEnabled } = useNotificationSettings();
|
|
63
|
+
const { hasPermissions } = useNotificationsStore();
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<Switch
|
|
67
|
+
value={notificationsEnabled}
|
|
68
|
+
onValueChange={setNotificationsEnabled}
|
|
69
|
+
/>
|
|
70
|
+
);
|
|
71
|
+
};
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## API
|
|
75
|
+
|
|
76
|
+
### NotificationService
|
|
77
|
+
|
|
78
|
+
- `requestPermissions()`: Request notification permissions
|
|
79
|
+
- `hasPermissions()`: Check if permissions are granted
|
|
80
|
+
- `notifications.scheduleNotification(options)`: Schedule a notification
|
|
81
|
+
- `notifications.cancelNotification(id)`: Cancel a notification
|
|
82
|
+
- `notifications.cancelAllNotifications()`: Cancel all notifications
|
|
83
|
+
- `notifications.getScheduledNotifications()`: Get all scheduled notifications
|
|
84
|
+
|
|
85
|
+
### Hooks
|
|
86
|
+
|
|
87
|
+
- `useNotificationSettings()`: Manage notification settings
|
|
88
|
+
- `useNotificationsStore()`: Access notification state
|
|
89
|
+
|
|
90
|
+
## License
|
|
91
|
+
|
|
92
|
+
MIT
|
|
93
|
+
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Notifications Domain - Public API
|
|
3
|
+
* Offline-first local notifications using expo-notifications
|
|
4
|
+
* NO backend, NO user IDs, NO push notifications
|
|
5
|
+
*/
|
|
6
|
+
export type { NotificationTrigger, ScheduleNotificationOptions, ScheduledNotification, } from './infrastructure/services/types';
|
|
7
|
+
export { notificationsConfig } from './infrastructure/config/notificationsConfig';
|
|
8
|
+
export type { NotificationSetting, NotificationSection, NotificationsConfig, } from './infrastructure/config/notificationsConfig';
|
|
9
|
+
export { useNotificationsStore, useNotifications } from './infrastructure/storage/NotificationsStore';
|
|
10
|
+
export { NotificationService, notificationService } from './infrastructure/services/NotificationService';
|
|
11
|
+
export { NotificationManager } from './infrastructure/services/NotificationManager';
|
|
12
|
+
export { useNotificationSettings } from './infrastructure/hooks/useNotificationSettings';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAOH,YAAY,EACV,mBAAmB,EACnB,2BAA2B,EAC3B,qBAAqB,GACtB,MAAM,iCAAiC,CAAC;AAGzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,6CAA6C,CAAC;AAClF,YAAY,EACV,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,6CAA6C,CAAC;AAGrD,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,6CAA6C,CAAC;AAGtG,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,+CAA+C,CAAC;AACzG,OAAO,EAAE,mBAAmB,EAAE,MAAM,+CAA+C,CAAC;AAGpF,OAAO,EAAE,uBAAuB,EAAE,MAAM,gDAAgD,CAAC"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Notifications Domain - Public API
|
|
3
|
+
* Offline-first local notifications using expo-notifications
|
|
4
|
+
* NO backend, NO user IDs, NO push notifications
|
|
5
|
+
*/
|
|
6
|
+
// Configuration
|
|
7
|
+
export { notificationsConfig } from './infrastructure/config/notificationsConfig';
|
|
8
|
+
// State Store (Zustand)
|
|
9
|
+
export { useNotificationsStore, useNotifications } from './infrastructure/storage/NotificationsStore';
|
|
10
|
+
// Services
|
|
11
|
+
export { NotificationService, notificationService } from './infrastructure/services/NotificationService';
|
|
12
|
+
export { NotificationManager } from './infrastructure/services/NotificationManager';
|
|
13
|
+
// Hooks
|
|
14
|
+
export { useNotificationSettings } from './infrastructure/hooks/useNotificationSettings';
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAaH,gBAAgB;AAChB,OAAO,EAAE,mBAAmB,EAAE,MAAM,6CAA6C,CAAC;AAOlF,wBAAwB;AACxB,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,6CAA6C,CAAC;AAEtG,WAAW;AACX,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,+CAA+C,CAAC;AACzG,OAAO,EAAE,mBAAmB,EAAE,MAAM,+CAA+C,CAAC;AAEpF,QAAQ;AACR,OAAO,EAAE,uBAAuB,EAAE,MAAM,gDAAgD,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Notifications Configuration
|
|
3
|
+
* Defines notification settings structure
|
|
4
|
+
*/
|
|
5
|
+
export interface NotificationSetting {
|
|
6
|
+
id: string;
|
|
7
|
+
titleKey: string;
|
|
8
|
+
descKey: string;
|
|
9
|
+
icon: string;
|
|
10
|
+
}
|
|
11
|
+
export interface NotificationSection {
|
|
12
|
+
id: string;
|
|
13
|
+
titleKey: string;
|
|
14
|
+
settings: NotificationSetting[];
|
|
15
|
+
}
|
|
16
|
+
export interface NotificationsConfig {
|
|
17
|
+
sections: NotificationSection[];
|
|
18
|
+
}
|
|
19
|
+
export declare const notificationsConfig: NotificationsConfig;
|
|
20
|
+
//# sourceMappingURL=notificationsConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notificationsConfig.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/config/notificationsConfig.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,mBAAmB,EAAE,CAAC;CACjC;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,mBAAmB,EAAE,CAAC;CACjC;AAED,eAAO,MAAM,mBAAmB,EAAE,mBA2EjC,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Notifications Configuration
|
|
3
|
+
* Defines notification settings structure
|
|
4
|
+
*/
|
|
5
|
+
export const notificationsConfig = {
|
|
6
|
+
sections: [
|
|
7
|
+
{
|
|
8
|
+
id: 'channels',
|
|
9
|
+
titleKey: 'notifications.channels',
|
|
10
|
+
settings: [
|
|
11
|
+
{
|
|
12
|
+
id: 'pushNotifications',
|
|
13
|
+
titleKey: 'notifications.push',
|
|
14
|
+
descKey: 'notifications.pushDesc',
|
|
15
|
+
icon: 'notifications',
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
id: 'emailNotifications',
|
|
19
|
+
titleKey: 'notifications.email',
|
|
20
|
+
descKey: 'notifications.emailDesc',
|
|
21
|
+
icon: 'email',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
id: 'smsNotifications',
|
|
25
|
+
titleKey: 'notifications.sms',
|
|
26
|
+
descKey: 'notifications.smsDesc',
|
|
27
|
+
icon: 'message',
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
id: 'content',
|
|
33
|
+
titleKey: 'notifications.content',
|
|
34
|
+
settings: [
|
|
35
|
+
{
|
|
36
|
+
id: 'appUpdates',
|
|
37
|
+
titleKey: 'notifications.updates',
|
|
38
|
+
descKey: 'notifications.updatesDesc',
|
|
39
|
+
icon: 'update',
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
id: 'features',
|
|
43
|
+
titleKey: 'notifications.features',
|
|
44
|
+
descKey: 'notifications.featuresDesc',
|
|
45
|
+
icon: 'new-releases',
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
id: 'tips',
|
|
49
|
+
titleKey: 'notifications.tips',
|
|
50
|
+
descKey: 'notifications.tipsDesc',
|
|
51
|
+
icon: 'tips-and-updates',
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
id: 'activity',
|
|
57
|
+
titleKey: 'notifications.activity',
|
|
58
|
+
settings: [
|
|
59
|
+
{
|
|
60
|
+
id: 'reminders',
|
|
61
|
+
titleKey: 'notifications.reminders',
|
|
62
|
+
descKey: 'notifications.remindersDesc',
|
|
63
|
+
icon: 'alarm',
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
id: 'achievements',
|
|
67
|
+
titleKey: 'notifications.achievements',
|
|
68
|
+
descKey: 'notifications.achievementsDesc',
|
|
69
|
+
icon: 'emoji-events',
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
id: 'social',
|
|
73
|
+
titleKey: 'notifications.social',
|
|
74
|
+
descKey: 'notifications.socialDesc',
|
|
75
|
+
icon: 'people',
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
};
|
|
81
|
+
//# sourceMappingURL=notificationsConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notificationsConfig.js","sourceRoot":"","sources":["../../../src/infrastructure/config/notificationsConfig.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAmBH,MAAM,CAAC,MAAM,mBAAmB,GAAwB;IACtD,QAAQ,EAAE;QACR;YACE,EAAE,EAAE,UAAU;YACd,QAAQ,EAAE,wBAAwB;YAClC,QAAQ,EAAE;gBACR;oBACE,EAAE,EAAE,mBAAmB;oBACvB,QAAQ,EAAE,oBAAoB;oBAC9B,OAAO,EAAE,wBAAwB;oBACjC,IAAI,EAAE,eAAe;iBACtB;gBACD;oBACE,EAAE,EAAE,oBAAoB;oBACxB,QAAQ,EAAE,qBAAqB;oBAC/B,OAAO,EAAE,yBAAyB;oBAClC,IAAI,EAAE,OAAO;iBACd;gBACD;oBACE,EAAE,EAAE,kBAAkB;oBACtB,QAAQ,EAAE,mBAAmB;oBAC7B,OAAO,EAAE,uBAAuB;oBAChC,IAAI,EAAE,SAAS;iBAChB;aACF;SACF;QACD;YACE,EAAE,EAAE,SAAS;YACb,QAAQ,EAAE,uBAAuB;YACjC,QAAQ,EAAE;gBACR;oBACE,EAAE,EAAE,YAAY;oBAChB,QAAQ,EAAE,uBAAuB;oBACjC,OAAO,EAAE,2BAA2B;oBACpC,IAAI,EAAE,QAAQ;iBACf;gBACD;oBACE,EAAE,EAAE,UAAU;oBACd,QAAQ,EAAE,wBAAwB;oBAClC,OAAO,EAAE,4BAA4B;oBACrC,IAAI,EAAE,cAAc;iBACrB;gBACD;oBACE,EAAE,EAAE,MAAM;oBACV,QAAQ,EAAE,oBAAoB;oBAC9B,OAAO,EAAE,wBAAwB;oBACjC,IAAI,EAAE,kBAAkB;iBACzB;aACF;SACF;QACD;YACE,EAAE,EAAE,UAAU;YACd,QAAQ,EAAE,wBAAwB;YAClC,QAAQ,EAAE;gBACR;oBACE,EAAE,EAAE,WAAW;oBACf,QAAQ,EAAE,yBAAyB;oBACnC,OAAO,EAAE,6BAA6B;oBACtC,IAAI,EAAE,OAAO;iBACd;gBACD;oBACE,EAAE,EAAE,cAAc;oBAClB,QAAQ,EAAE,4BAA4B;oBACtC,OAAO,EAAE,gCAAgC;oBACzC,IAAI,EAAE,cAAc;iBACrB;gBACD;oBACE,EAAE,EAAE,QAAQ;oBACZ,QAAQ,EAAE,sBAAsB;oBAChC,OAAO,EAAE,0BAA0B;oBACnC,IAAI,EAAE,QAAQ;iBACf;aACF;SACF;KACF;CACF,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { SendNotificationOptions, Notification, NotificationChannel, NotificationPreferences } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* useNotificationActions - Offline Notification Actions
|
|
4
|
+
*
|
|
5
|
+
* All actions use AsyncStorage and expo-notifications.
|
|
6
|
+
* NO backend - pure offline.
|
|
7
|
+
*/
|
|
8
|
+
export declare const useNotificationActions: (state: any, setters: any) => {
|
|
9
|
+
sendNotification: (options: SendNotificationOptions) => Promise<Notification[]>;
|
|
10
|
+
markAsRead: (notificationId: string) => Promise<boolean>;
|
|
11
|
+
markAllAsRead: () => Promise<boolean>;
|
|
12
|
+
deleteNotification: (notificationId: string) => Promise<boolean>;
|
|
13
|
+
registerChannel: (channelType: "push" | "in_app", preferences?: Record<string, any>) => Promise<NotificationChannel | null>;
|
|
14
|
+
verifyChannel: (channelId: string) => Promise<boolean>;
|
|
15
|
+
updatePreferences: (newPreferences: Partial<NotificationPreferences>) => Promise<boolean>;
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=useNotificationActions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useNotificationActions.d.ts","sourceRoot":"","sources":["../../../../src/infrastructure/hooks/actions/useNotificationActions.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,uBAAuB,EACvB,YAAY,EACZ,mBAAmB,EACnB,uBAAuB,EACxB,MAAM,UAAU,CAAC;AAKlB;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,GAAI,OAAO,GAAG,EAAE,SAAS,GAAG;gCAc3C,uBAAuB,KAAG,OAAO,CAAC,YAAY,EAAE,CAAC;iCAuC1C,MAAM,KAAG,OAAO,CAAC,OAAO,CAAC;yBAgCN,OAAO,CAAC,OAAO,CAAC;yCAwBnC,MAAM,KAAG,OAAO,CAAC,OAAO,CAAC;mCAkCjC,MAAM,GAAG,QAAQ,gBACjB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAC/B,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC;+BAkBpB,MAAM,KAAG,OAAO,CAAC,OAAO,CAAC;wCAsBpB,OAAO,CAAC,uBAAuB,CAAC,KAAG,OAAO,CAAC,OAAO,CAAC;CA4B7E,CAAC"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
3
|
+
import { NotificationDelivery } from '../../services/delivery/NotificationDelivery';
|
|
4
|
+
import { ChannelManager } from '../../services/channels/ChannelManager';
|
|
5
|
+
import { PreferencesManager } from '../../services/preferences/PreferencesManager';
|
|
6
|
+
/**
|
|
7
|
+
* useNotificationActions - Offline Notification Actions
|
|
8
|
+
*
|
|
9
|
+
* All actions use AsyncStorage and expo-notifications.
|
|
10
|
+
* NO backend - pure offline.
|
|
11
|
+
*/
|
|
12
|
+
export const useNotificationActions = (state, setters) => {
|
|
13
|
+
const { setNotifications, setUnreadCount, setChannels, setPreferences, setError, } = setters;
|
|
14
|
+
const notificationDelivery = new NotificationDelivery();
|
|
15
|
+
const channelManager = new ChannelManager();
|
|
16
|
+
const preferencesManager = new PreferencesManager();
|
|
17
|
+
const sendNotification = useCallback(async (options) => {
|
|
18
|
+
try {
|
|
19
|
+
setError(null);
|
|
20
|
+
// Create notification
|
|
21
|
+
const notification = {
|
|
22
|
+
id: `notif_${Date.now()}`,
|
|
23
|
+
title: options.title,
|
|
24
|
+
body: options.body,
|
|
25
|
+
data: options.data,
|
|
26
|
+
scheduled_for: options.scheduled_for?.toISOString(),
|
|
27
|
+
created_at: new Date().toISOString(),
|
|
28
|
+
read: false,
|
|
29
|
+
};
|
|
30
|
+
// Save to AsyncStorage
|
|
31
|
+
const data = await AsyncStorage.getItem('@notifications:list');
|
|
32
|
+
const notifications = data ? JSON.parse(data) : [];
|
|
33
|
+
notifications.unshift(notification);
|
|
34
|
+
await AsyncStorage.setItem('@notifications:list', JSON.stringify(notifications));
|
|
35
|
+
// Deliver using expo-notifications
|
|
36
|
+
await notificationDelivery.deliver(notification);
|
|
37
|
+
return [notification];
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
setError(err instanceof Error ? err.message : 'Failed to send notification');
|
|
41
|
+
return [];
|
|
42
|
+
}
|
|
43
|
+
}, [setError]);
|
|
44
|
+
const markAsRead = useCallback(async (notificationId) => {
|
|
45
|
+
try {
|
|
46
|
+
const data = await AsyncStorage.getItem('@notifications:list');
|
|
47
|
+
const notifications = data ? JSON.parse(data) : [];
|
|
48
|
+
const updated = notifications.map((n) => n.id === notificationId ? { ...n, read: true } : n);
|
|
49
|
+
await AsyncStorage.setItem('@notifications:list', JSON.stringify(updated));
|
|
50
|
+
setNotifications((prev) => prev.map((n) => n.id === notificationId ? { ...n, read: true } : n));
|
|
51
|
+
setUnreadCount((prev) => Math.max(0, prev - 1));
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
setError(err instanceof Error ? err.message : 'Failed to mark as read');
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
}, [setNotifications, setUnreadCount, setError]);
|
|
59
|
+
const markAllAsRead = useCallback(async () => {
|
|
60
|
+
try {
|
|
61
|
+
const data = await AsyncStorage.getItem('@notifications:list');
|
|
62
|
+
const notifications = data ? JSON.parse(data) : [];
|
|
63
|
+
const updated = notifications.map((n) => ({ ...n, read: true }));
|
|
64
|
+
await AsyncStorage.setItem('@notifications:list', JSON.stringify(updated));
|
|
65
|
+
setNotifications((prev) => prev.map((n) => ({ ...n, read: true })));
|
|
66
|
+
setUnreadCount(0);
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
setError(err instanceof Error ? err.message : 'Failed to mark all as read');
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
}, [setNotifications, setUnreadCount, setError]);
|
|
74
|
+
const deleteNotification = useCallback(async (notificationId) => {
|
|
75
|
+
try {
|
|
76
|
+
const data = await AsyncStorage.getItem('@notifications:list');
|
|
77
|
+
const notifications = data ? JSON.parse(data) : [];
|
|
78
|
+
const deleted = notifications.find((n) => n.id === notificationId);
|
|
79
|
+
const filtered = notifications.filter((n) => n.id !== notificationId);
|
|
80
|
+
await AsyncStorage.setItem('@notifications:list', JSON.stringify(filtered));
|
|
81
|
+
setNotifications((prev) => prev.filter((n) => n.id !== notificationId));
|
|
82
|
+
if (deleted && !deleted.read) {
|
|
83
|
+
setUnreadCount((prev) => Math.max(0, prev - 1));
|
|
84
|
+
}
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
setError(err instanceof Error ? err.message : 'Failed to delete notification');
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
}, [setNotifications, setUnreadCount, setError]);
|
|
92
|
+
const registerChannel = useCallback(async (channelType, preferences = {}) => {
|
|
93
|
+
try {
|
|
94
|
+
const channel = await channelManager.register(channelType, preferences);
|
|
95
|
+
if (channel) {
|
|
96
|
+
setChannels((prev) => [...prev, channel]);
|
|
97
|
+
}
|
|
98
|
+
return channel;
|
|
99
|
+
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
setError(err instanceof Error ? err.message : 'Failed to register channel');
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
}, [setChannels, setError]);
|
|
105
|
+
const verifyChannel = useCallback(async (channelId) => {
|
|
106
|
+
try {
|
|
107
|
+
const success = await channelManager.verify(channelId);
|
|
108
|
+
if (success) {
|
|
109
|
+
setChannels((prev) => prev.map((c) => c.id === channelId ? { ...c, is_verified: true } : c));
|
|
110
|
+
}
|
|
111
|
+
return success;
|
|
112
|
+
}
|
|
113
|
+
catch (err) {
|
|
114
|
+
setError(err instanceof Error ? err.message : 'Failed to verify channel');
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
}, [setChannels, setError]);
|
|
118
|
+
const updatePreferences = useCallback(async (newPreferences) => {
|
|
119
|
+
try {
|
|
120
|
+
const success = await preferencesManager.update(newPreferences);
|
|
121
|
+
if (success) {
|
|
122
|
+
setPreferences((prev) => prev ? { ...prev, ...newPreferences } : null);
|
|
123
|
+
}
|
|
124
|
+
return success;
|
|
125
|
+
}
|
|
126
|
+
catch (err) {
|
|
127
|
+
setError(err instanceof Error ? err.message : 'Failed to update preferences');
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
}, [setPreferences, setError]);
|
|
131
|
+
return {
|
|
132
|
+
sendNotification,
|
|
133
|
+
markAsRead,
|
|
134
|
+
markAllAsRead,
|
|
135
|
+
deleteNotification,
|
|
136
|
+
registerChannel,
|
|
137
|
+
verifyChannel,
|
|
138
|
+
updatePreferences,
|
|
139
|
+
};
|
|
140
|
+
};
|
|
141
|
+
//# sourceMappingURL=useNotificationActions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useNotificationActions.js","sourceRoot":"","sources":["../../../../src/infrastructure/hooks/actions/useNotificationActions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,YAAY,MAAM,2CAA2C,CAAC;AAQrE,OAAO,EAAE,oBAAoB,EAAE,MAAM,8CAA8C,C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AC;YACJ,CAAC;YACD,OAAO,OAAO,CAAC;QACjB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,QAAQ,CACN,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,0BAA0B,CAChE,CAAC;YACF,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC,EACD,CAAC,WAAW,EAAE,QAAQ,CAAC,CACxB,CAAC;IAEF,MAAM,iBAAiB,GAAG,WAAW,CACnC,KAAK,EAAE,cAAgD,EAAoB,EAAE;QAC3E,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,MAAM,kBAAkB,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;YAChE,IAAI,OAAO,EAAE,CAAC;gBACZ,cAAc,CAAC,CAAC,IAAoC,EAAE,EAAE,CACtD,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,cAAc,EAAE,CAAC,CAAC,CAAC,IAAI,CAC7C,CAAC;YACJ,CAAC;YACD,OAAO,OAAO,CAAC;QACjB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,QAAQ,CACN,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,8BAA8B,CACpE,CAAC;YACF,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC,EACD,CAAC,cAAc,EAAE,QAAQ,CAAC,CAC3B,CAAC;IAEF,OAAO;QACL,gBAAgB;QAChB,UAAU;QACV,aAAa;QACb,kBAAkB;QAClB,eAAe;QACf,aAAa;QACb,iBAAiB;KAClB,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { NotificationsState } from '../types';
|
|
2
|
+
export declare const useNotificationsState: () => {
|
|
3
|
+
state: NotificationsState;
|
|
4
|
+
setNotifications: (notifications: NotificationsState["notifications"]) => void;
|
|
5
|
+
setChannels: (channels: NotificationsState["channels"]) => void;
|
|
6
|
+
setUnreadCount: (unreadCount: number) => void;
|
|
7
|
+
setPreferences: (preferences: NotificationsState["preferences"]) => void;
|
|
8
|
+
setLoading: (loading: boolean) => void;
|
|
9
|
+
setError: (error: string | null) => void;
|
|
10
|
+
setHasMore: (hasMore: boolean) => void;
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=useNotificationsState.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useNotificationsState.d.ts","sourceRoot":"","sources":["../../../../src/infrastructure/hooks/state/useNotificationsState.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAEnD,eAAO,MAAM,qBAAqB;;sCAWS,kBAAkB,CAAC,eAAe,CAAC;4BAG7C,kBAAkB,CAAC,UAAU,CAAC;kCAGxB,MAAM;kCAGN,kBAAkB,CAAC,aAAa,CAAC;0BAGzC,OAAO;sBAGX,MAAM,GAAG,IAAI;0BAGT,OAAO;CAarC,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
export const useNotificationsState = () => {
|
|
3
|
+
const [state, setState] = useState({
|
|
4
|
+
notifications: [],
|
|
5
|
+
channels: [],
|
|
6
|
+
unreadCount: 0,
|
|
7
|
+
preferences: null,
|
|
8
|
+
loading: false,
|
|
9
|
+
error: null,
|
|
10
|
+
hasMore: true,
|
|
11
|
+
});
|
|
12
|
+
const setNotifications = (notifications) => setState(prev => ({ ...prev, notifications }));
|
|
13
|
+
const setChannels = (channels) => setState(prev => ({ ...prev, channels }));
|
|
14
|
+
const setUnreadCount = (unreadCount) => setState(prev => ({ ...prev, unreadCount }));
|
|
15
|
+
const setPreferences = (preferences) => setState(prev => ({ ...prev, preferences }));
|
|
16
|
+
const setLoading = (loading) => setState(prev => ({ ...prev, loading }));
|
|
17
|
+
const setError = (error) => setState(prev => ({ ...prev, error }));
|
|
18
|
+
const setHasMore = (hasMore) => setState(prev => ({ ...prev, hasMore }));
|
|
19
|
+
return {
|
|
20
|
+
state,
|
|
21
|
+
setNotifications,
|
|
22
|
+
setChannels,
|
|
23
|
+
setUnreadCount,
|
|
24
|
+
setPreferences,
|
|
25
|
+
setLoading,
|
|
26
|
+
setError,
|
|
27
|
+
setHasMore,
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=useNotificationsState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useNotificationsState.js","sourceRoot":"","sources":["../../../../src/infrastructure/hooks/state/useNotificationsState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAGjC,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,EAAE;IACxC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAqB;QACrD,aAAa,EAAE,EAAE;QACjB,QAAQ,EAAE,EAAE;QACZ,WAAW,EAAE,CAAC;QACd,WAAW,EAAE,IAAI;QACjB,OAAO,EAAE,KAAK;QACd,KAAK,EAAE,IAAI;QACX,OAAO,EAAE,IAAI;KACd,CAAC,CAAC;IAEH,MAAM,gBAAgB,GAAG,CAAC,aAAkD,EAAE,EAAE,CAC9E,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC;IAEjD,MAAM,WAAW,GAAG,CAAC,QAAwC,EAAE,EAAE,CAC/D,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC;IAE5C,MAAM,cAAc,GAAG,CAAC,WAAmB,EAAE,EAAE,CAC7C,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC;IAE/C,MAAM,cAAc,GAAG,CAAC,WAA8C,EAAE,EAAE,CACxE,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC;IAE/C,MAAM,UAAU,GAAG,CAAC,OAAgB,EAAE,EAAE,CACtC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;IAE3C,MAAM,QAAQ,GAAG,CAAC,KAAoB,EAAE,EAAE,CACxC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;IAEzC,MAAM,UAAU,GAAG,CAAC,OAAgB,EAAE,EAAE,CACtC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;IAE3C,OAAO;QACL,KAAK;QACL,gBAAgB;QAChB,WAAW;QACX,cAAc;QACd,cAAc;QACd,UAAU;QACV,QAAQ;QACR,UAAU;KACX,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Notification Hook Types - Offline-First
|
|
3
|
+
*
|
|
4
|
+
* All types for offline local notifications.
|
|
5
|
+
* NO backend dependencies.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Local notification entity
|
|
9
|
+
*/
|
|
10
|
+
export interface Notification {
|
|
11
|
+
id: string;
|
|
12
|
+
title: string;
|
|
13
|
+
body: string;
|
|
14
|
+
data?: Record<string, any>;
|
|
15
|
+
scheduled_for?: string;
|
|
16
|
+
created_at: string;
|
|
17
|
+
read: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Notification channel (push or in-app only)
|
|
21
|
+
*/
|
|
22
|
+
export interface NotificationChannel {
|
|
23
|
+
id: string;
|
|
24
|
+
channel_type: 'push' | 'in_app';
|
|
25
|
+
channel_address: string;
|
|
26
|
+
preferences: Record<string, any>;
|
|
27
|
+
is_verified: boolean;
|
|
28
|
+
is_active: boolean;
|
|
29
|
+
created_at: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Notification preferences
|
|
33
|
+
*/
|
|
34
|
+
export interface NotificationPreferences {
|
|
35
|
+
push_enabled: boolean;
|
|
36
|
+
quiet_hours: {
|
|
37
|
+
enabled: boolean;
|
|
38
|
+
start_time: string;
|
|
39
|
+
end_time: string;
|
|
40
|
+
timezone: string;
|
|
41
|
+
};
|
|
42
|
+
categories: {
|
|
43
|
+
reminders: {
|
|
44
|
+
push: boolean;
|
|
45
|
+
in_app: boolean;
|
|
46
|
+
};
|
|
47
|
+
updates: {
|
|
48
|
+
push: boolean;
|
|
49
|
+
in_app: boolean;
|
|
50
|
+
};
|
|
51
|
+
alerts: {
|
|
52
|
+
push: boolean;
|
|
53
|
+
in_app: boolean;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Options for sending notification
|
|
59
|
+
*/
|
|
60
|
+
export interface SendNotificationOptions {
|
|
61
|
+
title: string;
|
|
62
|
+
body: string;
|
|
63
|
+
data?: Record<string, any>;
|
|
64
|
+
scheduled_for?: Date;
|
|
65
|
+
category?: 'reminders' | 'updates' | 'alerts';
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* State for useNotifications hook
|
|
69
|
+
*/
|
|
70
|
+
export interface NotificationsState {
|
|
71
|
+
notifications: Notification[];
|
|
72
|
+
channels: NotificationChannel[];
|
|
73
|
+
unreadCount: number;
|
|
74
|
+
preferences: NotificationPreferences | null;
|
|
75
|
+
loading: boolean;
|
|
76
|
+
error: string | null;
|
|
77
|
+
hasMore: boolean;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Options for useNotifications hook
|
|
81
|
+
*/
|
|
82
|
+
export interface UseNotificationsOptions {
|
|
83
|
+
autoRefresh?: boolean;
|
|
84
|
+
refreshInterval?: number;
|
|
85
|
+
pageSize?: number;
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/hooks/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,OAAO,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,YAAY,EAAE,MAAM,GAAG,QAAQ,CAAC;IAChC,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACjC,WAAW,EAAE,OAAO,CAAC;IACrB,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,YAAY,EAAE,OAAO,CAAC;IACtB,WAAW,EAAE;QACX,OAAO,EAAE,OAAO,CAAC;QACjB,UAAU,EAAE,MAAM,CAAC;QACnB,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;IACF,UAAU,EAAE;QACV,SAAS,EAAE;YAAE,IAAI,EAAE,OAAO,CAAC;YAAC,MAAM,EAAE,OAAO,CAAA;SAAE,CAAC;QAC9C,OAAO,EAAE;YAAE,IAAI,EAAE,OAAO,CAAC;YAAC,MAAM,EAAE,OAAO,CAAA;SAAE,CAAC;QAC5C,MAAM,EAAE;YAAE,IAAI,EAAE,OAAO,CAAC;YAAC,MAAM,EAAE,OAAO,CAAA;SAAE,CAAC;KAC5C,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,aAAa,CAAC,EAAE,IAAI,CAAC;IACrB,QAAQ,CAAC,EAAE,WAAW,GAAG,SAAS,GAAG,QAAQ,CAAC;CAC/C;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,aAAa,EAAE,YAAY,EAAE,CAAC;IAC9B,QAAQ,EAAE,mBAAmB,EAAE,CAAC;IAChC,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,uBAAuB,GAAG,IAAI,CAAC;IAC5C,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/infrastructure/hooks/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple notification settings hook
|
|
3
|
+
* Manages a single toggle for enabling/disabling notifications
|
|
4
|
+
*/
|
|
5
|
+
export declare const useNotificationSettings: () => {
|
|
6
|
+
notificationsEnabled: boolean;
|
|
7
|
+
setNotificationsEnabled: (value: boolean) => Promise<void>;
|
|
8
|
+
isLoading: boolean;
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=useNotificationSettings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useNotificationSettings.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/hooks/useNotificationSettings.ts"],"names":[],"mappings":"AAKA;;;GAGG;AACH,eAAO,MAAM,uBAAuB;;qCAqBQ,OAAO;;CAclD,CAAC"}
|