* chore: return workspace name and logo in profile settings api * chore: remove unwanted fields * fix: backend * feat: workspace settings * feat: workspce settings + layouting * feat: profile + workspace settings ui * chore: project settings + refactoring * routes * fix: handled no project * fix: css + build * feat: profile settings internal screens upgrade * fix: workspace settings internal screens * fix: external scrolling allowed * fix: css * fix: css * fix: css * fix: preferences settings * fix: css * fix: mobile interface * fix: profile redirections * fix: dark theme * fix: css * fix: css * feat: scroll * fix: refactor * fix: bug fixes * fix: refactor * fix: css * fix: routes * fix: first day of the week * fix: scrolling * fix: refactoring * fix: project -> projects * fix: refactoring * fix: refactor * fix: no authorized view consistency * fix: folder structure * fix: revert * fix: handled redirections * fix: scroll * fix: deleted old routes * fix: empty states * fix: headings * fix: settings description * fix: build --------- Co-authored-by: gakshita <akshitagoyal1516@gmail.com> Co-authored-by: Akshita Goyal <36129505+gakshita@users.noreply.github.com>
46 lines
1.5 KiB
TypeScript
46 lines
1.5 KiB
TypeScript
import { useEffect, useRef } from "react";
|
|
import throttle from "lodash/throttle";
|
|
import { observer } from "mobx-react";
|
|
import { useUserSettings } from "@/hooks/store";
|
|
|
|
export const SettingsContentLayout = observer(({ children }: { children: React.ReactNode }) => {
|
|
// refs
|
|
const ref = useRef<HTMLDivElement>(null);
|
|
const scrolledRef = useRef(false);
|
|
// store hooks
|
|
const { toggleIsScrolled, isScrolled } = useUserSettings();
|
|
|
|
useEffect(() => {
|
|
toggleIsScrolled(false);
|
|
const container = ref.current;
|
|
if (!container) return;
|
|
|
|
const handleScroll = () => {
|
|
const scrollTop = container.scrollTop;
|
|
if (container.scrollHeight > container.clientHeight || scrolledRef.current) {
|
|
const _isScrolled = scrollTop > 0;
|
|
toggleIsScrolled(_isScrolled);
|
|
}
|
|
};
|
|
|
|
// Throttle the scroll handler to improve performance
|
|
// Set trailing to true to ensure the last call runs after the delay
|
|
const throttledHandleScroll = throttle(handleScroll, 150);
|
|
|
|
container.addEventListener("scroll", throttledHandleScroll);
|
|
return () => {
|
|
container.removeEventListener("scroll", throttledHandleScroll);
|
|
// Cancel any pending throttled invocations when unmounting
|
|
throttledHandleScroll.cancel();
|
|
};
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
scrolledRef.current = isScrolled;
|
|
}, [isScrolled]);
|
|
return (
|
|
<div className="w-full h-full min-h-full overflow-y-scroll " ref={ref}>
|
|
{children}
|
|
</div>
|
|
);
|
|
});
|