@@ -3,53 +3,64 @@ import { setModalStates } from "@/src/reduxStore/states/modal";
33import { selectConfiguration , updateConfigurationState } from "@/src/reduxStore/states/pages/data-browser" ;
44import { LineBreaksType } from "@/src/types/components/projects/projectId/data-browser/data-browser" ;
55import { ModalEnum } from "@/src/types/shared/modal" ;
6+ import { useCallback , useEffect } from "react" ;
67import { useDispatch , useSelector } from "react-redux" ;
78
89export default function ConfigurationModal ( ) {
910 const dispatch = useDispatch ( ) ;
1011
1112 const configuration = useSelector ( selectConfiguration ) ;
13+ useEffect ( ( ) => {
14+ const lineBreaks = localStorage . getItem ( 'lineBreaks' ) ;
15+ if ( lineBreaks ) {
16+ dispatch ( updateConfigurationState ( 'lineBreaks' , JSON . parse ( lineBreaks ) as LineBreaksType ) ) ;
17+ }
18+ } , [ ] ) ;
19+
1220
13- function toggleConfigurationOption ( field : string ) {
21+ const toggleConfigurationOption = useCallback ( ( field : string ) => {
1422 dispatch ( updateConfigurationState ( field , ! configuration [ field ] ) ) ;
1523 dispatch ( setModalStates ( ModalEnum . CONFIGURATION , { open : true } ) ) ;
16- }
24+ } , [ configuration ] ) ;
1725
18- function toggleLineBreaks ( ) {
26+ const toggleLineBreaks = useCallback ( ( ) => {
1927 if ( configuration . lineBreaks == LineBreaksType . IS_PRE_WRAP || configuration . lineBreaks == LineBreaksType . IS_PRE_LINE ) {
2028 dispatch ( updateConfigurationState ( 'lineBreaks' , LineBreaksType . NORMAL ) ) ;
2129 dispatch ( setModalStates ( ModalEnum . CONFIGURATION , { open : true } ) ) ;
30+ localStorage . setItem ( 'lineBreaks' , JSON . stringify ( LineBreaksType . NORMAL ) ) ;
2231
2332 } else {
2433 dispatch ( updateConfigurationState ( 'lineBreaks' , LineBreaksType . IS_PRE_WRAP ) ) ;
2534 dispatch ( setModalStates ( ModalEnum . CONFIGURATION , { open : true } ) ) ;
26-
35+ localStorage . setItem ( 'lineBreaks' , JSON . stringify ( LineBreaksType . IS_PRE_WRAP ) ) ;
2736 }
28- }
37+ } , [ configuration ] ) ;
38+
2939
30- function toggleLineBreaksPreWrap ( ) {
40+ const toggleLineBreaksPreWrap = useCallback ( ( ) => {
3141 if ( configuration . lineBreaks === LineBreaksType . IS_PRE_WRAP ) {
3242 dispatch ( updateConfigurationState ( 'lineBreaks' , LineBreaksType . IS_PRE_LINE ) ) ;
3343 dispatch ( setModalStates ( ModalEnum . CONFIGURATION , { open : true } ) ) ;
44+ localStorage . setItem ( 'lineBreaks' , JSON . stringify ( LineBreaksType . IS_PRE_LINE ) ) ;
3445
3546 } else if ( configuration . lineBreaks === LineBreaksType . IS_PRE_LINE ) {
3647 dispatch ( updateConfigurationState ( 'lineBreaks' , LineBreaksType . IS_PRE_WRAP ) ) ;
3748 dispatch ( setModalStates ( ModalEnum . CONFIGURATION , { open : true } ) ) ;
38-
49+ localStorage . setItem ( 'lineBreaks' , JSON . stringify ( LineBreaksType . IS_PRE_WRAP ) ) ;
3950 }
40- }
51+ } , [ configuration ] ) ;
52+
4153
42- function toggleSeparator ( ) {
54+ const toggleSeparator = useCallback ( ( ) => {
4355 if ( configuration . separator === ',' ) {
4456 dispatch ( updateConfigurationState ( 'separator' , '-' ) ) ;
4557 dispatch ( setModalStates ( ModalEnum . CONFIGURATION , { open : true } ) ) ;
4658
4759 } else {
4860 dispatch ( updateConfigurationState ( 'separator' , ',' ) ) ;
4961 dispatch ( setModalStates ( ModalEnum . CONFIGURATION , { open : true } ) ) ;
50-
5162 }
52- }
63+ } , [ configuration ] ) ;
5364
5465 return ( < Modal modalName = { ModalEnum . CONFIGURATION } >
5566 < div className = "flex flex-grow justify-center text-lg leading-6 text-gray-900 font-medium" > View configuration </ div >
0 commit comments