chat.stories.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { useEffect } from 'react'
  2. import ChatPane from '../js/features/chat/components/chat-pane'
  3. import useFetchMock from './hooks/use-fetch-mock'
  4. import { generateMessages } from './fixtures/chat-messages'
  5. import { ScopeDecorator } from './decorators/scope'
  6. export const Conversation = args => {
  7. useFetchMock(fetchMock => {
  8. fetchMock.get(/messages/, generateMessages(35)).post(/messages/, {})
  9. })
  10. return <ChatPane {...args} />
  11. }
  12. export const NoMessages = args => {
  13. useFetchMock(fetchMock => {
  14. fetchMock.get(/messages/, [])
  15. })
  16. return <ChatPane {...args} />
  17. }
  18. export const Loading = args => {
  19. useFetchMock(fetchMock => {
  20. fetchMock.get(/messages/, generateMessages(6), {
  21. delay: 1000 * 10,
  22. })
  23. })
  24. return <ChatPane {...args} />
  25. }
  26. export const LoadingError = args => {
  27. useFetchMock(fetchMock => {
  28. fetchMock.get(/messages/, 500)
  29. })
  30. return <ChatPane {...args} />
  31. }
  32. export default {
  33. title: 'Editor / Chat',
  34. component: ChatPane,
  35. argTypes: {
  36. resetUnreadMessages: { action: 'resetUnreadMessages' },
  37. },
  38. args: {
  39. resetUnreadMessages: () => {},
  40. },
  41. decorators: [
  42. ScopeDecorator,
  43. Story => {
  44. useEffect(() => {
  45. window.MathJax = {
  46. Hub: {
  47. Queue: () => {},
  48. config: { tex2jax: { inlineMath: [['$', '$']] } },
  49. },
  50. }
  51. return () => {
  52. delete window.MathJax
  53. }
  54. }, [])
  55. return <Story />
  56. },
  57. ],
  58. }