Skip to content

Commit

Permalink
docs: restructuring (#2250)
Browse files Browse the repository at this point in the history
### 🎯 Goal

Restructure documentation following new structures of iOS and RN.

TODO: 
- [ ] move certain content to proper places (both files and certain
paragraphs/articles)
- [x] We'll need to start using
[`sidebars-react.json`](https://github.com/GetStream/stream-chat-swift/blob/develop/docusaurus/sidebars-ios.json)
(iOS one for reference) as folder structure which looks like this:

![image](https://github.com/GetStream/stream-chat-react/assets/43254280/0a4fd24d-cc23-4dd9-9ee4-c6564ff9634d)
generates a sidebar which looks like this:

![image](https://github.com/GetStream/stream-chat-react/assets/43254280/259f8ca2-40f1-4e09-926f-5ace7df93016)
making <Message List> dropdown also a clickable link which navigates to
the content - which is not what we want - and content id's are not
respected.
(notice size of carets in this one and font of "Attachment" is also
different from others)

![image](https://github.com/GetStream/stream-chat-react/assets/43254280/082ea6ab-bca0-434b-8c44-26b7e75eac1b)
  • Loading branch information
arnautov-anton authored Mar 1, 2024
1 parent e086565 commit 4620b24
Show file tree
Hide file tree
Showing 294 changed files with 18,999 additions and 1,012 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
- name: Install dependencies
run: yarn install --frozen-lockfile --ignore-engines --ignore-scripts
- name: Merge shared "@stream-io/stream-chat-css" docs
run: bash scripts/merge-stream-chat-css-docs.sh node_modules/@stream-io/stream-chat-css/docs
run: yarn docs:copy-css-docs
- name: Push to stream-chat-docusaurus
uses: GetStream/push-stream-chat-docusaurus-action@main
with:
Expand Down
2 changes: 1 addition & 1 deletion developers/DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ If you are introducing changes impacting the API or behavior of the SDK parts, y


```bash
yarn docs-run
yarn docs:run
```

## Documentation patterns
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docusaurus/docs/React/assets/default-thread.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
216 changes: 59 additions & 157 deletions docusaurus/docs/React/basics/getting-started.mdx
Original file line number Diff line number Diff line change
@@ -1,78 +1,76 @@
---
id: getting_started
sidebar_position: 2
title: Getting Started
---

This section provides a high level overview of the library setup, core components, and how they fit together. It's a great
starting point and you can follow along in your code editor. For a complete, step-by-step guide in terms setting up a React
project or instructions on creating specific files, see our [React Chat tutorial](https://getstream.io/chat/react-chat/tutorial/).
This section provides a high level overview of the library setup, core components, and how they fit together. It's a great starting point and you can follow along in your code editor. For a complete, step-by-step guide in terms setting up a React project or instructions on creating specific files, see our [React Chat tutorial](https://getstream.io/chat/react-chat/tutorial/).

## Your First App with Stream Chat React

Before starting, make sure you have installed `stream-chat-react` (and `stream-chat`), as directed in the
[Installation](./installation.mdx) section.

The below example is all the code you need to launch a fully functioning chat experience. The [`Chat`](../components/core-components/chat.mdx)
and [`Channel`](../components/core-components/channel.mdx) components are React context providers that pass a variety of values to their
children, including UI components, stateful data, and action handler functions.
You'll also need to [register](https://getstream.io/chat/trial/) and create a free tier (for up to 25 MAU) Stream application to access credentials from which you'll be able to [generate a token](https://getstream.io/chat/docs/react/token_generator/) for a user which can access your chat application.

```jsx
const App = () => (
<Chat client={client}>
<Channel channel={channel}>
<Window>
<ChannelHeader />
<MessageList />
<MessageInput />
</Window>
<Thread />
</Channel>
</Chat>
);
```
The example below is all the code you'll need to launch a fully functioning chat experience. The [`Chat`](../components/core-components/chat.mdx) and [`Channel`](../components/core-components/channel.mdx) components are React context providers that pass a variety of values to their children, including UI components, stateful data, and action handler functions.

## Creating a Chat Client
```jsx
import {
Chat,
Channel,
ChannelList,
Window,
ChannelHeader,
MessageList,
MessageInput,
Thread,
useCreateChatClient,
} from 'stream-chat-react';
import 'stream-chat-react/dist/css/v2/index.css';

To communicate with the Stream Chat API, create an instance of Stream Chat client with your API key and pass via props into the `Chat`
component. To generate an API key, you can sign up for a [free 30-day trial](https://getstream.io/chat/trial/) on our website.
const apiKey = 'your-api-key';
const userId = 'user-id';
const token = 'authentication-token';

Initialize the Stream Chat client:
const filters = { members: { $in: [userId] }, type: 'messaging' };
const options = { presence: true, state: true };
const sort = { last_message_at: -1 };

```jsx
import { StreamChat } from 'stream-chat';
const App = () => {
const client = useCreateChatClient({
apiKey,
tokenOrProvider: token,
userData: { id: userId },
});

const client = new StreamChat('your_api_key');
if (!client) return <div>Loading...</div>;

<Chat client={client}>{/** children of Chat component*/}</Chat>;
return (
<Chat client={client}>
<ChannelList sort={sort} filters={filters} options={options} />
<Channel>
<Window>
<ChannelHeader />
<MessageList />
<MessageInput />
</Window>
<Thread />
</Channel>
</Chat>
);
};
```

## Connecting a User
## Chat Client & Connecting User

Tokens are used to authenticate a user. Typically, you send this token from your backend to your front end when a user logs in.
See the [Tokens & Authentication](https://getstream.io/chat/docs/javascript/tokens_and_authentication/) documentation to learn more
about creating tokens. For our purposes here, we will assume you have created and retrieved a `userToken`.

To connect a user, call the `connectUser` method on your client instance with the user object and `userToken` provided as arguments.
Connect the user directly after instantiating the client to establish a websocket connection with the Stream Chat API. Once the connection
has been opened, your client instance will begin receiving events from the API.

```jsx
client.connectUser(
{
id: 'dave-matthews',
name: 'Dave Matthews',
},
userToken,
);
```
To communicate with the Stream Chat API the SDK requires a client with an established connection. The hook mentioned in the code above (`useCreateChatClient`) handles client instantiation, establishes proper connection and handles cleanups and disconnects for you. If you wish to have more control over how all of the previously mentioned is being handled see [Client and User](../guides/client-and-user.mdx) guide.

## Creating a Channel

Channels are at the core of Stream Chat. Within a channel you send/receive messages and interact with other users. Once a channel
object has been initialized, the `Channel` component consumes the object and renders your chat app's functionality.

By default, the Stream Chat API provides support for five different [channel types](https://getstream.io/chat/docs/react/channel_features/)
By default, the Stream Chat API provides support for five different [channel types](https://getstream.io/chat/docs/react/channel_features)
of varying use cases. A channel type is required when creating a channel and dictates the available features and permissions.
The defaults include:

Expand All @@ -95,66 +93,44 @@ To create an instance of a channel, call the `channel` method on your client ins

```jsx
const channel = client.channel('messaging', {
image: 'dave.png',
name: 'Create a Messaging Channel',
image: 'https://cdn.com/image.png',
name: 'Just Chatting',
members: ['dave-matthews', 'trey-anastasio'],
// option to add custom fields
});
```

## Setting Up the UI Components
## Setting Up the Components

Now that we have a client instance, a connected user, and a channel, it's time to look at the core components involved in building
a fully functioning chat application.

### Chat

The [`Chat`](../components/core-components/chat.mdx) component is a React Context provider that wraps the entire Stream Chat application. It provides the [`ChatContext`](../components/contexts/chat-context.mdx)
to its children, which includes the `StreamChat` client instance. All other components within the library must be nested as children
of `Chat` to maintain proper functionality.
The [`Chat`](../components/core-components/chat.mdx) component is a React Context provider that wraps the entire Stream Chat application. It provides the [`ChatContext`](../components/contexts/chat-context.mdx) to its children, which includes the `StreamChat` client instance. All other components within the library must be nested as children of `Chat` to maintain proper functionality.

The client instance can be accessed with our custom context hook:

```jsx
import { useChatContext } from 'stream-chat-react';

// ...

const { client } = useChatContext();
```

### Channel

The [`Channel`](../components/core-components/channel.mdx) component is a React Context provider that wraps all of the logic, functionality, and UI for an individual chat channel.
It provides five separate contexts to its children:

:::caution
`EmojiContext` has been removed in version `11.0.0`, see related release guides ([Introducing new reactions](../release-guides/upgrade-to-v11.mdx#introducing-new-reactions), [Dropping support for built-in `EmojiPicker`](../release-guides/upgrade-to-v11.mdx#dropping-support-for-built-in-emojipicker) and [Dropping support for built-in `EmojiIndex`](../release-guides/upgrade-to-v11.mdx#dropping-support-for-built-in-emojiindex)) to adjust your integration to this new change.
:::
The [`Channel`](../components/core-components/channel.mdx) component is a React Context provider that wraps all of the logic, functionality, and UI for an individual chat channel. It provides five separate contexts to its children:

- [`ChannelStateContext`](../components/contexts/channel-state-context.mdx) - stateful data (ex: `messages` or `members`)
- [`ChannelActionContext`](../components/contexts/channel-action-context.mdx) - action handlers (ex: `sendMessage` or `openThread`)
- [`ComponentContext`](../components/contexts/component-context.mdx) - custom component UI overrides (ex: `Avatar` or `Message`)
- [`EmojiContext`](../components/contexts/emoji-context.mdx) - emoji UI components and data (ex: `EmojiPicker` or `emojiConfig`) - removed in `11.0.0`
- [`TypingContext`](../components/contexts/typing-context.mdx) - object of currently typing users (i.e., `typing`)

### ChannelList

The [`ChannelList`](../components/core-components/channel-list.mdx) component renders a list of channels and provides a preview for each. Though the `ChannelList` is essential in many chat apps,
it isn't a required piece of the library. If a `ChannelList` component is used, a channel object should not be placed as a prop on the `Channel`
component, as the `ChannelList` handles channel setting internally.

```jsx
const App = () => (
<Chat client={client}>
<ChannelList />
<Channel>
<Window>
<ChannelHeader />
<MessageList />
<MessageInput />
</Window>
<Thread />
</Channel>
</Chat>
);
```
The [`ChannelList`](../components/core-components/channel-list.mdx) component renders a list of channels and provides a preview for each. Though the `ChannelList` is essential in many chat apps, it isn't a required piece of the library. If a `ChannelList` component is used, a channel object should not be placed as a prop on the `Channel` component, as the `ChannelList` handles channel setting internally.

### Window

Expand All @@ -178,84 +154,10 @@ The [`Thread`](../components/core-components/thread.mdx) component renders a lis

### Emojis (picker & autocomplete)

The SDK is equipped with features designed to facilitate seamless integration, enabling developers to effortlessly incorporate emoji picker and emoji autocomplete (built on top of [`emoji-mart`](https://github.com/missive/emoji-mart)) functionalities for a comprehensive chat experience.

Starting from version `11.0.0`, these features are entirely optional, requiring integrators to opt-in manually. The decision was made in conjunction with enhanced architecture, aiming to reduce the overall size of the final bundles of our integrators.
The SDK is equipped with features designed to facilitate seamless integration, enabling developers to effortlessly incorporate [emoji picker](../guides/customization/emoji-picker.mdx) and emoji autocomplete (built on top of [`emoji-mart`](https://github.com/missive/emoji-mart)) functionalities for a comprehensive chat experience.

Make sure to read ["Dropping support for built-in `EmojiPicker`"](../release-guides/upgrade-to-v11.mdx#dropping-support-for-built-in-emojipicker) and ["Dropping support for built-in `EmojiIndex`"](../release-guides/upgrade-to-v11.mdx#dropping-support-for-built-in-emojiindex) release guides for more information.

## Summary

In addition to the above referenced UI components, client instantiation, and user connection, you need little other code to get a fully functioning chat application up and running. See below for an example of the complete code.
Make sure to read [_Dropping support for built-in `EmojiPicker`_](../release-guides/upgrade-to-v11.mdx#dropping-support-for-built-in-emojipicker) and [_Dropping support for built-in `EmojiIndex`_](../release-guides/upgrade-to-v11.mdx#dropping-support-for-built-in-emojiindex) release guides for more information.

:::note
Remember our [Theming](../guides/theming/overview.mdx) and [Customizing Components](../guides/customization/overview.mdx) sections in our guides. They offer you a lot of flexibility when adopting our SDK.
Read more about customization in our [Theming](../theming/introduction.mdx) and [Customizing Components](../guides/customization/overview.mdx) guides.
:::

```tsx
import React, { useEffect, useState } from 'react';
import { StreamChat } from 'stream-chat';
import {
Chat,
Channel,
ChannelHeader,
ChannelList,
MessageList,
MessageInput,
Thread,
Window,
} from 'stream-chat-react';
import 'stream-chat-react/dist/css/v2/index.css';

const filters = { type: 'messaging' };
const options = { state: true, presence: true, limit: 10 };
const sort = { last_message_at: -1 };

const App = () => {
const [client, setClient] = useState(null);

useEffect(() => {
const newClient = new StreamChat('your_api_key');

const handleConnectionChange = ({ online = false }) => {
if (!online) return console.log('connection lost');
setClient(newClient);
};

newClient.on('connection.changed', handleConnectionChange);

newClient.connectUser(
{
id: 'dave-matthews',
name: 'Dave Matthews',
},
'your_user_token',
);

return () => {
newClient.off('connection.changed', handleConnectionChange);
newClient.disconnectUser().then(() => console.log('connection closed'));
};
}, []);

if (!client) return null;

return (
<Chat client={client}>
<ChannelList filters={filters} sort={sort} options={options} />
<Channel>
<Window>
<ChannelHeader />
<MessageList />
<MessageInput />
</Window>
<Thread />
</Channel>
</Chat>
);
};

export default App;
```

With a basic chat app up and running with our default UI, it's time to take a deep dive into each individual component in the library.
36 changes: 1 addition & 35 deletions docusaurus/docs/React/basics/installation.mdx
Original file line number Diff line number Diff line change
@@ -1,42 +1,8 @@
---
id: installation
sidebar_position: 1
slug: /
title: Overview
title: Installation
---

Building on top of the Stream Chat API, the Stream Chat React component library includes everything you need to build feature-rich and high-functioning chat user experiences out of the box.
The library includes an extensive set of performant and customizable React components which allow you to get started quickly with little to no plumbing required.
Use cases include team and social messaging, virtual events, livestream gaming, and customer support. The library supports:

- Rich media messages
- Reactions
- Threads and quoted replies
- Text input commands (ex: Giphy and @mentions)
- Image and file uploads
- Video playback
- Read state and typing indicators
- Channel and message lists

## Where to get started

If you are new to our SDK it is best to go through a of our [tutorial](https://getstream.io/chat/react-chat/tutorial/).

After that, our [getting started page](./getting-started.mdx) is a great next step.

:::tip
If you are integrating our SDK, please pay attention to our [Theming](../guides/theming/overview.mdx) and [Customizing Components](../guides/customization/overview.mdx) sections in our guides. We see that most of our users can get very far by utilizing the flexibility of our SDKs.
:::

## Architecture

A common pattern in the library is the use of context provider hooks (see [Contexts](./contexts/chat_context)). These custom hooks allow for effective value sharing between parent components and their children.
This makes customization straightforward, as you can use our exported hooks in your custom components to receive the exact values needed, while also subscribing to context changes.

The left navigation will guide you to the various documentation sections for information on everything regarding our robust component library. Check out the instructions below for adding the library to your React project.

## Installation

We recommended using the component library through a package manager. Stream Chat React is based on top of Stream's [JavaScript Client](https://getstream.io/chat/docs/javascript/?language=javascript).

### Install with NPM
Expand Down
35 changes: 35 additions & 0 deletions docusaurus/docs/React/basics/overview.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
id: overview
slug: /
title: Overview
---

Building on top of the Stream Chat API, the Stream Chat React component library includes everything you need to build feature-rich and high-functioning chat user experiences out of the box.
The library includes an extensive set of performant and customizable React components which allow you to get started quickly with little to no plumbing required.
Use cases include team and social messaging, virtual events, livestream gaming, and customer support. The library supports:

- Rich media messages
- Reactions
- Threads and quoted replies
- Text input commands (ex: Giphy and @mentions)
- Image and file uploads
- Video playback
- Read state and typing indicators
- Channel and message lists

## Where to get started

If you are new to our SDK it is best to go through a of our [tutorial](https://getstream.io/chat/react-chat/tutorial/).

After that, our [getting started page](./getting-started.mdx) is a great next step.

:::tip
If you are integrating our SDK, please pay attention to our [Theming](../theming/introduction.mdx) and [Customizing Components](../guides/customization/overview.mdx) sections in our guides. We see that most of our users can get very far by utilizing the flexibility of our SDKs.
:::

## Architecture

A common pattern in the library is the use of context provider hooks. These custom hooks allow for effective value sharing between parent components and their children.
This makes customization straightforward, as you can use our exported hooks in your custom components to receive the exact values needed, while also subscribing to context changes.

The left navigation will guide you to the various documentation sections for information on everything regarding our robust component library. Check out the instructions below for adding the library to your React project.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
id: channel_action_context
sidebar_position: 3
title: ChannelActionContext
---

Expand Down
Loading

0 comments on commit 4620b24

Please sign in to comment.