emoji.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. <BlackBotIcon className="user-avatar" />
  38. ) : (
  39. <BotIcon className="user-avatar" />
  40. )}
  41. </div>
  42. );
  43. }
  44. return (
  45. <div className="user-avatar">
  46. {props.avatar && <EmojiAvatar avatar={props.avatar} />}
  47. </div>
  48. );
  49. }
  50. export function EmojiAvatar(props: { avatar: string; size?: number }) {
  51. return (
  52. <Emoji
  53. unified={props.avatar}
  54. size={props.size ?? 18}
  55. getEmojiUrl={getEmojiUrl}
  56. />
  57. );
  58. }