BetterDiscordApp-rauenzi/src/ui/settings/themecard.js

73 lines
3.4 KiB
JavaScript
Raw Normal View History

2019-06-27 07:44:50 +02:00
import {React, Strings} from "modules";
import ReloadIcon from "../icons/reload";
2019-06-09 04:24:05 +02:00
// import Toasts from "../toasts";
2019-05-28 23:27:25 +02:00
2019-06-10 05:40:35 +02:00
export default class ThemeCard extends React.Component {
2019-05-28 20:19:48 +02:00
constructor(props) {
super(props);
this.state = {
2019-06-27 22:18:40 +02:00
checked: this.props.enabled,
2019-05-28 20:19:48 +02:00
reloads: 0
};
2019-06-09 04:24:05 +02:00
this.onChange = this.onChange.bind(this);
this.reload = this.reload.bind(this);
2019-05-28 20:19:48 +02:00
}
reload() {
if (!this.props.reload) return;
2019-06-27 22:18:40 +02:00
this.props.addon = this.props.reload(this.props.addon.id);
this.forceUpdate();
}
2019-05-28 20:19:48 +02:00
2019-06-26 21:23:07 +02:00
buildTitle(name, version, author) {
const title = Strings.Addons.title.split(/({{[A-Za-z]+}})/);
const nameIndex = title.findIndex(s => s == "{{name}}");
2019-06-27 22:18:40 +02:00
if (nameIndex) title[nameIndex] = React.createElement("span", {className: "bd-name"}, name);
2019-06-26 21:23:07 +02:00
const versionIndex = title.findIndex(s => s == "{{version}}");
2019-06-27 22:18:40 +02:00
if (nameIndex) title[versionIndex] = React.createElement("span", {className: "bd-version"}, version);
2019-06-26 21:23:07 +02:00
const authorIndex = title.findIndex(s => s == "{{author}}");
2019-06-27 22:18:40 +02:00
if (nameIndex) title[authorIndex] = React.createElement("span", {className: "bd-author"}, author);
2019-06-26 21:23:07 +02:00
return title.flat();
}
2019-05-28 20:19:48 +02:00
render() {
2019-06-27 22:18:40 +02:00
const {addon} = this.props;
const name = addon.name;
const description = addon.description;
const version = addon.version;
const author = addon.author;
const website = addon.website;
const source = addon.source;
2019-05-28 20:19:48 +02:00
2019-06-27 22:18:40 +02:00
return React.createElement("li", {"data-name": name, "data-version": version, "className": "settings-closed bd-switch-item"},
React.createElement("div", {className: "bd-header"},
React.createElement("span", {className: "bd-header-title"},
2019-06-26 21:23:07 +02:00
this.buildTitle(name, version, author)
2019-05-28 20:19:48 +02:00
),
2019-06-27 22:18:40 +02:00
React.createElement("div", {className: "bd-controls"},
2019-06-27 07:44:50 +02:00
this.props.showReloadIcon && React.createElement(ReloadIcon, {className: "bd-reload bd-reload-card", onClick: this.reload}),
2019-06-27 22:18:40 +02:00
React.createElement("label", {className: "bd-switch-wrapper bd-flex-child", style: {flex: "0 0 auto"}},
React.createElement("input", {checked: this.state.checked, onChange: this.onChange, className: "bd-switch-checkbox", type: "checkbox"}),
React.createElement("div", {className: this.state.checked ? "bd-switch checked" : "bd-switch"})
2019-05-28 20:19:48 +02:00
)
)
),
2019-06-27 22:18:40 +02:00
React.createElement("div", {className: "bd-description-wrap scroller-wrap fade"},
React.createElement("div", {className: "bd-description scroller"}, description)
2019-05-28 20:19:48 +02:00
),
2019-06-27 22:18:40 +02:00
(website || source) && React.createElement("div", {className: "bd-footer"},
React.createElement("span", {className: "bd-links"},
website && React.createElement("a", {className: "bd-link", href: website, target: "_blank"}, "Website"),
2019-05-28 20:19:48 +02:00
website && source && " | ",
2019-06-27 22:18:40 +02:00
source && React.createElement("a", {className: "bd-link", href: source, target: "_blank"}, "Source")
2019-05-28 20:19:48 +02:00
)
)
);
}
onChange() {
this.setState({checked: !this.state.checked});
2019-06-27 22:18:40 +02:00
this.props.onChange && this.props.onChange(this.props.addon.id);
2019-05-28 20:19:48 +02:00
}
}