2019-05-29 05:48:41 +02:00
|
|
|
import {SettingsCookie, ThemeCookie, Themes} from "data";
|
|
|
|
import {BDV2, Core, ThemeManager} from "modules";
|
2019-05-28 23:27:25 +02:00
|
|
|
import ReloadIcon from "../icons/reload";
|
|
|
|
|
2019-05-28 20:19:48 +02:00
|
|
|
export default class V2C_ThemeCard extends BDV2.reactComponent {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.setInitialState();
|
|
|
|
this.onChange = this.onChange.bind(this);
|
|
|
|
this.reload = this.reload.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
setInitialState() {
|
|
|
|
this.state = {
|
2019-05-29 05:48:41 +02:00
|
|
|
checked: ThemeCookie[this.props.theme.name],
|
2019-05-28 20:19:48 +02:00
|
|
|
reloads: 0
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// componentDidMount() {
|
|
|
|
// BDEvents.on("theme-reloaded", this.onReload);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// componentWillUnmount() {
|
|
|
|
// BDEvents.off("theme-reloaded", this.onReload);
|
|
|
|
// }
|
|
|
|
|
|
|
|
onReload(themeName) {
|
|
|
|
if (themeName !== this.props.theme.name) return;
|
|
|
|
this.setState({reloads: this.state.reloads + 1});
|
|
|
|
}
|
|
|
|
|
|
|
|
reload() {
|
|
|
|
const theme = this.props.theme.name;
|
2019-05-29 05:48:41 +02:00
|
|
|
const error = ThemeManager.reloadTheme(theme);
|
|
|
|
if (error) Core.showToast(`Could not reload ${Themes[theme].name}. Check console for details.`, {type: "error"});
|
|
|
|
else Core.showToast(`${Themes[theme].name} v${Themes[theme].version} has been reloaded.`, {type: "success"});
|
2019-05-28 20:19:48 +02:00
|
|
|
// this.setState(this.state);
|
2019-05-29 05:48:41 +02:00
|
|
|
this.props.theme = Themes[theme];
|
2019-05-28 20:19:48 +02:00
|
|
|
this.onReload(this.props.theme.name);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2019-05-29 06:50:26 +02:00
|
|
|
const {theme} = this.props;
|
|
|
|
const name = theme.name;
|
|
|
|
const description = theme.description;
|
|
|
|
const version = theme.version;
|
|
|
|
const author = theme.author;
|
|
|
|
const website = Themes[name].website;
|
|
|
|
const source = Themes[name].source;
|
2019-05-28 20:19:48 +02:00
|
|
|
|
|
|
|
return BDV2.react.createElement("li", {"data-name": name, "data-version": version, "className": "settings-closed ui-switch-item"},
|
|
|
|
BDV2.react.createElement("div", {className: "bda-header"},
|
|
|
|
BDV2.react.createElement("span", {className: "bda-header-title"},
|
|
|
|
BDV2.react.createElement("span", {className: "bda-name"}, name),
|
|
|
|
" v",
|
|
|
|
BDV2.react.createElement("span", {className: "bda-version"}, version),
|
|
|
|
" by ",
|
|
|
|
BDV2.react.createElement("span", {className: "bda-author"}, author)
|
|
|
|
),
|
|
|
|
BDV2.react.createElement("div", {className: "bda-controls"},
|
2019-05-29 05:48:41 +02:00
|
|
|
!SettingsCookie["fork-ps-5"] && BDV2.react.createElement(ReloadIcon, {className: "bd-reload-card", onClick: this.reload}),
|
2019-05-28 20:19:48 +02:00
|
|
|
BDV2.react.createElement("label", {className: "ui-switch-wrapper ui-flex-child", style: {flex: "0 0 auto"}},
|
|
|
|
BDV2.react.createElement("input", {checked: this.state.checked, onChange: this.onChange, className: "ui-switch-checkbox", type: "checkbox"}),
|
|
|
|
BDV2.react.createElement("div", {className: this.state.checked ? "ui-switch checked" : "ui-switch"})
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
BDV2.react.createElement("div", {className: "bda-description-wrap scroller-wrap fade"},
|
|
|
|
BDV2.react.createElement("div", {className: "bda-description scroller"}, description)
|
|
|
|
),
|
|
|
|
(website || source) && BDV2.react.createElement("div", {className: "bda-footer"},
|
|
|
|
BDV2.react.createElement("span", {className: "bda-links"},
|
|
|
|
website && BDV2.react.createElement("a", {className: "bda-link", href: website, target: "_blank"}, "Website"),
|
|
|
|
website && source && " | ",
|
|
|
|
source && BDV2.react.createElement("a", {className: "bda-link", href: source, target: "_blank"}, "Source")
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
onChange() {
|
|
|
|
this.setState({checked: !this.state.checked});
|
2019-05-29 05:48:41 +02:00
|
|
|
ThemeManager.toggleTheme(this.props.theme.name);
|
2019-05-28 20:19:48 +02:00
|
|
|
}
|
|
|
|
}
|