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

Chat: add empty view stories #28173

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
88 changes: 85 additions & 3 deletions apps/react-storybook/stories/chat/Chat.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useCallback } from 'react';
import React, { useState, useCallback, useEffect } from 'react';
import {Chat, ChatTypes} from 'devextreme-react/chat'
import type {Meta, StoryObj} from '@storybook/react';
import { firstAuthor, secondAuthor, initialMessages } from './data';
Expand Down Expand Up @@ -44,6 +44,7 @@ export const Overview: Story = {
[firstAuthor.name]: firstAuthor,
[secondAuthor.name]: secondAuthor,
},
defaultValue: firstAuthor.name,
},
hint: {
control: 'text',
Expand All @@ -65,8 +66,14 @@ export const Overview: Story = {
const [messages, setMessages] = useState(items);

const onMessageSend = useCallback(({ message }) => {
setMessages((prevMessages) => [...prevMessages, message]);
}, []);
const updatedMessages = [...messages, message];

setMessages(updatedMessages);
}, [messages]);

useEffect(() => {
setMessages(items);
}, [items]);

return (
<div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
Expand All @@ -90,6 +97,76 @@ export const Overview: Story = {
}
}

export const EmptyView: Story = {
args: {
items: [],
user: firstAuthor,
...commonArgs,
},
argTypes: {
user: {
control: 'select',
options: [firstAuthor.name, secondAuthor.name],
mapping: {
[firstAuthor.name]: firstAuthor,
[secondAuthor.name]: secondAuthor,
},
defaultValue: firstAuthor.name,
},
hint: {
control: 'text',
}
},
render: ({
width,
height,
disabled,
rtlEnabled,
user,
items,
onItemsChange,
visible,
hint,
activeStateEnabled,
hoverStateEnabled,
focusStateEnabled,
}) => {
const [messages, setMessages] = useState(items);

const onMessageSend = useCallback(({ message }) => {
const updatedMessages = [...messages, message];

setMessages(updatedMessages);
}, [messages]);

useEffect(() => {
console.log(2);
setMessages(items);
}, [items]);

return (
<div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
<Chat
width={width}
height={height}
items={messages}
onItemsChange={onItemsChange}
disabled={disabled}
rtlEnabled={rtlEnabled}
user={user}
onMessageSend={onMessageSend}
visible={visible}
hint={hint}
activeStateEnabled={activeStateEnabled}
focusStateEnabled={focusStateEnabled}
hoverStateEnabled={hoverStateEnabled}
>
</Chat>
</div>
);
}
}

export const PopupIntegration: Story = {
args: {
items: initialMessages,
Expand All @@ -106,6 +183,7 @@ export const PopupIntegration: Story = {
[firstAuthor.name]: firstAuthor,
[secondAuthor.name]: secondAuthor,
},
defaultValue: firstAuthor.name,
},
hint: {
control: 'text',
Expand All @@ -130,6 +208,10 @@ export const PopupIntegration: Story = {
setMessages((prevMessages) => [...prevMessages, message]);
}, []);

useEffect(() => {
setMessages(items);
}, [items]);

return (
<Popup
width={300}
Expand Down
17 changes: 16 additions & 1 deletion apps/react-storybook/stories/chat/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ export const secondAuthor: ChatTypes.User = {
name: "Jane Smith"
};

const todayDate = new Date();

const date = new Date();
const yesterdayDate = date.setDate(date.getDate() - 1);

export const initialMessages: ChatTypes.Message[] = [
{
timestamp: "2024-10-01T10:15:30Z",
Expand Down Expand Up @@ -54,8 +59,18 @@ export const initialMessages: ChatTypes.Message[] = [
text: "I also want to get out into nature. Want to join me?"
},
{
timestamp: "2024-10-01T10:35:00Z",
timestamp: yesterdayDate,
author: secondAuthor,
text: "I'd love to! Just let me know when you're ready."
},
{
timestamp: todayDate,
author: firstAuthor,
text: "Great!"
},
{
timestamp: todayDate,
author: firstAuthor,
text: "Great! Looking forward to it!"
}
];
Loading