Skip to content

Commit

Permalink
Add a timeout for useEffect to fix mobile marquee
Browse files Browse the repository at this point in the history
  • Loading branch information
skanderm committed Sep 26, 2023
1 parent 1d222ec commit 6483450
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 16 deletions.
2 changes: 1 addition & 1 deletion server/.formatter.exs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
:ash_json_api
],
subdirectories: ["priv/*/migrations"],
plugins: [Phoenix.LiveView.HTMLFormatter],
plugins: [Phoenix.LiveView.HTMLFormatter, Spark.Formatter],
inputs: ["*.{heex,ex,exs}", "{config,lib,test}/**/*.{heex,ex,exs}", "priv/*/seeds.exs"],
export: [locals_without_parens: [:plug, :uuid_attribute]]
]
20 changes: 20 additions & 0 deletions server/config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,26 @@ config :orcasite, Oban,
plugins: [{Oban.Plugins.Pruner, max_age: 7 * 24 * 60 * 60}],
queues: [default: 10, email: 10]

config :spark, :formatter,
remove_parens?: true,
"Ash.Resource": [
type: Ash.Resource,
section_order: [
:postgres,
:identities,
:attributes,
:calculations,
:relationships,
:authentication,
:token,
:policies,
:actions,
:admin,
:json_api,
:graphql
]
]

# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
import_config "#{config_env()}.exs"
45 changes: 30 additions & 15 deletions ui/src/utils/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,46 @@ export function useIsRelativeOverflow(
const { current: currentTarget } = targetRef;

const trigger = () => {
if (!currentContainer || !currentTarget) return;
const hasOverflow =
currentTarget.clientWidth > currentContainer.clientWidth;
setTimeout(() => {
if (!currentContainer || !currentTarget) return;
const hasOverflow =
currentTarget.clientWidth > currentContainer.clientWidth;

setIsOverflow(hasOverflow);
setIsOverflow(hasOverflow);

if (callback) callback(hasOverflow);
if (callback) callback(hasOverflow);
}, 100);
};

if (currentContainer && currentTarget) {
trigger();
}
}, [callback, containerRef, targetRef, size.width]);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
callback,
size.width,
containerRef,
targetRef,
containerRef.current,
targetRef.current,
]);

return isOverflow;
}

function useWindowSize(): {
height: number | undefined;
width: number | undefined;
} {
const isClient = typeof window === "object";

function useWindowSize(): { height: number | undefined; width: number | undefined } {
const isClient = typeof window === 'object';

function getSize(): { height: number | undefined; width: number | undefined } {
function getSize(): {
height: number | undefined;
width: number | undefined;
} {
return {
width: isClient ? window.innerWidth : undefined,
height: isClient ? window.innerHeight : undefined
height: isClient ? window.innerHeight : undefined,
};
}

Expand All @@ -53,11 +68,11 @@ function useWindowSize(): { height: number | undefined; width: number | undefine
setWindowSize(getSize());
}

window.addEventListener('resize', handleResize);
window.addEventListener("resize", handleResize);

return (): void => window.removeEventListener('resize', handleResize);
// eslint-disable-next-line react-hooks/exhaustive-deps
return (): void => window.removeEventListener("resize", handleResize);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []); // Empty array ensures that effect is only run on mount and unmount

return windowSize;
}
}

0 comments on commit 6483450

Please sign in to comment.