Skip to content

Commit

Permalink
refactor(core): move SearchContext to singletons
Browse files Browse the repository at this point in the history
  • Loading branch information
binoy14 committed Apr 29, 2024
1 parent 0f0d13f commit b4a8f3b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 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 @@ -31,6 +31,7 @@ export * from './studio/ColorSchemeSetValueContext'
export * from './studio/ColorSchemeValueContext'
export * from './studio/components/navbar/free-trial/FreeTrialContext'
export * from './studio/components/navbar/search/components/filters/filter/inputs/date/datePicker/calendar/CalendarContext'
export * from './studio/components/navbar/search/SearchContext'
export * from './studio/NavbarContext'
export * from './studio/SourceContext'
export * from './studio/WorkspaceContext'
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {createContext} from 'react'
import type {SearchContextValue} from 'sanity'

/**
* @internal
*/
export const SearchContext = createContext<SearchContextValue | undefined>(undefined)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {createContext, type Dispatch, type SetStateAction} from 'react'
import {type Dispatch, type SetStateAction} from 'react'

import {type CommandListHandle} from '../../../../../../components/commandList/types'
import {type SearchAction, type SearchReducerState} from './reducer'
Expand All @@ -14,8 +14,3 @@ export interface SearchContextValue {
setOnClose: (onClose: () => void) => void
state: SearchReducerState
}

/**
* @internal
*/
export const SearchContext = createContext<SearchContextValue | undefined>(undefined)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {isEqual} from 'lodash'
import {type ReactNode, useCallback, useEffect, useMemo, useReducer, useRef, useState} from 'react'
import {SearchContext} from 'sanity/_singletons'

import {type CommandListHandle} from '../../../../../../components'
import {useSchema} from '../../../../../../hooks'
Expand All @@ -17,7 +18,6 @@ import {validateFilter} from '../../utils/filterUtils'
import {hasSearchableTerms} from '../../utils/hasSearchableTerms'
import {isRecentSearchTerms} from '../../utils/isRecentSearchTerms'
import {initialSearchState, searchReducer} from './reducer'
import {SearchContext} from './SearchContext'

interface SearchProviderProps {
children?: ReactNode
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {useContext} from 'react'
import {SearchContext} from 'sanity/_singletons'

import {SearchContext, type SearchContextValue} from './SearchContext'
import {type SearchContextValue} from './SearchContext'

/**
* @internal
Expand Down

0 comments on commit b4a8f3b

Please sign in to comment.