Skip to content

Commit 53528c6

Browse files
committed
Coderabbit improvement for the deboucing
1 parent 1119bd1 commit 53528c6

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

apps/webapp/app/components/navigation/SideMenu.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,30 @@ export function SideMenu({
183183
[user.isImpersonating, preferencesFetcher]
184184
);
185185

186-
// Cleanup timeout on unmount
186+
// Flush pending preferences on unmount to avoid losing the last toggle
187187
useEffect(() => {
188188
return () => {
189189
if (debounceTimeoutRef.current) {
190190
clearTimeout(debounceTimeoutRef.current);
191191
}
192+
if (user.isImpersonating) return;
193+
const pending = pendingPreferencesRef.current;
194+
if (pending.isCollapsed !== undefined || pending.manageSectionCollapsed !== undefined) {
195+
const formData = new FormData();
196+
if (pending.isCollapsed !== undefined) {
197+
formData.append("isCollapsed", String(pending.isCollapsed));
198+
}
199+
if (pending.manageSectionCollapsed !== undefined) {
200+
formData.append("manageSectionCollapsed", String(pending.manageSectionCollapsed));
201+
}
202+
preferencesFetcher.submit(formData, {
203+
method: "POST",
204+
action: "/resources/preferences/sidemenu",
205+
});
206+
pendingPreferencesRef.current = {};
207+
}
192208
};
193-
}, []);
209+
}, [preferencesFetcher, user.isImpersonating]);
194210

195211
const handleToggleCollapsed = () => {
196212
const newIsCollapsed = !isCollapsed;

0 commit comments

Comments
 (0)