From aa58b2ac853860946d9ef9cc1b5d2daa1288fcde Mon Sep 17 00:00:00 2001 From: Apoorv Mishra Date: Thu, 22 Aug 2024 18:59:07 +0530 Subject: [PATCH] fix: fetch upon hover and display menu only when data is loaded --- app/components/ContextMenu/index.tsx | 19 +- app/menus/DocumentMenu.tsx | 303 +++++++++++++-------------- 2 files changed, 152 insertions(+), 170 deletions(-) diff --git a/app/components/ContextMenu/index.tsx b/app/components/ContextMenu/index.tsx index d88daaed24..ae77fc8b61 100644 --- a/app/components/ContextMenu/index.tsx +++ b/app/components/ContextMenu/index.tsx @@ -19,7 +19,6 @@ import { fadeAndSlideDown, mobileContextMenu, } from "~/styles/animations"; -import PlaceholderText from "../PlaceholderText"; export type Placement = | "auto-start" @@ -53,7 +52,6 @@ type Props = MenuStateReturn & { /** The maximum width of the context menu. */ maxWidth?: number; children?: React.ReactNode; - loading?: boolean; }; const ContextMenu: React.FC = ({ @@ -62,7 +60,6 @@ const ContextMenu: React.FC = ({ onOpen, onClose, parentMenuState, - loading, ...rest }: Props) => { const previousVisible = usePrevious(rest.visible); @@ -122,7 +119,6 @@ const ContextMenu: React.FC = ({ @@ -134,20 +130,11 @@ const ContextMenu: React.FC = ({ ); }; -const Loader: React.FC = () => ( - <> - - - - -); - type InnerContextMenuProps = MenuStateReturn & { isSubMenu: boolean; menuProps: { style?: React.CSSProperties; placement: string }; children: React.ReactNode; maxWidth?: number; - loading?: boolean; }; /** @@ -239,11 +226,7 @@ const InnerContextMenu = (props: InnerContextMenuProps) => { hiddenScrollbars style={style} > - {props.loading ? ( - - ) : props.visible || props.animating ? ( - props.children - ) : null} + {props.visible || props.animating ? props.children : null} diff --git a/app/menus/DocumentMenu.tsx b/app/menus/DocumentMenu.tsx index eb953802de..71f7448797 100644 --- a/app/menus/DocumentMenu.tsx +++ b/app/menus/DocumentMenu.tsx @@ -109,17 +109,12 @@ function DocumentMenu({ }) ); - React.useEffect(() => { - if ( - menu.visible && - isUndefined(data ?? error) && - !loading && - !documents.isFetching - ) { + const handleMouseEnter = React.useCallback(() => { + if (isUndefined(data ?? error) && !loading && !documents.isFetching) { void request(); void document.loadRelations(); } - }, [menu.visible, request, loading, data, error, document, documents]); + }, [data, error, loading, request, document, documents]); const handleRestore = React.useCallback( async ( @@ -217,160 +212,164 @@ function DocumentMenu({ {label ? ( - {label} + + {label} + ) : ( )} - -