index.tsx 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import React from 'react'
  2. import type { FC } from 'react'
  3. import { useTranslation } from 'react-i18next'
  4. import {
  5. ChatBubbleOvalLeftEllipsisIcon,
  6. PencilSquareIcon
  7. } from '@heroicons/react/24/outline'
  8. import { ChatBubbleOvalLeftEllipsisIcon as ChatBubbleOvalLeftEllipsisSolidIcon, } from '@heroicons/react/24/solid'
  9. import Button from '../../../base/button'
  10. // import Card from './card'
  11. import type { ConversationItem } from '@/models/share'
  12. function classNames(...classes: any[]) {
  13. return classes.filter(Boolean).join(' ')
  14. }
  15. const MAX_CONVERSATION_LENTH = 20
  16. export type ISidebarProps = {
  17. copyRight: string
  18. currentId: string
  19. onCurrentIdChange: (id: string) => void
  20. list: ConversationItem[]
  21. }
  22. const Sidebar: FC<ISidebarProps> = ({
  23. copyRight,
  24. currentId,
  25. onCurrentIdChange,
  26. list }) => {
  27. const { t } = useTranslation()
  28. return (
  29. <div
  30. className="shrink-0 flex flex-col overflow-y-auto bg-white pc:w-[244px] tablet:w-[192px] mobile:w-[240px] border-r border-gray-200 tablet:h-[calc(100vh_-_3rem)] mobile:h-screen"
  31. >
  32. {list.length < MAX_CONVERSATION_LENTH && (
  33. <div className="flex flex-shrink-0 p-4 !pb-0">
  34. <Button
  35. onClick={() => { onCurrentIdChange('-1') }}
  36. className="group block w-full flex-shrink-0 !justify-start !h-9 text-primary-600 items-center text-sm">
  37. <PencilSquareIcon className="mr-2 h-4 w-4" /> {t('share.chat.newChat')}
  38. </Button>
  39. </div>
  40. )}
  41. <nav className="mt-4 flex-1 space-y-1 bg-white p-4 !pt-0">
  42. {list.map((item) => {
  43. const isCurrent = item.id === currentId
  44. const ItemIcon
  45. = isCurrent ? ChatBubbleOvalLeftEllipsisSolidIcon : ChatBubbleOvalLeftEllipsisIcon
  46. return (
  47. <div
  48. onClick={() => onCurrentIdChange(item.id)}
  49. key={item.id}
  50. className={classNames(
  51. isCurrent
  52. ? 'bg-primary-50 text-primary-600'
  53. : 'text-gray-700 hover:bg-gray-100 hover:text-gray-700',
  54. 'group flex items-center rounded-md px-2 py-2 text-sm font-medium cursor-pointer',
  55. )}
  56. >
  57. <ItemIcon
  58. className={classNames(
  59. isCurrent
  60. ? 'text-primary-600'
  61. : 'text-gray-400 group-hover:text-gray-500',
  62. 'mr-3 h-5 w-5 flex-shrink-0',
  63. )}
  64. aria-hidden="true"
  65. />
  66. {item.name}
  67. </div>
  68. )
  69. })}
  70. </nav>
  71. <div className="flex flex-shrink-0 pr-4 pb-4 pl-4">
  72. <div className="text-gray-400 font-normal text-xs">© {copyRight} {(new Date()).getFullYear()}</div>
  73. </div>
  74. </div>
  75. )
  76. }
  77. export default React.memo(Sidebar)