ChatGPT-Next-Web/app/components/emoji.tsx

63 lines
1.5 KiB
TypeScript
Raw Normal View History

2023-04-22 17:27:15 +00:00
import EmojiPicker, {
Emoji,
EmojiStyle,
Theme as EmojiTheme,
} from "emoji-picker-react";
import { ModelType } from "../store";
import BotIcon from "../icons/bot.svg";
import BlackBotIcon from "../icons/black-bot.svg";
export function getEmojiUrl(unified: string, style: EmojiStyle) {
2023-12-25 19:44:40 +00:00
// Whoever owns this Content Delivery Network (CDN), I am using your CDN to serve emojis
// Old CDN broken, so I had to switch to this one
// Author: https://github.com/H0llyW00dzZ
return `https://cdn.jsdelivr.net/npm/emoji-datasource-apple/img/${style}/64/${unified}.png`;
2023-04-22 17:27:15 +00:00
}
export function AvatarPicker(props: {
onEmojiClick: (emojiId: string) => void;
}) {
return (
<EmojiPicker
lazyLoadEmojis
theme={EmojiTheme.AUTO}
getEmojiUrl={getEmojiUrl}
onEmojiClick={(e) => {
props.onEmojiClick(e.unified);
}}
/>
);
}
export function Avatar(props: { model?: ModelType; avatar?: string }) {
if (props.model) {
return (
<div className="no-dark">
{props.model?.startsWith("gpt-4") ? (
2023-04-25 18:02:46 +00:00
<BlackBotIcon className="user-avatar" />
2023-04-22 17:27:15 +00:00
) : (
2023-04-25 18:02:46 +00:00
<BotIcon className="user-avatar" />
2023-04-22 17:27:15 +00:00
)}
</div>
);
}
return (
2023-04-25 18:02:46 +00:00
<div className="user-avatar">
2023-04-22 17:27:15 +00:00
{props.avatar && <EmojiAvatar avatar={props.avatar} />}
</div>
);
}
export function EmojiAvatar(props: { avatar: string; size?: number }) {
return (
<Emoji
unified={props.avatar}
size={props.size ?? 18}
getEmojiUrl={getEmojiUrl}
/>
);
}