diff options
Diffstat (limited to 'apps/web/src/editor/use-menu-preview.ts')
| -rw-r--r-- | apps/web/src/editor/use-menu-preview.ts | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/apps/web/src/editor/use-menu-preview.ts b/apps/web/src/editor/use-menu-preview.ts new file mode 100644 index 00000000..ca42124e --- /dev/null +++ b/apps/web/src/editor/use-menu-preview.ts @@ -0,0 +1,26 @@ +import { useRef } from "react";
+import { useEditor } from "@/editor/use-editor";
+
+export function useMenuPreview() {
+ const editor = useEditor();
+ const didCommitRef = useRef(false);
+
+ const discard = () => {
+ if (!didCommitRef.current && editor.timeline.isPreviewActive()) {
+ editor.timeline.discardPreview();
+ }
+ };
+
+ const markCommitted = () => {
+ didCommitRef.current = true;
+ };
+
+ const onOpenChange = (isOpen: boolean) => {
+ if (!isOpen) {
+ discard();
+ didCommitRef.current = false;
+ }
+ };
+
+ return { onPointerLeave: discard, onOpenChange, markCommitted };
+}
|
