From 5242d300cb68f68a8ed3ddc2074ce486440b4cf4 Mon Sep 17 00:00:00 2001 From: Pedro Bonamin Date: Tue, 5 Sep 2023 11:35:23 +0200 Subject: [PATCH] feat(titles): Adds controlsDocumentTitle property to Tool --- packages/sanity/src/core/config/types.ts | 5 +++++ packages/sanity/src/core/studio/StudioLayout.tsx | 6 +++--- packages/sanity/src/desk/deskTool.ts | 2 ++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/sanity/src/core/config/types.ts b/packages/sanity/src/core/config/types.ts index adcb9bb78da0..cf20a86f5b47 100644 --- a/packages/sanity/src/core/config/types.ts +++ b/packages/sanity/src/core/config/types.ts @@ -141,6 +141,11 @@ export interface Tool { */ title: string + /** + * Determines whether the tool will control the document title. + */ + controlsDocumentTitle?: boolean + /** * Gets the state for the given intent. * diff --git a/packages/sanity/src/core/studio/StudioLayout.tsx b/packages/sanity/src/core/studio/StudioLayout.tsx index 4b3855f0f7ba..3266ad4f9962 100644 --- a/packages/sanity/src/core/studio/StudioLayout.tsx +++ b/packages/sanity/src/core/studio/StudioLayout.tsx @@ -89,14 +89,14 @@ export function StudioLayout() { return mainTitle }, [activeToolName, name, title]) + const toolControlsDocumentTitle = !!activeTool?.controlsDocumentTitle useEffect(() => { - if (activeToolName === 'content') { - // Will be handled by sanity/src/desk/components/deskTool/DeskTitle.tsx + if (toolControlsDocumentTitle) { return } document.title = documentTitle - }, [documentTitle, activeToolName]) + }, [documentTitle, toolControlsDocumentTitle]) const handleSearchFullscreenOpenChange = useCallback((open: boolean) => { setSearchFullscreenOpen(open) diff --git a/packages/sanity/src/desk/deskTool.ts b/packages/sanity/src/desk/deskTool.ts index 8ae9a53e33b3..896451f37dbd 100644 --- a/packages/sanity/src/desk/deskTool.ts +++ b/packages/sanity/src/desk/deskTool.ts @@ -107,6 +107,8 @@ export const deskTool = definePlugin((options) => ({ (intent === 'create' && params.template), ) }, + // Controlled by sanity/src/desk/components/deskTool/DeskTitle.tsx + controlsDocumentTitle: true, getIntentState, options, router,