Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

page.tsx 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. 'use client';
  2. import { useState } from 'react';
  3. import type { Chat } from '@/types/chat';
  4. import { Flex, Layout, Row, Col, Input, Space, Upload, Button } from 'antd';
  5. import PageTitle from '@/components/ui/PageTitle';
  6. import Navigation from '@/components/layout/Navigation'
  7. import { useParams } from 'next/navigation'
  8. import { useQuery } from '@tanstack/react-query';
  9. import { getChat } from '@/app/api/user/chatService';
  10. import { PaperClipOutlined, SendOutlined } from '@ant-design/icons'
  11. const ChatPage: React.FC = () => {
  12. const params = useParams()
  13. const chatID = Number(params.chatID);
  14. const { data: chat, error, isLoading } = useQuery<Chat | undefined>({
  15. queryKey: ["getChat"],
  16. queryFn: () => getChat(chatID)
  17. })
  18. const [enabled, setEnabled] = useState(false);
  19. if (isLoading) {
  20. return <p>Loading...</p>
  21. }
  22. if (error) {
  23. return <p>Loading...</p>
  24. }
  25. return (
  26. <Layout className="!w-full !max-w-[430px] !mx-auto !relative !bg-white">
  27. <Flex vertical className='!h-screen'>
  28. <Row>
  29. <Col span={24}>
  30. <PageTitle position='center' backButton={true}>{chat?.name}</PageTitle>
  31. <div className="bg-white shadow p-4 flex flex-row border-b-2">
  32. <div>
  33. <img
  34. src="/default-avatar.png"
  35. alt="Profile"
  36. className="w-15 h-15 rounded-full object-cover border"
  37. />
  38. </div>
  39. <div className='ps-2'>
  40. <p className="text-xl text-gray-500">{ }</p>
  41. <p className="text-md text-gray-500">{chat?.persona?.role}</p>
  42. </div>
  43. <div className='ps-2 flex flex-row gap-2 items-center ms-auto'>
  44. <span>Live</span>
  45. <button
  46. onClick={() => setEnabled(!enabled)}
  47. className={`w-12 h-6 flex items-center rounded-full p-1 transition-colors duration-300 ${enabled ? 'bg-blue-500' : 'bg-gray-300'
  48. }`}
  49. >
  50. <div
  51. className={`bg-white w-4 h-4 rounded-full shadow-md transform transition-transform duration-300 ${enabled ? 'translate-x-6' : 'translate-x-0'
  52. }`}
  53. />
  54. </button>
  55. <span>Offline</span>
  56. </div>
  57. </div>
  58. </Col>
  59. </Row>
  60. <Row className='flex-1 overflow-y-scroll overflow-x-hidden'>
  61. <Col span={24}>
  62. <Flex vertical className="!bg-white">
  63. {/* Chat messages */}
  64. <div className="flex-1 overflow-y-auto px-4 py-6 space-y-4">
  65. {chat?.chatList.map((msg, index) => (
  66. <div key={index}>
  67. <p className={`mb-1 text-gray-500 ${msg.self ? 'text-left' : 'text-right'}`}>
  68. {msg.self ? 'Visitor' : 'Ruccan Chat'}
  69. </p>
  70. <div className={`flex ${msg.self ? 'justify-start' : 'justify-end'}`}>
  71. <div className={`max-w-xs whitespace-pre-wrap px-4 py-2 rounded-lg text-sm ${msg.self ? 'bg-white text-gray-800 shadow' : 'bg-blue-500 text-white'}`}>
  72. {msg.text}
  73. <div className="text-[10px] mt-1 text-right opacity-70">
  74. {msg.time}
  75. </div>
  76. </div>
  77. </div>
  78. </div>
  79. ))}
  80. </div>
  81. </Flex>
  82. </Col>
  83. </Row>
  84. <div>
  85. <Flex vertical={false} className="!bg-gray-200 !p-4" align="center" justify="space-between">
  86. <Input.TextArea
  87. placeholder="Write a message"
  88. className='!bg-gray-200 !border-0 !text-black'
  89. autoSize={{ minRows: 1, maxRows: 4 }}
  90. style={{ color: 'black', fontSize: 20, resize: 'none', flex: 1 }}
  91. />
  92. <Space size="middle" className="!ps-3">
  93. <Upload showUploadList={false}>
  94. <Button
  95. icon={<PaperClipOutlined style={{ fontSize: 24 }} />}
  96. type="text"
  97. size="large"
  98. style={{ height: 28, width: 28, padding: 0 }}
  99. />
  100. </Upload>
  101. <Button
  102. icon={<SendOutlined style={{ fontSize: 24 }} />}
  103. type="text"
  104. size="large"
  105. style={{ height: 28, width: 28, padding: 0 }}
  106. />
  107. </Space>
  108. </Flex>
  109. <Navigation />
  110. </div>
  111. </Flex>
  112. </Layout>
  113. );
  114. };
  115. export default ChatPage;