import classNames from "classnames"; import React from "react"; import { Component, ReactNode } from "react"; import { EndpointID } from "../../Service/Const"; import WKApp from "../../App"; import { Emoji, EmojiService } from "../../Service/EmojiService"; import ConversationContext from "../Conversation/context"; import "./index.css" import { LottieSticker } from "../../Messages/LottieSticker"; interface EmojiToolbarProps { conversationContext: ConversationContext icon: string } interface EmojiToolbarState { show: boolean animationStart: boolean } export default class EmojiToolbar extends Component{ constructor(props: any) { super(props) this.state = { show: false, animationStart: false, } } render(): ReactNode { const { show, animationStart } = this.state const { icon, conversationContext } = this.props return
{ this.setState({ show: !show, animationStart: true }) }}>
{ // this.setState({ // animationStart: false // }) if (!show) { this.setState({ animationStart: false, }) } }} className={classNames("wk-emojitoolbar-emojipanel", animationStart ? (show ? "wk-emojitoolbar-emojipanel-show" : "wk-emojitoolbar-emojipanel-hide") : undefined)}> { this.setState({ show: false }) const lottieSticker = new LottieSticker() lottieSticker.category = sticker.category lottieSticker.url = sticker.path lottieSticker.placeholder = sticker.placeholder lottieSticker.format = sticker.format conversationContext.sendMessage(lottieSticker) }} onEmoji={(emoji) => { this.setState({ show: false }) conversationContext.messageInputContext().insertText(emoji.key) }}>
{ show ?
{ this.setState({ show: false, }) }}>
: undefined }
} } interface EmojiPanelState { emojis: Emoji[] category: string stickers: any[] } interface EmojiPanelProps { onEmoji?: (emoji: Emoji) => void onSticker?: (sticker: any) => void } var stickerCategories = new Array() export class EmojiPanel extends Component { emojiService: EmojiService constructor(props: any) { super(props) this.emojiService = WKApp.endpointManager.invoke(EndpointID.emojiService) this.state = { emojis: [], category: "emoji", stickers: [] } } componentDidMount() { this.setState({ emojis: this.emojiService.getAllEmoji() }) this.requestStickerCategory() } requestStickerCategory() { if (!stickerCategories || stickerCategories.length === 0) { WKApp.dataSource.commonDataSource.userStickerCategory().then((result) => { stickerCategories = result this.setState({}) }) } } requestStickers(category: string) { WKApp.dataSource.commonDataSource.getStickers(category).then((result) => { this.setState({ stickers: result.list, }) }) } render(): React.ReactNode { const { emojis, category, stickers } = this.state const { onEmoji, onSticker } = this.props return
    { category === "emoji" ? emojis.map((emoji, i) => { return
  • { e.stopPropagation() if (onEmoji) { onEmoji(emoji) } }}> {/* */}
  • }) : undefined } { stickers && stickers.length > 0 && category !== "emoji" ? stickers.map((sticker) => { return
  • { e.stopPropagation() if (onSticker) { onSticker(sticker) } }}> {/* */}
  • }) : undefined }
{ e.stopPropagation() this.setState({ category: "emoji" }) }}>
{ stickerCategories.map((stickerCategory) => { return (
{ e.stopPropagation() const category: string = stickerCategory.category || "" this.setState({ category: category }) this.requestStickers(category) }}>
) }) }
} }