1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
import * as Uebersicht from "uebersicht";
import * as Icons from "../icons/icons.jsx";
import * as Utils from "../../utils";
import * as Settings from "../../settings";
import SettingsInner from "./settings-inner.jsx";
const { React } = Uebersicht;
const settingsKeys = {
batteryWidget: "batteryWidgetOptions",
browserTrackWidget: "browserTrackWidgetOptions",
cpuWidget: "cpuWidgetOptions",
cryptoWidget: "cryptoWidgetOptions",
dateWidget: "dateWidgetOptions",
gpuWidget: "gpuWidgetOptions",
memoryWidget: "memoryWidgetOptions",
keyboardWidget: "keyboardWidgetOptions",
micWidget: "micWidgetOptions",
mpdWidget: "mpdWidgetOptions",
musicWidget: "musicWidgetOptions",
netstatsWidget: "netstatsWidgetOptions",
nextMeetingWidget: "nextMeetingWidgetOptions",
notificationsWidget: "notificationsWidgetOptions",
soundWidget: "soundWidgetOptions",
spotifyWidget: "spotifyWidgetOptions",
stockWidget: "stockWidgetOptions",
timeWidget: "timeWidgetOptions",
vpnWidget: "vpnWidgetOptions",
githubWidget: "githubWidgetOptions",
weatherWidget: "weatherWidgetOptions",
wifiWidget: "networkWidgetOptions",
youtubeMusicWidget: "youtubeMusicWidgetOptions",
zoomWidget: "zoomWidgetOptions",
userWidgets: "userWidgets",
};
/**
* SettingsWidgets component to render widgets setting category.
* @param {Object} props - Component properties.
* @param {Object} props.newSettings - Object containing current modified settings.
* @param {Function} props.setNewSettings - Function allowing to save newly modified settings.
*/
export default function SettingsWidgets({ newSettings, setNewSettings }) {
const [currentWidget, setCurrentWidget] = React.useState(null);
const currentSetting = Settings.data[currentWidget];
/**
* Removes the current widget setting,
*/
const removeCurrentWidget = () => {
setCurrentWidget(null);
};
/**
* Prevent checkbox click from propagating to the parent element,
* allowing to avoid triggering the widget selection.
*/
const handleCheckboxClick = (e) => {
e.stopPropagation();
Utils.clickEffect(e);
};
/**
* Updates the current widget based on the clicked element.
* @param {string} widget - The key of the widget to update.
*/
const updateCurrentWidget = (widget) => (e) => {
if (widget === "processWidget") return;
Utils.clickEffect(e);
const widgetKey = settingsKeys[widget];
setCurrentWidget(currentWidget === widgetKey ? null : widgetKey);
};
return (
<div className="settings__widgets">
<Breadcrumb
currentSetting={currentSetting}
removeCurrentWidget={removeCurrentWidget}
/>
{!currentWidget ? (
<div className="settings__widgets-list">
<div
className="settings__widgets-item"
onClick={updateCurrentWidget("userWidgets")}
>
Custom widgets
<Icons.ChevronRight className="settings__widgets-item-icon" />
</div>
{Object.keys(Settings.defaultSettings.widgets).map((subKey) => {
const subSetting = Settings.data[subKey];
if (!subSetting) return null;
const { label } = subSetting;
const defaultValue = newSettings.widgets[subKey];
const isProcess = subKey === "processWidget";
const classes = Utils.classNames("settings__widgets-item", {
"settings__widgets-item--process": isProcess,
});
const onChange = (e) => {
const value = e.target.checked;
const updatedSettings = {
...newSettings,
widgets: { ...newSettings.widgets, [subKey]: value },
};
setNewSettings(updatedSettings);
};
return (
<div
key={subKey}
className={classes}
onClick={updateCurrentWidget(subKey)}
>
<input
type="checkbox"
defaultChecked={defaultValue}
onChange={onChange}
onClick={handleCheckboxClick}
/>
{label}
{!isProcess && (
<Icons.ChevronRight className="settings__widgets-item-icon" />
)}
</div>
);
})}
</div>
) : (
<div className="settings__widget-settings">
<SettingsInner
settingKey={currentWidget}
setting={currentSetting}
newSettings={newSettings}
setNewSettings={setNewSettings}
/>
</div>
)}
</div>
);
}
/**
* SettingsWidgets component to render widgets setting category.
* @param {Object} props - Component properties.
* @param {Object} props.currentSetting - Object containing the current setting.
* @param {Function} props.removeCurrentWidget - Function removing the current setting allowing to go back to widget list.
*/
function Breadcrumb({ currentSetting, removeCurrentWidget }) {
if (!currentSetting) {
return (
<div className="settings__widgets-breadcrumb">
<div className="settings__widgets-breadcrumb-title">Widgets</div>
</div>
);
}
const { label } = currentSetting;
return (
<div className="settings__widgets-breadcrumb">
<button
className="settings__widgets-breadcrumb-title"
onClick={removeCurrentWidget}
>
Widgets
</button>
<span className="settings__widgets-breadcrumb-current">
{">"} {label}
</span>
<button
className="settings__widgets-breadcrumb-back"
onClick={removeCurrentWidget}
>
<Icons.ChevronLeft className="settings__widgets-breadcrumb-back-icon" />
Back
</button>
</div>
);
}
|