Skip to content

Commit 55b7d08

Browse files
committed
Add save function for settings
1 parent 4d87ca3 commit 55b7d08

File tree

5 files changed

+82
-56
lines changed

5 files changed

+82
-56
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "c13n-arc",
3-
"homepage": "https://c13n-io.github.io/arc/",
3+
"homepage": "./",
44
"version": "0.0.2",
55
"private": true,
66
"dependencies": {

src/components/content-pages/chat-history.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ const ChatHistory = (props) => {
808808
<p className="chat-history-feeModal-text">Received by you</p>
809809
<Button
810810
className="chat-history-feeModal-button"
811-
type="default"
811+
type="secondary"
812812
onClick={() => {
813813
setRawMessageInfoModalVisible(true);
814814
}}

src/components/content-pages/user-settings.js

Lines changed: 23 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
import React, { useState } from "react";
22
import { Button, Form, Divider, Switch, Select, Collapse } from "antd";
3-
import { LogoutOutlined } from "@ant-design/icons";
43
import { GithubPicker } from "react-color";
54
import "./user-settings.css";
65
import theme from "../../style/theme";
76
import { 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+
920
const 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>

src/payload-protocol/parsers.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,11 @@ import c13nLinkRef from "../components/content-pages/markdown/c13n-link-ref";
66
import c13nText from "../components/content-pages/markdown/c13n-text";
77
import c13nInlineCode from "../components/content-pages/markdown/c13n-inline-code";
88

9-
import ChatHistoryImage from "../components/content-pages/chat-history-image";
10-
119
import { issuePayreq, checkPayreq, satisfyPayreq } from "../utils/payreq/payreq-tracker";
1210

1311
import { Button, List } from "antd";
1412
import { CheckOutlined } from "@ant-design/icons";
1513

16-
import { downloadImage, cachedImages } from "../utils/lsat/download-image";
1714
import React from "react";
1815
import { sendPayreqPay } from "../utils/payreq/utils";
1916

src/utils/settings.js

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,21 @@ const loadAutomaticImageLoadingSetting = (setAutomaticImageLoading) => {
33
setAutomaticImageLoading(res !== 'false');
44
};
55

6+
const saveAutomaticImageLoadingSetting = (setAutomaticImageLoading, value) => {
7+
window.localStorage.setItem('automaticImageLoadingSetting', value);
8+
setAutomaticImageLoading(value);
9+
};
10+
611
const loadSmoothAnimationsSetting = (setSmoothAnimations) => {
712
let res = window.localStorage.getItem('smoothAnimationsSetting');
813
setSmoothAnimations(res !== 'false');
914
};
1015

16+
const saveSmoothAnimationsSetting = (setSmoothAnimations, value) => {
17+
window.localStorage.setItem('smoothAnimationsSetting', value);
18+
setSmoothAnimations(value);
19+
};
20+
1121
const loadSelectedCryptoUnit = (setSelectedCryptoUnit) => {
1222
let res = window.localStorage.getItem('selectedCryptoUnitSetting');
1323
if (res === 'sat' || res === 'msat' || res === 'mBTC') {
@@ -17,6 +27,11 @@ const loadSelectedCryptoUnit = (setSelectedCryptoUnit) => {
1727
}
1828
};
1929

30+
const saveSelectedCryptoUnit = (setSelectedCryptoUnit, value) => {
31+
window.localStorage.setItem('selectedCryptoUnitSetting', value);
32+
setSelectedCryptoUnit(value);
33+
};
34+
2035
const loadSelectedFiatUnit = (setSelectedFiatUnit) => {
2136
let res = window.localStorage.getItem('selectedFiatUnitSetting');
2237
if (res === 'EUR' || res === 'USD') {
@@ -26,11 +41,21 @@ const loadSelectedFiatUnit = (setSelectedFiatUnit) => {
2641
}
2742
};
2843

44+
const saveSelectedFiatUnit = (setSelectedFiatUnit, value) => {
45+
window.localStorage.setItem('selectedFiatUnitSetting', value);
46+
setSelectedFiatUnit(value);
47+
};
48+
2949
const loadChatIdenticonsSetting = (setChatIdenticons) => {
3050
let res = window.localStorage.getItem('chatIdenticonsSetting');
3151
setChatIdenticons(res !== 'false');
3252
};
3353

54+
const saveChatIdenticonsSetting = (setChatIdenticons, value) => {
55+
window.localStorage.setItem('chatIdenticonsSetting', value);
56+
setChatIdenticons(value);
57+
};
58+
3459
const loadChatLayoutSetting = (setChatLayout) => {
3560
let res = window.localStorage.getItem('chatLayoutSetting');
3661
if (res === 'normal' || res === 'left' || res === 'right') {
@@ -40,6 +65,11 @@ const loadChatLayoutSetting = (setChatLayout) => {
4065
}
4166
};
4267

68+
const saveChatLayoutSetting = (setChatLayout, value) => {
69+
window.localStorage.setItem('chatLayoutSetting', value);
70+
setChatLayout(value);
71+
};
72+
4373
const loadMyMessageColor = (setMyMessageColor) => {
4474
let res = window.localStorage.getItem('myMessageColorSetting');
4575
if(res !== 'undefined' && res !== undefined && res !== null) {
@@ -49,6 +79,11 @@ const loadMyMessageColor = (setMyMessageColor) => {
4979
}
5080
};
5181

82+
const saveMyMessageColor = (setMyMessageColor, value) => {
83+
window.localStorage.setItem('myMessageColorSetting', value);
84+
setMyMessageColor(value);
85+
};
86+
5287
const loadOtherMessageColor = (setOtherMessageColor) => {
5388
let res = window.localStorage.getItem('otherMessageColorSetting');
5489
if(res !== 'undefined' && res !== undefined && res !== null) {
@@ -58,6 +93,11 @@ const loadOtherMessageColor = (setOtherMessageColor) => {
5893
}
5994
};
6095

96+
const saveOtherMessageColor = (setOtherMessageColor, value) => {
97+
window.localStorage.setItem('otherMessageColorSetting', value);
98+
setOtherMessageColor(value);
99+
};
100+
61101
const loadDeveloperLogsSetting = (setDeveloperLogs) => {
62102
let res = window.localStorage.getItem('developerLogsSetting');
63103
setDeveloperLogs(res === 'true');
@@ -67,6 +107,13 @@ const loadDeveloperLogsSetting = (setDeveloperLogs) => {
67107
}
68108
};
69109

110+
const saveDeveloperLogsSetting = (setDeveloperLogs, value) => {
111+
window.localStorage.setItem('developerLogsSetting', value);
112+
setDeveloperLogs(value);
113+
};
114+
115+
116+
70117
export {
71118
loadAutomaticImageLoadingSetting,
72119
loadSmoothAnimationsSetting,
@@ -76,5 +123,14 @@ export {
76123
loadChatLayoutSetting,
77124
loadMyMessageColor,
78125
loadOtherMessageColor,
79-
loadDeveloperLogsSetting
126+
loadDeveloperLogsSetting,
127+
saveAutomaticImageLoadingSetting,
128+
saveSmoothAnimationsSetting,
129+
saveSelectedCryptoUnit,
130+
saveSelectedFiatUnit,
131+
saveChatIdenticonsSetting,
132+
saveChatLayoutSetting,
133+
saveMyMessageColor,
134+
saveOtherMessageColor,
135+
saveDeveloperLogsSetting
80136
};

0 commit comments

Comments
 (0)