11import React , { useState } from "react" ;
22import { Button , Form , Divider , Switch , Select , Collapse } from "antd" ;
3- import { LogoutOutlined } from "@ant-design/icons" ;
43import { GithubPicker } from "react-color" ;
54import "./user-settings.css" ;
65import theme from "../../style/theme" ;
76import { DoubleRightOutlined } from "@ant-design/icons" ;
87
8+ import {
9+ saveAutomaticImageLoadingSetting ,
10+ saveSmoothAnimationsSetting ,
11+ saveSelectedCryptoUnit ,
12+ saveSelectedFiatUnit ,
13+ saveChatIdenticonsSetting ,
14+ saveChatLayoutSetting ,
15+ saveMyMessageColor ,
16+ saveOtherMessageColor ,
17+ saveDeveloperLogsSetting ,
18+ } from "../../utils/settings" ;
19+
920const messageColorsArray = [
1021 "black" ,
1122 "darkslategray" ,
@@ -69,11 +80,7 @@ const UserSettings = (props) => {
6980 checked = { ! ! props . automaticImageLoading }
7081 className = "user-settings-collapse"
7182 onChange = { ( value ) => {
72- props . setAutomaticImageLoading ( value ) ;
73- window . localStorage . setItem (
74- "automaticImageLoadingSetting" ,
75- value
76- ) ;
83+ saveAutomaticImageLoadingSetting ( props . setAutomaticImageLoading , value ) ;
7784 } }
7885 />
7986 Allow automatic loading of externally linked images
@@ -83,11 +90,7 @@ const UserSettings = (props) => {
8390 checked = { ! ! props . smoothAnimations }
8491 className = "user-settings-collapse"
8592 onChange = { ( value ) => {
86- props . setSmoothAnimations ( value ) ;
87- window . localStorage . setItem (
88- "smoothAnimationsSetting" ,
89- value
90- ) ;
93+ saveSmoothAnimationsSetting ( props . setSmoothAnimations , value ) ;
9194 } }
9295 />
9396 Enable smooth animations and transitions
@@ -97,11 +100,7 @@ const UserSettings = (props) => {
97100 checked = { ! ! props . chatIdenticons }
98101 className = "user-settings-collapse"
99102 onChange = { ( value ) => {
100- props . setChatIdenticons ( value ) ;
101- window . localStorage . setItem (
102- "chatIdenticonsSetting" ,
103- value
104- ) ;
103+ saveChatIdenticonsSetting ( props . setChatIdenticons , value ) ;
105104 } }
106105 />
107106 Show user icons in chat messages
@@ -111,8 +110,7 @@ const UserSettings = (props) => {
111110 defaultValue = { `${ props . chatLayout } ` }
112111 className = "user-settings-formSelect"
113112 onChange = { ( e ) => {
114- props . setChatLayout ( e ) ;
115- window . localStorage . setItem ( "chatLayoutSetting" , e ) ;
113+ saveChatLayoutSetting ( props . setChatLayout , e ) ;
116114 } }
117115 >
118116 < Select . Option value = "normal" > Normal</ Select . Option >
@@ -129,20 +127,12 @@ const UserSettings = (props) => {
129127 colors = { messageColorsArray }
130128 color = { props . myMessageColor }
131129 onChangeComplete = { ( color ) => {
132- props . setMyMessageColor ( color . hex ) ;
133- window . localStorage . setItem (
134- "myMessageColorSetting" ,
135- color . hex
136- ) ;
130+ saveMyMessageColor ( props . setMyMessageColor , color . hex ) ;
137131 } }
138132 />
139133 < Button
140134 onClick = { ( ) => {
141- props . setMyMessageColor ( "rgba(0, 0, 0, 0.0)" ) ;
142- window . localStorage . setItem (
143- "myMessageColorSetting" ,
144- "rgba(0, 0, 0, 0.0)"
145- ) ;
135+ saveMyMessageColor ( props . setMyMessageColor , "rgba(0, 0, 0, 0.0)" ) ;
146136 } }
147137 >
148138 Transparent
@@ -156,20 +146,12 @@ const UserSettings = (props) => {
156146 colors = { messageColorsArray }
157147 color = { props . myMessageColor }
158148 onChangeComplete = { ( color ) => {
159- props . setOtherMessageColor ( color . hex ) ;
160- window . localStorage . setItem (
161- "otherMessageColorSetting" ,
162- color . hex
163- ) ;
149+ saveOtherMessageColor ( props . setOtherMessageColor , color . hex ) ;
164150 } }
165151 />
166152 < Button
167153 onClick = { ( ) => {
168- props . setOtherMessageColor ( "rgba(0, 0, 0, 0.0)" ) ;
169- window . localStorage . setItem (
170- "otherMessageColorSetting" ,
171- "rgba(0, 0, 0, 0.0)"
172- ) ;
154+ saveOtherMessageColor ( props . setOtherMessageColor , "rgba(0, 0, 0, 0.0)" ) ;
173155 } }
174156 >
175157 Transparent
@@ -180,11 +162,7 @@ const UserSettings = (props) => {
180162 checked = { ! ! props . developerLogs }
181163 className = "user-settings-collapse"
182164 onChange = { ( value ) => {
183- props . setDeveloperLogs ( value ) ;
184- window . localStorage . setItem (
185- "developerLogsSetting" ,
186- value
187- ) ;
165+ saveDeveloperLogsSetting ( props . setDeveloperLogs , value ) ;
188166 } }
189167 />
190168 Developer Logs (Page refresh required)
@@ -196,11 +174,7 @@ const UserSettings = (props) => {
196174 defaultValue = { `${ props . selectedCryptoUnit } ` }
197175 className = "user-settings-formSelect"
198176 onChange = { ( e ) => {
199- props . setSelectedCryptoUnit ( e ) ;
200- window . localStorage . setItem (
201- "selectedCryptoUnitSetting" ,
202- e
203- ) ;
177+ saveSelectedCryptoUnit ( props . setSelectedCryptoUnit , e ) ;
204178 } }
205179 >
206180 < Select . Option value = "mBTC" > mBTC</ Select . Option >
@@ -214,8 +188,7 @@ const UserSettings = (props) => {
214188 defaultValue = { `${ props . selectedFiatUnit } ` }
215189 className = "user-settings-formSelect"
216190 onChange = { ( e ) => {
217- props . setSelectedFiatUnit ( e ) ;
218- window . localStorage . setItem ( "selectedFiatUnitSetting" , e ) ;
191+ setSelectedFiatUnit ( props . setSelectedFiatUnit , e ) ;
219192 } }
220193 >
221194 < Select . Option value = "EUR" > EUR</ Select . Option >
0 commit comments