diff --git a/packages/status-react/src/contexts/app-context.tsx b/packages/status-react/src/contexts/app-context.tsx index 3e6e84f..f96e537 100644 --- a/packages/status-react/src/contexts/app-context.tsx +++ b/packages/status-react/src/contexts/app-context.tsx @@ -1,10 +1,12 @@ import React, { createContext, useContext, useMemo, useReducer } from 'react' +import type { Config } from '../types/config' import type { Dispatch, Reducer } from 'react' type Context = { state: State dispatch: Dispatch + options: NonNullable } const AppContext = createContext(undefined) @@ -31,13 +33,27 @@ const initialState: State = { interface Props { children: React.ReactNode + config: Config } export const AppProvider = (props: Props) => { - const { children } = props + const { children, config } = props const [state, dispatch] = useReducer(reducer, initialState) - const value = useMemo(() => ({ state, dispatch }), [state]) + + const value = useMemo( + () => ({ + state, + dispatch, + options: { + enableSidebar: true, + enableMembers: true, + ...config.options, + }, + }), + // eslint-disable-next-line react-hooks/exhaustive-deps + [state] + ) return {children} } diff --git a/packages/status-react/src/modules/community/index.tsx b/packages/status-react/src/modules/community/index.tsx index 3a13f2e..c88ea80 100644 --- a/packages/status-react/src/modules/community/index.tsx +++ b/packages/status-react/src/modules/community/index.tsx @@ -31,7 +31,7 @@ export const Community = (props: Props) => { return ( - + diff --git a/packages/status-react/src/modules/community/messenger.tsx b/packages/status-react/src/modules/community/messenger.tsx index 8c16b58..597eadd 100644 --- a/packages/status-react/src/modules/community/messenger.tsx +++ b/packages/status-react/src/modules/community/messenger.tsx @@ -3,6 +3,7 @@ import React from 'react' import { Route, Routes } from 'react-router-dom' import { MainSidebar } from '~/src/components/main-sidebar' +import { useAppState } from '~/src/contexts/app-context' import { Chat } from '~/src/routes/chat' import { NewChat } from '~/src/routes/new-chat' import { styled } from '~/src/styles/config' @@ -42,9 +43,11 @@ import { styled } from '~/src/styles/config' // } export function Messenger() { + const { options } = useAppState() + return ( - + {options.enableMembers && } } /> } /> diff --git a/packages/status-react/src/routes/chat/index.tsx b/packages/status-react/src/routes/chat/index.tsx index 2b617e9..5226153 100644 --- a/packages/status-react/src/routes/chat/index.tsx +++ b/packages/status-react/src/routes/chat/index.tsx @@ -44,10 +44,10 @@ const Content = () => { } export const Chat = () => { - const { state } = useAppState() + const { state, options } = useAppState() // TODO: Update condition based on a chat type - const enableMembers = true + const enableMembers = options.enableMembers // && (chat.type === 'group' || chat.type === 'channel') const showMembers = enableMembers && state.showMembers return ( diff --git a/packages/status-react/src/types/config.tsx b/packages/status-react/src/types/config.tsx index 6ce2847..97b71e4 100644 --- a/packages/status-react/src/types/config.tsx +++ b/packages/status-react/src/types/config.tsx @@ -8,4 +8,8 @@ export interface Config { environment?: Environment theme?: Theme router?: typeof BrowserRouter | typeof MemoryRouter | typeof HashRouter + options?: { + enableSidebar: boolean + enableMembers: boolean + } }