Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions examples/vite/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import data from '@emoji-mart/data/sets/14/native.json';
import { humanId } from 'human-id';

import { appSettingsStore, useAppSettingsSelector } from './AppSettings/state.ts';
import { DESKTOP_LAYOUT_BREAKPOINT } from './ChatLayout/constants.ts';
import { ChannelsPanels, ThreadsPanels } from './ChatLayout/Panels.tsx';
import { PanelLayoutStyleSync, SidebarLayoutSync } from './ChatLayout/Resize.tsx';
import {
Expand Down Expand Up @@ -159,9 +158,6 @@ const App = () => {
tokenOrProvider: tokenProvider,
userData: { id: userId },
});
const useResponsiveInitialNav =
typeof window === 'undefined' || window.innerWidth < DESKTOP_LAYOUT_BREAKPOINT;

const searchController = useMemo(() => {
if (!chatClient) return undefined;

Expand Down Expand Up @@ -265,7 +261,6 @@ const App = () => {
searchController={searchController}
client={chatClient}
initialNavOpen={initialNavOpen}
initialNavOpenResponsive={useResponsiveInitialNav}
isMessageAIGenerated={isMessageAIGenerated}
theme={chatTheme}
>
Expand Down
10 changes: 4 additions & 6 deletions src/components/Chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ export type ChatProps = {
defaultLanguage?: SupportedTranslations;
/** Instance of Stream i18n */
i18nInstance?: Streami18n;
/** Initial status of mobile navigation. Ignored when initialNavOpenResponsive is true. */
/**
* Initial open state of the sidebar. Omit for responsive (viewport-derived); set to true/false for an explicit initial state.
*/
initialNavOpen?: boolean;
/** When true, sidebar (ChannelList/ThreadList + selector) is open on load; it closes when a channel or thread is selected. */
initialNavOpenResponsive?: boolean;
/** Instance of SearchController class that allows to control all the search operations. */
searchController?: SearchController;
/** Used for injecting className/s to the Channel and ChannelList components */
Expand All @@ -56,8 +56,7 @@ export const Chat = (props: PropsWithChildren<ChatProps>) => {
customClasses,
defaultLanguage,
i18nInstance,
initialNavOpen = true,
initialNavOpenResponsive = true,
initialNavOpen,
isMessageAIGenerated,
searchController: customChannelSearchController,
theme = 'messaging light',
Expand All @@ -79,7 +78,6 @@ export const Chat = (props: PropsWithChildren<ChatProps>) => {
defaultLanguage,
i18nInstance,
initialNavOpen,
initialNavOpenResponsive,
});

const channelsQueryState = useChannelsQueryState();
Expand Down
11 changes: 5 additions & 6 deletions src/components/Chat/hooks/useChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,17 @@ export type UseChatParams = {
client: StreamChat;
defaultLanguage?: SupportedTranslations;
i18nInstance?: Streami18n;
/** Initial open state of the sidebar. Ignored when initialNavOpenResponsive is true. */
/**
* Initial open state of the sidebar. Omit for responsive (viewport-derived); set to true/false for an explicit initial state.
*/
initialNavOpen?: boolean;
/** When true, initial nav state is open so sidebar (ChannelList/ThreadList + selector) is visible; close on channel/thread selection. */
initialNavOpenResponsive?: boolean;
};

export const useChat = ({
client,
defaultLanguage = 'en',
i18nInstance,
initialNavOpen,
initialNavOpenResponsive = false,
}: UseChatParams) => {
const [translators, setTranslators] = useState<TranslationContextValue>({
t: defaultTranslatorFunction,
Expand All @@ -50,8 +49,8 @@ export const useChat = ({
const [channel, setChannel] = useState<Channel>();
const [mutes, setMutes] = useState<Array<Mute>>([]);
const [navOpen, setNavOpen] = useState(() => {
if (initialNavOpenResponsive) return getDefaultNavOpenFromViewport() ?? true;
return initialNavOpen === false ? false : true;
if (initialNavOpen === undefined) return getDefaultNavOpenFromViewport() ?? true;
return initialNavOpen;
});
const [latestMessageDatesByChannels, setLatestMessageDatesByChannels] = useState({});

Expand Down
Loading