1
- import React , { useContext , useEffect , useState } from 'react'
1
+ import React , { useContext , useEffect , useRef , useState } from 'react'
2
2
import { FormattedMessage } from 'react-intl'
3
- import { AppContext } from '../../context/context'
4
3
import { useDialogDispatchers } from '../../context/provider'
5
- import { AppModalCancelTypes } from '../../types'
6
4
declare global {
7
5
interface Window {
8
6
_paq : any
@@ -13,12 +11,23 @@ const _paq = (window._paq = window._paq || [])
13
11
interface ManagePreferencesDialogProps {
14
12
}
15
13
16
- const ManagePreferencesDialog = ( props : ManagePreferencesDialogProps ) => {
17
- const { modal } = useDialogDispatchers ( )
18
- const [ visible , setVisible ] = useState < boolean > ( true )
14
+ const ManagePreferencesSwitcher = ( prop : {
15
+ setParentState : ( state : any ) => void
16
+ } ) => {
17
+ const [ remixAISwitch , setRemixAISwitch ] = useState ( true )
18
+ const [ matPerfSwitch , setMatPerfSwitch ] = useState ( false )
19
+ const [ matAnonSwitch , setMatAnonSwitch ] = useState ( false )
20
+
19
21
20
- const message = ( ) => {
21
- return (
22
+ useEffect ( ( ) => {
23
+ prop . setParentState ( {
24
+ remixAISwitch,
25
+ matPerfSwitch,
26
+ matAnonSwitch
27
+ } )
28
+ } , [ remixAISwitch , matPerfSwitch , matAnonSwitch ] )
29
+
30
+ return (
22
31
< >
23
32
< div data-id = "remixAI" className = 'justify-content-between d-flex' >
24
33
< div className = 'mt-2' >
@@ -40,9 +49,9 @@ const ManagePreferencesDialog = (props: ManagePreferencesDialogProps) => {
40
49
data-id = "remixAISwitch"
41
50
id = 'remixAISwitch'
42
51
className = "btn text-ai"
43
- onClick = { ( ) => { } }
52
+ onClick = { ( ) => setRemixAISwitch ( ! remixAISwitch ) }
44
53
>
45
- < i className = "fas fa-toggle-on fa-2xl" > </ i >
54
+ { remixAISwitch ? < i className = "fas fa-toggle-on fa-2xl" > </ i > : < i className = "fas fa-toggle-off fa-2xl" > </ i > }
46
55
</ button >
47
56
</ div >
48
57
</ div >
@@ -66,9 +75,9 @@ const ManagePreferencesDialog = (props: ManagePreferencesDialogProps) => {
66
75
data-id = "matomoAnonAnalyticsSwitch"
67
76
id = 'matomoAnonAnalyticsSwitch'
68
77
className = "btn text-ai"
69
- onClick = { ( ) => { } }
78
+ onClick = { ( ) => setMatAnonSwitch ( ! matAnonSwitch ) }
70
79
>
71
- < i className = "fas fa-toggle-off fa-2xl" > </ i >
80
+ { matAnonSwitch ? < i className = "fas fa-toggle-on fa-2xl" > </ i > : < i className = "fas fa-toggle- off fa-2xl"> </ i > }
72
81
</ button >
73
82
</ div >
74
83
</ div >
@@ -82,32 +91,43 @@ const ManagePreferencesDialog = (props: ManagePreferencesDialogProps) => {
82
91
data-id = "matomoPerfAnalyticsSwitch"
83
92
id = 'matomoPerfAnalyticsSwitch'
84
93
className = "btn text-secondary"
85
- onClick = { ( ) => { } }
94
+ onClick = { ( ) => setMatPerfSwitch ( ! matPerfSwitch ) }
86
95
>
87
- < i className = "fas fa-toggle-off fa-2xl" > </ i >
96
+ { matPerfSwitch ? < i className = "fas fa-toggle-on fa-2xl" > </ i > : < i className = "fas fa-toggle- off fa-2xl"> </ i > }
88
97
</ button >
89
98
</ div >
90
99
</ div >
91
100
</ >
92
101
)
93
- }
102
+ }
103
+
104
+ const ManagePreferencesDialog = ( props : ManagePreferencesDialogProps ) => {
105
+ const { modal } = useDialogDispatchers ( )
106
+ const [ visible , setVisible ] = useState < boolean > ( true )
107
+ let switcherState = useRef < Record < string , any > > ( null )
94
108
95
109
useEffect ( ( ) => {
96
110
if ( visible ) {
97
111
modal ( {
98
112
id : 'managePreferencesModal' ,
99
113
title : < FormattedMessage id = "remixApp.managePreferences" /> ,
100
- message : message ( ) ,
101
- okLabel : < FormattedMessage id = "remixApp.declineCookies" /> ,
102
- okFn : ( ) => { } ,
103
- cancelLabel : < FormattedMessage id = "remixApp.savePreferences" /> ,
114
+ message : < ManagePreferencesSwitcher setParentState = { ( state ) => {
115
+ switcherState . current = state
116
+ } } /> ,
117
+ okLabel : < FormattedMessage id = "remixApp.savePreferences" /> ,
118
+ okFn : savePreferences ,
119
+ cancelLabel : < FormattedMessage id = "remixApp.declineCookies" /> ,
104
120
cancelFn : ( ) => { } ,
105
121
showCancelIcon : true ,
106
122
preventBlur : true
107
123
} )
108
124
}
109
125
} , [ visible ] )
110
126
127
+ const savePreferences = async ( ) => {
128
+ console . log ( 'switcherState--->' , switcherState . current )
129
+ }
130
+
111
131
return < > </ >
112
132
}
113
133
0 commit comments