Skip to content
Draft
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
159 changes: 121 additions & 38 deletions examples/vite/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { type PropsWithChildren, useCallback, useEffect, useMemo } from 'react';
import {
createContext,
type PropsWithChildren,
useCallback,
useContext,
useEffect,
useMemo,
useState,
} from 'react';
import {
ChannelFilters,
ChannelOptions,
Expand Down Expand Up @@ -27,6 +35,9 @@ import {
MessageList,
Window,
WithComponents,
GroupAvatar,
ReactionsList,
useMessageContext,
} from 'stream-chat-react';
import { createTextComposerEmojiMiddleware, EmojiPicker } from 'stream-chat-react/emojis';
import { init, SearchIndex } from 'emoji-mart';
Expand Down Expand Up @@ -79,9 +90,39 @@ const useUser = () => {
return { userId: userId, tokenProvider };
};

const CustomMessageReactions = (props: React.ComponentProps<typeof ReactionsList>) => {
const { visualStyle, verticalPosition, flipHorizontalPosition } = useContext(TempCtx);

return (
<ReactionsList
{...props}
flipHorizontalPosition={flipHorizontalPosition}
verticalPosition={verticalPosition}
visualStyle={visualStyle}
/>
);
};

type TempCtxValue = {
visualStyle: 'clustered' | 'segmented';
verticalPosition: 'top' | 'bottom';
flipHorizontalPosition: boolean;
};
const TempCtx = createContext<TempCtxValue>({
visualStyle: 'clustered',
verticalPosition: 'top',
flipHorizontalPosition: false,
});

const App = () => {
const { userId, tokenProvider } = useUser();

const [tempCtxValue, setTempCtxValue] = useState<TempCtxValue>({
visualStyle: 'clustered',
verticalPosition: 'top',
flipHorizontalPosition: false,
});

const chatClient = useCreateChatClient({
apiKey,
tokenOrProvider: tokenProvider,
Expand Down Expand Up @@ -141,43 +182,85 @@ const App = () => {
if (!chatClient) return <>Loading...</>;

return (
<WithComponents overrides={{ emojiSearchIndex: SearchIndex, EmojiPicker }}>
<Chat client={chatClient} isMessageAIGenerated={isMessageAIGenerated}>
<ChatView>
<ChatView.Selector />
<ChatView.Channels>
<ChannelList
Avatar={ChannelAvatar}
filters={filters}
options={options}
sort={sort}
showChannelSearch
additionalChannelSearchProps={{ searchForChannels: true }}
/>
<Channel>
<Window>
<ChannelHeader Avatar={ChannelAvatar} />
<MessageList returnAllReadData />
<AIStateIndicator />
<MessageInput
focus
audioRecordingEnabled
maxRows={10}
asyncMessagesMultiSendEnabled
/>
</Window>
<Thread virtualized />
</Channel>
</ChatView.Channels>
<ChatView.Threads>
<ThreadList />
<ChatView.ThreadAdapter>
<Thread virtualized />
</ChatView.ThreadAdapter>
</ChatView.Threads>
</ChatView>
</Chat>
</WithComponents>
<TempCtx.Provider value={tempCtxValue}>
<WithComponents
overrides={{
emojiSearchIndex: SearchIndex,
EmojiPicker,
ReactionsList: CustomMessageReactions,
}}
>
<Chat client={chatClient} isMessageAIGenerated={isMessageAIGenerated}>
<ChatView>
<ChatView.Selector />
<ChatView.Channels>
<ChannelList
Avatar={ChannelAvatar}
filters={filters}
options={options}
sort={sort}
showChannelSearch
additionalChannelSearchProps={{ searchForChannels: true }}
/>
<Channel>
<Window>
<div style={{ display: 'flex', gap: 10, padding: 10 }}>
<button
onClick={() =>
setTempCtxValue((prev) => ({
...prev,
visualStyle:
prev.visualStyle === 'clustered' ? 'segmented' : 'clustered',
}))
}
>
Toggle Visual Style
</button>
<button
onClick={() =>
setTempCtxValue((prev) => ({
...prev,
verticalPosition:
prev.verticalPosition === 'top' ? 'bottom' : 'top',
}))
}
>
Toggle Vertical Position
</button>
<button
onClick={() =>
setTempCtxValue((prev) => ({
...prev,
flipHorizontalPosition: !prev.flipHorizontalPosition,
}))
}
>
Toggle Horizontal Position
</button>
</div>
<ChannelHeader Avatar={ChannelAvatar} />
<MessageList returnAllReadData />
<AIStateIndicator />
<MessageInput
focus
audioRecordingEnabled
maxRows={10}
asyncMessagesMultiSendEnabled
/>
</Window>
<Thread virtualized />
</Channel>
</ChatView.Channels>
<ChatView.Threads>
<ThreadList />
<ChatView.ThreadAdapter>
<Thread virtualized />
</ChatView.ThreadAdapter>
</ChatView.Threads>
</ChatView>
</Chat>
</WithComponents>
</TempCtx.Provider>
);
};

Expand Down
2 changes: 1 addition & 1 deletion examples/vite/src/stream-imports-layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
//@use 'stream-chat-react/dist/scss/v2/MessageInput/MessageInput-layout'; // X
@use 'stream-chat-react/dist/scss/v2/MessageList/MessageList-layout';
@use 'stream-chat-react/dist/scss/v2/MessageList/VirtualizedMessageList-layout';
@use 'stream-chat-react/dist/scss/v2/MessageReactions/MessageReactions-layout';
// @use 'stream-chat-react/dist/scss/v2/MessageReactions/MessageReactions-layout';
@use 'stream-chat-react/dist/scss/v2/MessageReactions/MessageReactionsSelector-layout';
@use 'stream-chat-react/dist/scss/v2/Modal/Modal-layout';
@use 'stream-chat-react/dist/scss/v2/Notification/MessageNotification-layout';
Expand Down
2 changes: 1 addition & 1 deletion examples/vite/src/stream-imports-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
@use 'stream-chat-react/dist/scss/v2/MessageBouncePrompt/MessageBouncePrompt-theme';
@use 'stream-chat-react/dist/scss/v2/MessageList/MessageList-theme';
@use 'stream-chat-react/dist/scss/v2/MessageList/VirtualizedMessageList-theme';
@use 'stream-chat-react/dist/scss/v2/MessageReactions/MessageReactions-theme';
// @use 'stream-chat-react/dist/scss/v2/MessageReactions/MessageReactions-theme';
@use 'stream-chat-react/dist/scss/v2/MessageReactions/MessageReactionsSelector-theme';
@use 'stream-chat-react/dist/scss/v2/Modal/Modal-theme';
@use 'stream-chat-react/dist/scss/v2/Notification/MessageNotification-theme';
Expand Down
Loading
Loading