Skip to content

Commit 3eb083f

Browse files
committed
switcher state
1 parent 659669f commit 3eb083f

File tree

1 file changed

+39
-19
lines changed

1 file changed

+39
-19
lines changed

libs/remix-ui/app/src/lib/remix-app/components/modals/managePreferences.tsx

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import React, { useContext, useEffect, useState } from 'react'
1+
import React, { useContext, useEffect, useRef, useState } from 'react'
22
import { FormattedMessage } from 'react-intl'
3-
import { AppContext } from '../../context/context'
43
import { useDialogDispatchers } from '../../context/provider'
5-
import { AppModalCancelTypes } from '../../types'
64
declare global {
75
interface Window {
86
_paq: any
@@ -13,12 +11,23 @@ const _paq = (window._paq = window._paq || [])
1311
interface ManagePreferencesDialogProps {
1412
}
1513

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+
1921

20-
const message = () => {
21-
return (
22+
useEffect(() => {
23+
prop.setParentState({
24+
remixAISwitch,
25+
matPerfSwitch,
26+
matAnonSwitch
27+
})
28+
}, [remixAISwitch, matPerfSwitch, matAnonSwitch])
29+
30+
return (
2231
<>
2332
<div data-id="remixAI" className='justify-content-between d-flex'>
2433
<div className='mt-2'>
@@ -40,9 +49,9 @@ const ManagePreferencesDialog = (props: ManagePreferencesDialogProps) => {
4049
data-id="remixAISwitch"
4150
id='remixAISwitch'
4251
className="btn text-ai"
43-
onClick={() => {}}
52+
onClick={() => setRemixAISwitch(!remixAISwitch)}
4453
>
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> }
4655
</button>
4756
</div>
4857
</div>
@@ -66,9 +75,9 @@ const ManagePreferencesDialog = (props: ManagePreferencesDialogProps) => {
6675
data-id="matomoAnonAnalyticsSwitch"
6776
id='matomoAnonAnalyticsSwitch'
6877
className="btn text-ai"
69-
onClick={() => {}}
78+
onClick={() => setMatAnonSwitch(!matAnonSwitch)}
7079
>
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> }
7281
</button>
7382
</div>
7483
</div>
@@ -82,32 +91,43 @@ const ManagePreferencesDialog = (props: ManagePreferencesDialogProps) => {
8291
data-id="matomoPerfAnalyticsSwitch"
8392
id='matomoPerfAnalyticsSwitch'
8493
className="btn text-secondary"
85-
onClick={() => {}}
94+
onClick={() => setMatPerfSwitch(!matPerfSwitch)}
8695
>
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> }
8897
</button>
8998
</div>
9099
</div>
91100
</>
92101
)
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)
94108

95109
useEffect(() => {
96110
if (visible) {
97111
modal({
98112
id: 'managePreferencesModal',
99113
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" />,
104120
cancelFn: () => {},
105121
showCancelIcon: true,
106122
preventBlur: true
107123
})
108124
}
109125
}, [visible])
110126

127+
const savePreferences = async () => {
128+
console.log('switcherState--->', switcherState.current)
129+
}
130+
111131
return <></>
112132
}
113133

0 commit comments

Comments
 (0)