1
1
import * as React from 'react'
2
- import { isRtl } from '@framework/AppContext'
3
2
import * as Operations from '@framework/Operations'
4
- import { getTypeInfo , symbolNiceName } from '@framework/Reflection'
5
3
import * as Finder from '@framework/Finder'
6
4
import { is , JavascriptMessage , toLite } from '@framework/Signum.Entities'
7
- import { Toast , NavItem , Button , ButtonGroup } from 'react-bootstrap'
5
+ import { Toast , Button , ButtonGroup } from 'react-bootstrap'
8
6
import { DateTime } from 'luxon'
9
- import { useAPI , useAPIWithReload , useDocumentEvent , useForceUpdate , useInterval , usePrevious , useThrottle , useUpdatedRef } from '@framework/Hooks' ;
10
- import { LinkContainer } from '@framework/Components'
7
+ import { useAPIWithReload , useForceUpdate , useUpdatedRef } from '@framework/Hooks' ;
11
8
import * as AuthClient from '../Authorization/AuthClient'
12
9
import * as Navigator from '@framework/Navigator'
13
10
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
@@ -17,27 +14,33 @@ import "./AlertDropdown.css"
17
14
import { Link } from 'react-router-dom' ;
18
15
import { classes , Dic } from '@framework/Globals'
19
16
import MessageModal from '@framework/Modals/MessageModal'
20
- import { EntityLink } from '@framework/Search '
17
+ import { useSignalRCallback , useSignalRConnection } from './useSignalR '
21
18
22
- export default function AlertDropdown ( props : { checkForChangesEvery ?: number , keepRingingFor ?: number } ) {
19
+ export default function AlertDropdown ( props : { keepRingingFor ?: number } ) {
23
20
24
21
if ( ! Navigator . isViewable ( AlertEntity ) )
25
22
return null ;
26
23
27
- return < AlertDropdownImp checkForChangesEvery = { props . checkForChangesEvery ?? 30 * 1000 } keepRingingFor = { props . keepRingingFor ?? 10 * 1000 } /> ;
24
+ return < AlertDropdownImp keepRingingFor = { props . keepRingingFor ?? 10 * 1000 } /> ;
28
25
}
29
26
30
- function AlertDropdownImp ( props : { checkForChangesEvery : number , keepRingingFor : number } ) {
27
+ function AlertDropdownImp ( props : { keepRingingFor : number } ) {
28
+
29
+ const conn = useSignalRConnection ( "~/api/alertshub" , {
30
+ accessTokenFactory : ( ) => AuthClient . getAuthToken ( ) ! ,
31
+ } ) ;
32
+
33
+ useSignalRCallback ( conn , "AlertsChanged" , ( ) => {
34
+ reloadCount ( ) ;
35
+ } , [ ] ) ;
31
36
32
37
const forceUpdate = useForceUpdate ( ) ;
33
38
const [ isOpen , setIsOpen ] = React . useState < boolean > ( false ) ;
34
39
const [ ringing , setRinging ] = React . useState < boolean > ( false ) ;
35
40
const ringingRef = useUpdatedRef ( ringing ) ;
36
41
37
42
const [ showAlerts , setShowAlert ] = React . useState < number > ( 5 ) ;
38
-
39
- var ticks = useInterval ( props . checkForChangesEvery , 0 , n => n + 1 ) ;
40
-
43
+
41
44
const isOpenRef = useUpdatedRef ( isOpen ) ;
42
45
43
46
var [ countResult , reloadCount ] = useAPIWithReload < AlertsClient . NumAlerts > ( ( signal , oldResult ) => AlertsClient . API . myAlertsCount ( ) . then ( res => {
@@ -63,7 +66,7 @@ function AlertDropdownImp(props: { checkForChangesEvery: number, keepRingingFor:
63
66
}
64
67
65
68
return res ;
66
- } ) , [ ticks ] , { avoidReset : true } ) ;
69
+ } ) , [ ] , { avoidReset : true } ) ;
67
70
68
71
React . useEffect ( ( ) => {
69
72
if ( ringing ) {
@@ -75,10 +78,6 @@ function AlertDropdownImp(props: { checkForChangesEvery: number, keepRingingFor:
75
78
}
76
79
} , [ ringing ] ) ;
77
80
78
- useDocumentEvent ( "refresh-alerts" , ( e : Event ) => {
79
- reloadCount ( ) ;
80
- } , [ ] ) ;
81
-
82
81
const [ alerts , setAlerts ] = React . useState < AlertEntity [ ] | undefined > ( undefined ) ;
83
82
const [ groupBy , setGroupBy ] = React . useState < AlertDropDownGroup > ( "ByTypeAndUser" ) ;
84
83
@@ -108,8 +107,6 @@ function AlertDropdownImp(props: { checkForChangesEvery: number, keepRingingFor:
108
107
countResult . numAlerts -= toRemove . length ;
109
108
forceUpdate ( ) ;
110
109
111
-
112
-
113
110
Operations . API . executeMultiple ( toRemove . map ( a => toLite ( a ) ) , AlertOperation . Attend )
114
111
. then ( res => {
115
112
0 commit comments