MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / useBlockHandlers

Function useBlockHandlers

packages/studio/src/hooks/useBlockHandlers.ts:52–150  ·  view source on GitHub ↗
({
  projectId,
  blockCtxDeps,
  previewIframeRef,
  setRightCollapsed,
  setRightPanelTab,
}: UseBlockHandlersParams)

Source from the content-addressed store, hash-verified

50}
51
52export function useBlockHandlers({
53 projectId,
54 blockCtxDeps,
55 previewIframeRef,
56 setRightCollapsed,
57 setRightPanelTab,
58}: UseBlockHandlersParams): UseBlockHandlersResult {
59 const [activeBlockParams, setActiveBlockParams] =
60 useState<UseBlockHandlersResult["activeBlockParams"]>(null);
61
62 const blockCtx = useMemo(
63 () => ({
64 activeCompPath: blockCtxDeps.activeCompPath,
65 timelineElements: blockCtxDeps.timelineElements,
66 readProjectFile: blockCtxDeps.readProjectFile,
67 writeProjectFile: blockCtxDeps.writeProjectFile,
68 recordEdit: blockCtxDeps.recordEdit,
69 refreshFileTree: blockCtxDeps.refreshFileTree,
70 reloadPreview: blockCtxDeps.reloadPreview,
71 showToast: blockCtxDeps.showToast,
72 }),
73 // eslint-disable-next-line react-hooks/exhaustive-deps
74 [
75 blockCtxDeps.activeCompPath,
76 blockCtxDeps.timelineElements,
77 blockCtxDeps.readProjectFile,
78 blockCtxDeps.writeProjectFile,
79 blockCtxDeps.recordEdit,
80 blockCtxDeps.refreshFileTree,
81 blockCtxDeps.reloadPreview,
82 blockCtxDeps.showToast,
83 ],
84 );
85
86 const handleAddBlock = useCallback(
87 (blockName: string) => {
88 if (!projectId) return;
89 void (async () => {
90 const result = await addBlockToProject({
91 projectId,
92 blockName,
93 ...blockCtx,
94 previewIframe: previewIframeRef.current,
95 currentTime: usePlayerStore.getState().currentTime,
96 });
97 const params = result?.block.type === "hyperframes:block" ? result.block.params : undefined;
98 if (params?.length) {
99 setActiveBlockParams({
100 blockName: result!.block.name,
101 blockTitle: result!.block.title,
102 params,
103 compositionPath: result!.compositionPath,
104 });
105 setRightCollapsed(false);
106 setRightPanelTab("block-params");
107 }
108 })();
109 },

Callers 1

StudioAppFunction · 0.90

Calls 1

addBlockToProjectFunction · 0.90

Tested by

no test coverage detected