Your SaaS
@@ -93,18 +99,21 @@ function NavBarDesktopUserDropdown({ isScrolled }: { isScrolled: boolean }) {
{isUserLoading ? null : !user ? (
Log in{' '}
@@ -140,9 +149,9 @@ function NavBarMobileMenu({
>
Open main menu
@@ -213,9 +222,9 @@ function renderNavigationItems(
const NavLogo = ({ isScrolled }: { isScrolled: boolean }) => (
void,
- delayInMilliseconds: number
-): ((...args: any[]) => void) & { cancel: () => void } {
- let fnLastCallTime: number | null = null;
- let trailingInvocationTimeoutId: ReturnType | null = null;
- let isTrailingInvocationPending = false;
-
- const callFn = () => {
- fnLastCallTime = Date.now();
- fn();
- };
-
- const throttledFn = () => {
- const currentTime = Date.now();
- const timeSinceLastExecution = fnLastCallTime ? currentTime - fnLastCallTime : 0;
-
- const shouldCallImmediately = fnLastCallTime === null || timeSinceLastExecution >= delayInMilliseconds;
-
- if (shouldCallImmediately) {
- callFn();
- return;
- }
-
- if (!isTrailingInvocationPending) {
- isTrailingInvocationPending = true;
- const remainingDelayTime = Math.max(delayInMilliseconds - timeSinceLastExecution, 0);
-
- trailingInvocationTimeoutId = setTimeout(() => {
- callFn();
- isTrailingInvocationPending = false;
- }, remainingDelayTime);
- }
- };
-
- throttledFn.cancel = () => {
- if (trailingInvocationTimeoutId) {
- clearTimeout(trailingInvocationTimeoutId);
- trailingInvocationTimeoutId = null;
- }
- isTrailingInvocationPending = false;
- };
-
- return throttledFn as typeof throttledFn & { cancel: () => void };
-}