Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(projects): refactor preview panel to prevent nested preview nesting (#3460)
teoeb40217eceaa
diff --git a/js/app/packages/app/component/PreviewPanel.tsx b/js/app/packages/app/component/PreviewPanel.tsxindex ddef1641ca..cee334fbe3 100644--- a/js/app/packages/app/component/PreviewPanel.tsx+++ b/js/app/packages/app/component/PreviewPanel.tsx@@ -50,7 +50,10 @@ const PreviewPanelContent: Component<NonNullableFields<PreviewPanel>> = (scopedLayoutRefs.headerRight = undefined;if (props.selectedEntity.type === 'project') {- const [previewState, setPreviewState] = createSignal(true);+ // Isolate the previewed project's preview state from the outer panel so+ // the nested SoupView's sync effect doesn't clobber the parent. Preview+ // can only work one level deep, so we never enable preview inside.+ const [previewState, setPreviewState] = createSignal(false);scopedSplitPanelContextType.previewState = [previewState, setPreviewState];}diff --git a/js/app/packages/block-project/component/Block.tsx b/js/app/packages/block-project/component/Block.tsxindex f054a6ce5e..36fdc60fff 100644--- a/js/app/packages/block-project/component/Block.tsx+++ b/js/app/packages/block-project/component/Block.tsx@@ -1,3 +1,4 @@+import { useAnalytics } from '@app/component/analytics-context';import { useBlockEntityCommands } from '@app/component/next-soup/actions';import {createSoupState,@@ -93,9 +94,21 @@ const Block: Component = () => {const previewPanel = useMaybePreviewPanel();const splitPanelContext = useSplitPanelOrThrow();+ const analytics = useAnalytics();- const [preview, setPreview] = splitPanelContext.previewState;+ const projectSoup = createSoupState({+ initialPredicates: { and: ['project-content'] },+ predicateConfigs: [+ {+ id: 'project-content',+ predicate: (entity: { type: string }) =>+ PROJECT_ENTITY_TYPES.includes(entity.type),+ },+ ],+ });+ // Preview can only work one level deep — don't register the toggle when+ // this project is already being rendered inside a preview panel.if (!previewPanel) {registerHotkey({hotkey: ['space'],@@ -103,24 +116,20 @@ const Block: Component = () => {description: 'Toggle Preview',hotkeyToken: TOKENS.unifiedList.togglePreview,keyDownHandler: () => {- setPreview((prev) => !prev);+ if (projectSoup.previewEntity()) {+ projectSoup.setPreviewEntity(undefined);+ return true;+ }+ const focused = projectSoup.focus.id();+ if (!focused) return true;+ analytics.track('preview_panel_use');+ projectSoup.setPreviewEntity(focused);return true;},hide: true,});}- const projectSoup = createSoupState({- initialPredicates: { and: ['project-content'] },- predicateConfigs: [- {- id: 'project-content',- predicate: (entity: { type: string }) =>- PROJECT_ENTITY_TYPES.includes(entity.type),- },- ],- });-const [attachHotkeys, projectViewScope] = useHotkeyDOMScope('project-view');return (@@ -157,7 +166,9 @@ const Block: Component = () => {value={{...splitPanelContext,halfSplitState: () =>- preview() ? { side: 'left', percentage: 30 } : undefined,+ projectSoup.previewEntity() && projectSoup.focus.item()+ ? { side: 'left', percentage: 30 }+ : undefined,}}><ProjectEntityList