Skip to content

Commit

Permalink
refactor(core): move NavbarContext to singletons
Browse files Browse the repository at this point in the history
  • Loading branch information
binoy14 committed Apr 29, 2024
1 parent 96e1bb7 commit 2601315
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
1 change: 1 addition & 0 deletions packages/sanity/src/_singletons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ export * from './presence/FormFieldPresenceContext'
export * from './store/_legacy/ResourceCacheContext'
export * from './studio/ColorSchemeSetValueContext'
export * from './studio/ColorSchemeValueContext'
export * from './studio/NavbarContext'
export * from './studio/SourceContext'
export * from './studio/WorkspaceContext'
11 changes: 11 additions & 0 deletions packages/sanity/src/_singletons/studio/NavbarContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {createContext} from 'react'
import type {NavbarContextValue} from 'sanity'

/** @internal */
export const NavbarContext = createContext<NavbarContextValue>({
onSearchFullscreenOpenChange: () => '',
onSearchOpenChange: () => '',
searchFullscreenOpen: false,
searchFullscreenPortalEl: null,
searchOpen: false,
})
12 changes: 2 additions & 10 deletions packages/sanity/src/core/studio/StudioLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable i18next/no-literal-string, @sanity/i18n/no-attribute-template-literals */
import {Card, Flex} from '@sanity/ui'
import {startCase} from 'lodash'
import {createContext, Suspense, useCallback, useEffect, useMemo, useState} from 'react'
import {Suspense, useCallback, useEffect, useMemo, useState} from 'react'
import {NavbarContext} from 'sanity/_singletons'
import {RouteScope, useRouter, useRouterState} from 'sanity/router'
import {styled} from 'styled-components'

Expand Down Expand Up @@ -37,15 +38,6 @@ export interface NavbarContextValue {
searchOpen: boolean
}

/** @internal */
export const NavbarContext = createContext<NavbarContextValue>({
onSearchFullscreenOpenChange: () => '',
onSearchOpenChange: () => '',
searchFullscreenOpen: false,
searchFullscreenPortalEl: null,
searchOpen: false,
})

/**
* The Studio Layout component is the root component of the Sanity Studio UI.
* It renders the navbar, the active tool, and the search modal as well as the error boundary.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
useMediaIndex,
} from '@sanity/ui'
import {useCallback, useContext, useEffect, useMemo, useRef, useState} from 'react'
import {NavbarContext} from 'sanity/_singletons'
import {type RouterState, useRouterState} from 'sanity/router'
import {styled} from 'styled-components'

Expand All @@ -19,7 +20,6 @@ import {type NavbarProps} from '../../../config/studio/types'
import {isDev} from '../../../environment'
import {useTranslation} from '../../../i18n'
import {useToolMenuComponent} from '../../studio-components-hooks'
import {NavbarContext} from '../../StudioLayout'
import {useWorkspace} from '../../workspace'
import {ConfigIssuesButton} from './configIssues/ConfigIssuesButton'
import {FreeTrial} from './free-trial'
Expand Down

0 comments on commit 2601315

Please sign in to comment.