mirror of
https://github.com/outline/outline.git
synced 2026-11-25 07:04:37 +03:00
* Improve sidebar menu and navigation tree performance * remote some test and rollback useOnScreen * feat: introduce ActionFactory type and update context menu components to support it - Added ActionFactory type to allow functions returning ActionWithChildren. - Updated ContextMenu and DropdownMenu components to handle ActionFactory. - Modified DocumentRow, SidebarLink, and other components to accept ActionFactory for context actions. - Refactored useDocumentMenuAction to utilize createRootMenuAction for better action management. --------- Co-authored-by: Tom Moor <tom@getoutline.com>
30 lines
805 B
TypeScript
30 lines
805 B
TypeScript
import { isEqual } from "es-toolkit/compat";
|
|
import { useRef } from "react";
|
|
import { createRootMenuAction } from "~/actions";
|
|
import type {
|
|
ActionGroup,
|
|
ActionSeparator,
|
|
ActionVariant,
|
|
ActionWithChildren,
|
|
} from "~/types";
|
|
import usePrevious from "./usePrevious";
|
|
|
|
type Actions = (ActionVariant | ActionGroup | ActionSeparator)[];
|
|
|
|
export function useMenuAction(actions: Actions) {
|
|
const rootActionRef = useRef<ActionWithChildren>();
|
|
const prevActions = usePrevious(actions);
|
|
|
|
if (!rootActionRef.current) {
|
|
rootActionRef.current = createRootMenuAction(actions);
|
|
return rootActionRef.current;
|
|
}
|
|
|
|
if (!prevActions || isEqual(actions, prevActions)) {
|
|
return rootActionRef.current;
|
|
}
|
|
|
|
rootActionRef.current = createRootMenuAction(actions);
|
|
return rootActionRef.current;
|
|
}
|