Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,11 @@ export default function GeneralSection() {

const handleNotificationToggle = useCallback(
(key: 'taskComplete' | 'approvalRequest' | 'gatewayDisconnect', value: boolean) => {
setNotifyState((prev) => {
const next = { ...prev, [key]: value };
window.clawwork.updateSettings({ notifications: next });
return next;
});
const next = { ...notifyState, [key]: value };
setNotifyState(next);
window.clawwork.updateSettings({ notifications: next });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For consistency with other setting handlers in this component (e.g., handleThemeToggle at line 38 or handleDensityChange at line 46), consider adding a success toast after the settings are updated, and handle potential IPC errors to inform the user if the persistence fails.

},
[],
[notifyState],
Comment on lines +101 to +105
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Hoisting the IPC call out of the setNotifyState updater successfully prevents double-invocation in React Strict Mode. However, this implementation introduces a potential race condition because it relies on notifyState from the closure. If a user toggles multiple settings quickly, notifyState might be stale during the second click (before the first update's re-render), causing the first update to be overwritten in the final state.

To maintain state consistency while keeping the side effect out of the updater, consider using a useEffect hook to sync state to the backend, or use a ref to track the latest state value for the IPC call.

);

const notificationToggles = [
Expand Down