Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: revert "feat: expose channels state on chat level (#2161)" #2184

Merged
merged 3 commits into from
Dec 1, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
docs: keep documentation for channelsQueryState & ChatContextValue
MartinCupela committed Nov 23, 2023
commit d71691e306c1017c789d74a6dbae28988eed2ab1
20 changes: 20 additions & 0 deletions docusaurus/docs/React/components/contexts/chat-context.mdx
Original file line number Diff line number Diff line change
@@ -33,6 +33,26 @@ The currently active channel, which populates the [`Channel`](../core-components
| ------- |
| Channel |

### channelsQueryState

Exposes API that:

- indicates, whether and what channels query has been triggered within [`ChannelList` component](../core-components/channel-list.mdx) by its channels pagination controller - `queryInProgress` of type `ChannelQueryState`
- allows to set the `queryInProgress` state with `setQueryInProgress` state setter
- keeps track of error response from the channels query - `error`
- allows to set the `error` state with `setError`

The `queryInProgress` values are:

- `uninitialized` - the initial state before the first channels query is triggered
- `reload` - the initial channels query (loading the first page) is in progress
- `load-more` - loading the next page of channels
- `null` - at least one channels page has been loaded and there is no query in progress at the moment

| Type |
|----------------------|
| `ChannelsQueryState` |

### closeMobileNav

The function to close mobile navigation.
2 changes: 1 addition & 1 deletion src/components/Chat/hooks/useChannelsQueryState.ts
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ import { Dispatch, SetStateAction, useState } from 'react';
import type { APIErrorResponse, ErrorFromResponse } from 'stream-chat';

type ChannelQueryState =
| 'uninitialized' // the initial state before the first channels query is trigerred
| 'uninitialized' // the initial state before the first channels query is triggered
| 'reload' // the initial channels query (loading the first page) is in progress
| 'load-more' // loading the next page of channels
| null; // at least one channels page has been loaded and there is no query in progress at the moment
18 changes: 18 additions & 0 deletions src/context/ChatContext.tsx
Original file line number Diff line number Diff line change
@@ -28,20 +28,38 @@ export type ThemeVersion = '1' | '2';
export type ChatContextValue<
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics
> = {
/**
* Indicates, whether a channels query has been triggered within ChannelList by its channels pagination controller.
*/
channelsQueryState: ChannelsQueryState;
closeMobileNav: () => void;
getAppSettings: () => Promise<AppSettingsAPIResponse<StreamChatGenerics>> | null;
latestMessageDatesByChannels: Record<ChannelCID, Date>;
mutes: Array<Mute<StreamChatGenerics>>;
openMobileNav: () => void;
/**
* Sets active channel to be rendered within Channel component.
* @param newChannel
* @param watchers
* @param event
*/
setActiveChannel: (
newChannel?: Channel<StreamChatGenerics>,
watchers?: { limit?: number; offset?: number },
event?: React.BaseSyntheticEvent,
) => void;
/**
* Allows to opt out of the use of legacy CSS (version "1") and opt into the use of the latest SDK's CSS (version "2").
*/
themeVersion: ThemeVersion;
useImageFlagEmojisOnWindows: boolean;
/**
* Active channel used to render the contents of the Channel component.
*/
channel?: Channel<StreamChatGenerics>;
/**
* Object through which custom classes can be set for main container components of the SDK.
*/
customClasses?: CustomClasses;
navOpen?: boolean;
} & Required<Pick<ChatProps<StreamChatGenerics>, 'theme' | 'client'>>;