emoji.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import EmojiPicker, {
  2. Emoji,
  3. EmojiStyle,
  4. Theme as EmojiTheme,
  5. } from "emoji-picker-react";
  6. import { ModelType } from "../store";
  7. import BotIcon from "../icons/bot.svg";
  8. import BlackBotIcon from "../icons/black-bot.svg";
  9. export function getEmojiUrl(unified: string, style: EmojiStyle) {
  10. // Whoever owns this Content Delivery Network (CDN), I am using your CDN to serve emojis
  11. // Old CDN broken, so I had to switch to this one
  12. // Author: https://github.com/H0llyW00dzZ
  13. return `https://fastly.jsdelivr.net/npm/emoji-datasource-apple/img/${style}/64/${unified}.png`;
  14. }
  15. export function AvatarPicker(props: {
  16. onEmojiClick: (emojiId: string) => void;
  17. }) {
  18. return (
  19. <EmojiPicker
  20. width={"100%"}
  21. lazyLoadEmojis
  22. theme={EmojiTheme.AUTO}
  23. getEmojiUrl={getEmojiUrl}
  24. onEmojiClick={(e) => {
  25. props.onEmojiClick(e.unified);
  26. }}
  27. />
  28. );
  29. }
  30. export function Avatar(props: { model?: ModelType; avatar?: string }) {
  31. if (props.model) {
  32. return (
  33. <div className="no-dark">
  34. {props.model?.startsWith("gpt-4") ||
  35. props.model?.startsWith("chatgpt-4o") ||
  36. props.model?.startsWith("o1") ||
  37. props.model?.startsWith("o3") ? (
  38. <BlackBotIcon className="user-avatar" />
  39. ) : (
  40. <BotIcon className="user-avatar" />
  41. )}
  42. </div>
  43. );
  44. }
  45. return (
  46. <div className="user-avatar">
  47. {props.avatar && <EmojiAvatar avatar={props.avatar} />}
  48. </div>
  49. );
  50. }
  51. export function EmojiAvatar(props: { avatar: string; size?: number }) {
  52. return (
  53. <Emoji
  54. unified={props.avatar}
  55. size={props.size ?? 18}
  56. getEmojiUrl={getEmojiUrl}
  57. />
  58. );
  59. }