diff --git a/native/root.react.js b/native/root.react.js --- a/native/root.react.js +++ b/native/root.react.js @@ -49,6 +49,7 @@ import { store } from './redux/redux-setup.js'; import { useSelector } from './redux/redux-utils.js'; import { RootContext } from './root-context.js'; +import { MessageSearchProvider } from './search/search-provider.react.js'; import Socket from './socket.react.js'; import { StaffContextProvider } from './staff/staff-context.provider.react.js'; import { useLoadCommFonts } from './themes/fonts.js'; @@ -262,19 +263,21 @@ - - - - {gated} - - - - - {navigation} + + + + + {gated} + + + + + {navigation} + diff --git a/native/search/search-provider.react.js b/native/search/search-provider.react.js new file mode 100644 --- /dev/null +++ b/native/search/search-provider.react.js @@ -0,0 +1,42 @@ +// @flow + +import * as React from 'react'; + +import type { SetState } from 'lib/types/hook-types.js'; + +export type MessageSearchContextType = { + +query: string, + +setQuery: SetState, + +clearQuery: () => void, +}; + +const MessageSearchContext: React.Context = + React.createContext(); + +type Props = { + +children: React.Node, +}; +function MessageSearchProvider(props: Props): React.Node { + const { children } = props; + + const [query, setQuery] = React.useState(''); + + const clearQuery = React.useCallback(() => setQuery(''), []); + + const context = React.useMemo( + () => ({ + query, + setQuery, + clearQuery, + }), + [query, clearQuery], + ); + + return ( + + {children} + + ); +} + +export { MessageSearchContext, MessageSearchProvider };