1- import { useEffect , useState } from 'react' ;
1+ import { useEffect , useState , useRef } from 'react' ;
22import ToggleButton from 'react-toggle-button' ;
33import { setRemoteUser , setupReplication , teardownReplication } from 'trace-search' ;
44import Auth from "@aws-amplify/auth" ;
5+ import NotificationAlert from "react-notification-alert" ;
56
67function SyncToggle ( ) {
78 const [ replicate , setReplicate ] = useState ( false ) ;
89 const [ isLoggedIn , setIsLoggedIn ] = useState ( false ) ;
910
11+ const notificationAlertRef = useRef ( null ) ;
12+ const toast = ( message , type ) => {
13+ var options = { } ;
14+ options = {
15+ place : "bc" ,
16+ message : ( < span > { message } </ span > ) ,
17+ type : type ,
18+ autoDismiss : 7 ,
19+ } ;
20+ notificationAlertRef . current . notificationAlert ( options ) ;
21+ }
22+
1023 useEffect ( ( ) => {
1124 ( async ( ) => {
1225 try {
@@ -23,7 +36,7 @@ function SyncToggle() {
2336 useEffect ( ( ) => {
2437 async function handleReplication ( ) {
2538 if ( ! isLoggedIn && replicate ) {
26- alert ( 'You must sign in to use sync!' ) ;
39+ toast ( 'You must sign in to use sync!' , "danger" ) ;
2740 setReplicate ( false ) ;
2841 return ;
2942 }
@@ -36,12 +49,12 @@ function SyncToggle() {
3649 const replicator = obj . TODO_replication ;
3750
3851 replicator . on ( 'error' , ( e ) => {
39- alert ( `Replication error: ${ e . message || e } ` ) ;
52+ toast ( `Replication error: ${ e . message || e } ` , "danger" ) ;
4053 console . error ( e ) ;
4154 setReplicate ( false ) ;
4255 } ) ;
4356 } catch ( e ) {
44- alert ( `Replication error: ${ e . message || e } ` ) ;
57+ toast ( `Replication error: ${ e . message || e } ` , "danger" ) ;
4558 console . error ( e ) ;
4659 setReplicate ( false ) ;
4760 return ;
@@ -59,15 +72,20 @@ function SyncToggle() {
5972 } , [ replicate , isLoggedIn ] ) ;
6073
6174 return (
62- < div style = { { textAlign : 'center' } } >
63- Sync
64- < ToggleButton
65- inactiveLabel = { < span > Off</ span > }
66- activeLabel = { < span > On</ span > }
67- value = { replicate || false }
68- onToggle = { ( ) => setReplicate ( prev => ! prev ) }
69- />
70- </ div >
75+ < >
76+ < div className = "react-notification-alert-container" >
77+ < NotificationAlert ref = { notificationAlertRef } />
78+ </ div >
79+ < div style = { { textAlign : 'center' } } >
80+ Sync
81+ < ToggleButton
82+ inactiveLabel = { < span > Off</ span > }
83+ activeLabel = { < span > On</ span > }
84+ value = { replicate || false }
85+ onToggle = { ( ) => setReplicate ( prev => ! prev ) }
86+ />
87+ </ div >
88+ </ >
7189 ) ;
7290}
7391
0 commit comments