@@ -3,20 +3,27 @@ import {
3
3
Contents ,
4
4
idxKey ,
5
5
ILink ,
6
+ mog ,
6
7
NodeEditorContent ,
7
8
NodeMetadata ,
9
+ Reminder ,
10
+ ReminderActions ,
8
11
Snippet ,
9
12
UserDetails ,
10
13
WorkspaceDetails
11
14
} from '@mexit/core'
12
15
import { Theme } from '@mexit/shared'
13
16
import { AsyncMethodReturns , Methods } from 'penpal'
17
+ import { useEffect } from 'react'
18
+ import { addMinutes } from 'date-fns'
14
19
import toast from 'react-hot-toast'
15
20
import { useContentStore } from '../Stores/useContentStore'
16
21
import useDataStore from '../Stores/useDataStore'
22
+ import { useReminderStore } from '../Stores/useReminderStore'
17
23
import { useSnippetStore } from '../Stores/useSnippetStore'
18
24
import { useAuthStore } from './useAuth'
19
25
import useInternalAuthStore from './useAuthStore'
26
+ import { useReminders } from './useReminders'
20
27
import useThemeStore from './useThemeStore'
21
28
22
29
interface ParentMethods {
@@ -26,6 +33,7 @@ interface ParentMethods {
26
33
// ['SEARCH']: (key: idxKey | idxKey[], query: string) => Promise<any>
27
34
[ 'SET_CONTENT' ] : [ props : { nodeid : string ; content : NodeEditorContent ; metadata : NodeMetadata } ]
28
35
[ 'ADD_ILINK' ] : [ props : AddILinkProps ]
36
+ [ 'ACT_ON_REMINDER' ] : [ props : { action : ReminderActions ; reminder : Reminder } ]
29
37
}
30
38
31
39
// Raju is great with doing Hera Pheri
@@ -38,6 +46,42 @@ export default function useRaju() {
38
46
const initContents = useContentStore ( ( store ) => store . initContents )
39
47
const setIlinks = useDataStore ( ( store ) => store . setIlinks )
40
48
const initSnippets = useSnippetStore ( ( store ) => store . initSnippets )
49
+ const { setReminders, reminders } = useReminderStore ( )
50
+ const { actOnReminder } = useReminders ( )
51
+
52
+ useEffect ( ( ) => {
53
+ const handleMessage = ( message ) => {
54
+ if ( message . type === 'RAJU' ) {
55
+ console . log ( 'actOnReminders' , reminders , message , addMinutes ( Date . now ( ) , 15 ) . getTime ( ) )
56
+ const mentionedReminder = reminders . find ( ( item ) => item . id === message . notificationId )
57
+ switch ( message . action ) {
58
+ case 'OPEN' :
59
+ actOnReminder ( { type : 'open' } , mentionedReminder )
60
+ dispatch ( 'ACT_ON_REMINDER' , { action : { type : 'open' } , reminder : mentionedReminder } )
61
+ break
62
+ case 'SNOOZE' :
63
+ actOnReminder ( { type : 'snooze' , value : addMinutes ( Date . now ( ) , 15 ) . getTime ( ) } , mentionedReminder )
64
+ dispatch ( 'ACT_ON_REMINDER' , {
65
+ action : { type : 'snooze' , value : addMinutes ( Date . now ( ) , 15 ) . getTime ( ) } ,
66
+ reminder : mentionedReminder
67
+ } )
68
+ break
69
+ case 'DISMISS' :
70
+ actOnReminder ( { type : 'dismiss' } , mentionedReminder )
71
+ dispatch ( 'ACT_ON_REMINDER' , { action : { type : 'dismiss' } , reminder : mentionedReminder } )
72
+ break
73
+ }
74
+ }
75
+
76
+ return
77
+ }
78
+
79
+ chrome . runtime . onMessage . addListener ( handleMessage )
80
+
81
+ return ( ) => {
82
+ chrome . runtime . onMessage . removeListener ( handleMessage )
83
+ }
84
+ } , [ reminders ] )
41
85
42
86
const methods : Methods = {
43
87
init (
@@ -47,14 +91,16 @@ export default function useRaju() {
47
91
authAWS : any ,
48
92
snippets : Snippet [ ] ,
49
93
contents : Contents ,
50
- ilinks : any [ ]
94
+ ilinks : any [ ] ,
95
+ reminders : Reminder [ ]
51
96
) {
52
97
setAuthenticated ( userDetails , workspaceDetails )
53
98
setTheme ( theme )
54
99
setInternalAuthStore ( authAWS )
55
100
initSnippets ( snippets )
56
101
setIlinks ( ilinks )
57
102
initContents ( contents )
103
+ setReminders ( reminders )
58
104
} ,
59
105
success ( message : string ) {
60
106
toast . success ( message )
0 commit comments