BetterDiscordApp-rauenzi/src/ui/emote.js

88 lines
3.4 KiB
JavaScript
Raw Normal View History

2019-06-24 21:47:24 +02:00
import {Settings, React, WebpackModules, Events} from "modules";
// import EmoteMenu from "../builtins/emotemenu";
2019-05-28 23:27:25 +02:00
const TooltipWrapper = WebpackModules.getByDisplayName("TooltipDeprecated");
2019-06-19 05:09:49 +02:00
export default class BDEmote extends React.Component {
2019-05-28 20:19:48 +02:00
constructor(props) {
super(props);
this.state = {
shouldAnimate: !this.animateOnHover,
2019-06-24 21:47:24 +02:00
isFavorite: this.props.isFavorite
2019-05-28 20:19:48 +02:00
};
this.onMouseEnter = this.onMouseEnter.bind(this);
this.onMouseLeave = this.onMouseLeave.bind(this);
this.onClick = this.onClick.bind(this);
}
get animateOnHover() {
2019-06-08 08:35:43 +02:00
return Settings.get("emotes", "general", "animateOnHover");
2019-05-28 20:19:48 +02:00
}
get label() {
return this.props.modifier ? `${this.props.name}:${this.props.modifier}` : this.props.name;
}
get modifierClass() {
return this.props.modifier ? ` emote${this.props.modifier}` : "";
}
onMouseEnter() {
if (!this.state.shouldAnimate && this.animateOnHover) this.setState({shouldAnimate: true});
2019-06-24 21:47:24 +02:00
// if (!this.state.isFavorite && EmoteMenu.favoriteEmotes[this.label]) this.setState({isFavorite: true});
// else if (this.state.isFavorite && !EmoteMenu.favoriteEmotes[this.label]) this.setState({isFavorite: false});
2019-05-28 20:19:48 +02:00
}
onMouseLeave() {
if (this.state.shouldAnimate && this.animateOnHover) this.setState({shouldAnimate: false});
}
onClick(e) {
if (this.props.onClick) this.props.onClick(e);
}
render() {
return React.createElement(TooltipWrapper, {
2019-05-28 20:19:48 +02:00
color: "black",
position: "top",
text: this.label,
delay: 750
},
2019-06-19 05:09:49 +02:00
React.createElement("div", {
2019-05-28 20:19:48 +02:00
className: "emotewrapper" + (this.props.jumboable ? " jumboable" : ""),
onMouseEnter: this.onMouseEnter,
onMouseLeave: this.onMouseLeave,
onClick: this.onClick
},
2019-06-19 05:09:49 +02:00
React.createElement("img", {
2019-05-28 20:19:48 +02:00
draggable: false,
className: "emote" + this.modifierClass + (this.props.jumboable ? " jumboable" : "") + (!this.state.shouldAnimate ? " stop-animation" : ""),
dataModifier: this.props.modifier,
alt: this.label,
src: this.props.url
}),
2019-06-19 05:09:49 +02:00
React.createElement("input", {
2019-05-28 20:19:48 +02:00
className: "fav" + (this.state.isFavorite ? " active" : ""),
title: "Favorite!",
type: "button",
onClick: (e) => {
e.preventDefault();
e.stopPropagation();
if (this.state.isFavorite) {
2019-06-24 21:47:24 +02:00
Events.emit("emotes-favorite-removed", this.label);
// delete EmoteMenu.favoriteEmotes[this.label];
// EmoteMenu.updateFavorites();
2019-05-28 20:19:48 +02:00
}
else {
2019-06-24 21:47:24 +02:00
Events.emit("emotes-favorite-added", this.label, this.props.url);
// EmoteMenu.favorite(this.label, this.props.url);
2019-05-28 20:19:48 +02:00
}
this.setState({isFavorite: !this.state.isFavorite});
}
})
)
);
}
}