Skip to content

Commit c8678bc

Browse files
committed
refactor: simplify SettingsDialog state update logic
- Replaced the specific embedLockDebounceTime handler with a more generic updateSetting function to streamline state updates for various settings. - Removed unused styles from SettingsDialog.scss to enhance code clarity and maintainability.
1 parent 1c48b3a commit c8678bc

File tree

2 files changed

+9
-24
lines changed

2 files changed

+9
-24
lines changed

src/frontend/src/ui/SettingsDialog.scss

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
.settings-dialog {
2-
3-
.control-label {
4-
font-size: 0px;
5-
}
62

73
&__wrapper {
84
position: absolute;
@@ -34,15 +30,6 @@
3430
flex-direction: column;
3531
}
3632

37-
&__empty {
38-
display: flex;
39-
align-items: center;
40-
justify-content: center;
41-
height: 100%;
42-
color: #888;
43-
font-style: italic;
44-
}
45-
4633
&__section {
4734
margin-bottom: 1.5rem;
4835
}
@@ -72,11 +59,4 @@
7259
margin: 1rem 0;
7360
}
7461

75-
&__range-labels {
76-
display: flex;
77-
justify-content: space-between;
78-
font-size: 0.8rem;
79-
color: var(--text-primary-color);
80-
opacity: 0.7;
81-
}
8262
}

src/frontend/src/ui/SettingsDialog.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,17 @@ const SettingsDialog: React.FC<SettingsDialogProps> = ({
3535
}
3636
}, [onClose]);
3737

38-
const handleEmbedLockDebounceTimeChange = (value: number) => {
38+
/**
39+
* Updates a specific setting and syncs it with the excalidraw app state
40+
* @param key The setting key to update
41+
* @param value The new value for the setting
42+
*/
43+
const updateSetting = <K extends keyof UserSettings>(key: K, value: UserSettings[K]) => {
3944
if (!excalidrawAPI) return;
4045

4146
const newSettings = {
4247
...settings,
43-
embedLockDebounceTime: value
48+
[key]: value
4449
};
4550

4651
setSettings(newSettings);
@@ -72,14 +77,14 @@ const SettingsDialog: React.FC<SettingsDialogProps> = ({
7277
<div className="settings-dialog__range-container">
7378
<Range
7479
value={Math.round(((settings.embedLockDebounceTime || 350) - 150) / 4850 * 100)}
75-
onChange={(value) => handleEmbedLockDebounceTimeChange(
80+
onChange={(value) => updateSetting(
81+
'embedLockDebounceTime',
7682
// Map 0-100 range to 150-5000ms
7783
Math.round(150 + (value / 100) * 4850)
7884
)}
7985
min={0}
8086
max={100}
8187
step={1}
82-
label="Embed Lock Time"
8388
minLabel="150ms"
8489
maxLabel="5000ms"
8590
showValueBubble={false}

0 commit comments

Comments
 (0)