index.tsx 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { TranscriptionIcon, AiIcon } from "@/components/icons"
  2. import { CloseOutlined } from "@ant-design/icons"
  3. import { RootState } from "@/store"
  4. import { useSelector, useDispatch } from "react-redux"
  5. import React, { useEffect, useMemo, useRef, useState } from "react"
  6. import { MenuType } from "@/types"
  7. import {
  8. setAIShow,
  9. setDialogRecordShow,
  10. removeMenuItem,
  11. addMenuItem,
  12. } from "@/store/reducers/global"
  13. import styles from "./index.module.scss"
  14. import { useTranslation } from "react-i18next"
  15. const MenuTitle = () => {
  16. const dispatch = useDispatch()
  17. const { t } = useTranslation()
  18. const menuList = useSelector((state: RootState) => state.global.menuList)
  19. const activeType = menuList[0]
  20. const TitleOneText = useMemo(() => {
  21. if (activeType == "AI") {
  22. return t("footer.aIAssistant")
  23. } else {
  24. return t("footer.conversationHistory")
  25. }
  26. }, [activeType])
  27. const onClickClose = (e: React.MouseEvent) => {
  28. e.stopPropagation()
  29. if (activeType === "AI") {
  30. dispatch(setAIShow(false))
  31. dispatch(removeMenuItem("AI"))
  32. } else {
  33. dispatch(setDialogRecordShow(false))
  34. dispatch(removeMenuItem("DialogRecord"))
  35. }
  36. }
  37. const onClickItem = (type: MenuType) => {
  38. dispatch(addMenuItem(type))
  39. }
  40. return (
  41. <div className={styles.title}>
  42. {menuList.length == 1 ? (
  43. <div className={styles.titleOne}>
  44. <TranscriptionIcon width={16} height={16}></TranscriptionIcon>
  45. <span className={styles.text}>{TitleOneText}</span>
  46. <CloseOutlined style={{ fontSize: "12px" }} onClick={onClickClose} />
  47. </div>
  48. ) : (
  49. <div className={styles.titleTwo}>
  50. <span
  51. className={`${styles.item} ${activeType == "DialogRecord" ? "active" : ""}`}
  52. onClick={() => onClickItem("DialogRecord")}
  53. >
  54. <TranscriptionIcon width={16} height={16}></TranscriptionIcon>
  55. <span className={styles.text}>{t("footer.conversationHistory")}</span>
  56. {activeType == "DialogRecord" ? (
  57. <CloseOutlined style={{ fontSize: "12px" }} onClick={onClickClose} />
  58. ) : null}
  59. </span>
  60. <span
  61. className={`${styles.item} ${activeType == "AI" ? "active" : ""}`}
  62. onClick={() => onClickItem("AI")}
  63. >
  64. <AiIcon width={16} height={16}></AiIcon>
  65. <span className={styles.text}>{t("footer.aIAssistant")}</span>
  66. {activeType == "AI" ? (
  67. <CloseOutlined style={{ fontSize: "12px" }} onClick={onClickClose} />
  68. ) : null}
  69. </span>
  70. </div>
  71. )}
  72. </div>
  73. )
  74. }
  75. export default MenuTitle