settings.tsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. import { useState, useRef, useEffect } from "react";
  2. import EmojiPicker, { Emoji, Theme as EmojiTheme } from "emoji-picker-react";
  3. import styles from "./settings.module.scss";
  4. import ResetIcon from "../icons/reload.svg";
  5. import { List, ListItem, Popover } from "./ui-lib";
  6. import { IconButton } from "./button";
  7. import { SubmitKey, useChatStore, Theme } from "../store";
  8. import { Avatar } from "./home";
  9. import dynamic from "next/dynamic";
  10. export function Settings() {
  11. const [showEmojiPicker, setShowEmojiPicker] = useState(false);
  12. const [config, updateConfig, resetConfig] = useChatStore((state) => [
  13. state.config,
  14. state.updateConfig,
  15. state.resetConfig,
  16. ]);
  17. return (
  18. <>
  19. <div className={styles["window-header"]}>
  20. <div>
  21. <div className={styles["window-header-title"]}>设置</div>
  22. <div className={styles["window-header-sub-title"]}>设置选项</div>
  23. </div>
  24. <div className={styles["window-actions"]}>
  25. <div className={styles["window-action-button"]}>
  26. <IconButton
  27. icon={<ResetIcon />}
  28. onClick={resetConfig}
  29. bordered
  30. title="重置所有选项"
  31. />
  32. </div>
  33. </div>
  34. </div>
  35. <div className={styles["settings"]}>
  36. <List>
  37. <ListItem>
  38. <div className={styles["settings-title"]}>头像</div>
  39. <Popover
  40. onClose={() => setShowEmojiPicker(false)}
  41. content={
  42. <EmojiPicker
  43. lazyLoadEmojis
  44. theme={EmojiTheme.AUTO}
  45. onEmojiClick={(e) => {
  46. updateConfig((config) => (config.avatar = e.unified));
  47. setShowEmojiPicker(false);
  48. }}
  49. />
  50. }
  51. open={showEmojiPicker}
  52. >
  53. <div
  54. className={styles.avatar}
  55. onClick={() => setShowEmojiPicker(true)}
  56. >
  57. <Avatar role="user" />
  58. </div>
  59. </Popover>
  60. </ListItem>
  61. <ListItem>
  62. <div className={styles["settings-title"]}>发送键</div>
  63. <div className="">
  64. <select
  65. value={config.submitKey}
  66. onChange={(e) => {
  67. updateConfig(
  68. (config) =>
  69. (config.submitKey = e.target.value as any as SubmitKey)
  70. );
  71. }}
  72. >
  73. {Object.values(SubmitKey).map((v) => (
  74. <option value={v} key={v}>
  75. {v}
  76. </option>
  77. ))}
  78. </select>
  79. </div>
  80. </ListItem>
  81. <ListItem>
  82. <div className={styles["settings-title"]}>主题</div>
  83. <div className="">
  84. <select
  85. value={config.theme}
  86. onChange={(e) => {
  87. updateConfig(
  88. (config) => (config.theme = e.target.value as any as Theme)
  89. );
  90. }}
  91. >
  92. {Object.values(Theme).map((v) => (
  93. <option value={v} key={v}>
  94. {v}
  95. </option>
  96. ))}
  97. </select>
  98. </div>
  99. </ListItem>
  100. <ListItem>
  101. <div className={styles["settings-title"]}>紧凑边框</div>
  102. <input
  103. type="checkbox"
  104. checked={config.tightBorder}
  105. onChange={(e) =>
  106. updateConfig(
  107. (config) => (config.tightBorder = e.currentTarget.checked)
  108. )
  109. }
  110. ></input>
  111. </ListItem>
  112. </List>
  113. <List>
  114. <ListItem>
  115. <div className={styles["settings-title"]}>最大上下文消息数</div>
  116. <input
  117. type="range"
  118. title={config.historyMessageCount.toString()}
  119. value={config.historyMessageCount}
  120. min="5"
  121. max="20"
  122. step="5"
  123. onChange={(e) =>
  124. updateConfig(
  125. (config) =>
  126. (config.historyMessageCount = e.target.valueAsNumber)
  127. )
  128. }
  129. ></input>
  130. </ListItem>
  131. <ListItem>
  132. <div className={styles["settings-title"]}>
  133. 上下文中包含机器人消息
  134. </div>
  135. <input
  136. type="checkbox"
  137. checked={config.sendBotMessages}
  138. onChange={(e) =>
  139. updateConfig(
  140. (config) => (config.sendBotMessages = e.currentTarget.checked)
  141. )
  142. }
  143. ></input>
  144. </ListItem>
  145. </List>
  146. </div>
  147. </>
  148. );
  149. }