This commit is contained in:
David Ralph
2021-01-16 22:43:46 +00:00
parent 0a735384df
commit 3ec5a2c199
32 changed files with 530 additions and 182 deletions

View File

@@ -35,8 +35,13 @@ export default class Addons extends React.PureComponent {
if (type === 'item') {
const installed = JSON.parse(localStorage.getItem('installed'));
const info = installed.find(i => i.name === data);
this.setState({
current_data: { type: type2, name: data, content: info },
current_data: {
type: type2,
name: data,
content: info
},
item_data: {
name: info.name,
author: info.author,
@@ -53,23 +58,40 @@ export default class Addons extends React.PureComponent {
document.getElementById('marketplace').style.display = 'block';
document.getElementById('item').style.display = 'none';
}
this.setState({ button: this.buttons.uninstall });
this.setState({
button: this.buttons.uninstall
});
}
manage(type, input) {
switch (type) {
case 'install': MarketplaceFunctions.install(input.type, input, true); break;
case 'uninstall': MarketplaceFunctions.uninstall(this.state.current_data.name, this.state.current_data.content.type); break;
default: break;
case 'install':
MarketplaceFunctions.install(input.type, input, true);
break;
case 'uninstall':
MarketplaceFunctions.uninstall(this.state.current_data.name, this.state.current_data.content.type);
break;
default:
break;
}
toast(this.props.toastLanguage[type + 'ed']);
let button = '';
if (type === 'install') button = this.buttons.uninstall;
this.setState({ button: button, installed: JSON.parse(localStorage.getItem('installed')) });
if (type === 'install'){
button = this.buttons.uninstall;
}
this.setState({
button: button,
installed: JSON.parse(localStorage.getItem('installed'))
});
}
componentDidMount() {
if (localStorage.getItem('animations') === 'true') document.getElementById('marketplace').classList.add('marketplaceanimation');
if (localStorage.getItem('animations') === 'true') {
document.getElementById('marketplace').classList.add('marketplaceanimation');
}
}
render() {

View File

@@ -44,12 +44,20 @@ export default class Marketplace extends React.PureComponent {
case 'seemore':
document.getElementById('marketplace').style.display = 'none';
document.getElementById('seemore').style.display = 'block';
this.setState({ see_more: this.state[type2], see_more_type: type2 });
this.setState({
see_more: this.state[type2],
see_more_type: type2
});
break;
case 'item':
let info;
try { info = await (await fetch(`${Constants.MARKETPLACE_URL}/item/${type2}/${data}`)).json(); }
catch (e) { return toast(this.props.toastLanguage.error); }
try {
info = await (await fetch(`${Constants.MARKETPLACE_URL}/item/${type2}/${data}`)).json();
} catch (e) {
return toast(this.props.toastLanguage.error);
}
this.setState({
current_data: { type: type2, name: data, content: info },
@@ -64,14 +72,22 @@ export default class Marketplace extends React.PureComponent {
});
let button = this.buttons.install;
const installed = JSON.parse(localStorage.getItem('installed'));
if (installed.some(item => item.name === data)) button = this.buttons.uninstall;
this.setState({ button: button });
if (installed.some(item => item.name === data)) {
button = this.buttons.uninstall;
}
this.setState({
button: button
});
document.getElementById('marketplace').style.display = 'none';
document.getElementById('seemore').style.display = 'none';
document.getElementById('item').style.display = 'block';
break;
default:
document.getElementById('marketplace').style.display = 'block';
document.getElementById('item').style.display = 'none';
@@ -83,6 +99,7 @@ export default class Marketplace extends React.PureComponent {
async getItems() {
const data = await (await fetch(Constants.MARKETPLACE_URL + '/all')).json();
const featured = await (await fetch(Constants.MARKETPLACE_URL + '/featured')).json();
this.setState({
settings: data.data.settings,
photo_packs: data.data.photo_packs,
@@ -95,10 +112,16 @@ export default class Marketplace extends React.PureComponent {
manage(type) {
switch (type) {
case 'install': MarketplaceFunctions.install(this.state.current_data.type, this.state.current_data.content.data); break;
case 'uninstall': MarketplaceFunctions.uninstall(this.state.current_data.content.data.name, this.state.current_data.type); break;
default: break;
case 'install':
MarketplaceFunctions.install(this.state.current_data.type, this.state.current_data.content.data);
break;
case 'uninstall':
MarketplaceFunctions.uninstall(this.state.current_data.content.data.name, this.state.current_data.type);
break;
default:
break;
}
toast(this.props.toastLanguage[type + 'ed']);
this.setState({
button: (type === 'install') ? this.buttons.uninstall : this.buttons.install
@@ -106,8 +129,14 @@ export default class Marketplace extends React.PureComponent {
}
componentDidMount() {
if (localStorage.getItem('animations') === 'true') document.getElementById('marketplace').classList.add('marketplaceanimation');
if (navigator.onLine === false) return;
if (localStorage.getItem('animations') === 'true') {
document.getElementById('marketplace').classList.add('marketplaceanimation');
}
if (navigator.onLine === false) {
return;
}
this.getItems();
}

View File

@@ -24,13 +24,19 @@ export default class Settings extends React.PureComponent {
if (document.getElementById('modal').classList.contains('dark')) { // Dark theme support for dropdowns
const choices = document.getElementsByClassName('choices');
for (let i = 0; i < choices.length; i++) choices[i].style.backgroundColor = '#2f3542';
for (let i = 0; i < choices.length; i++) {
choices[i].style.backgroundColor = '#2f3542';
}
}
}
settingsImport(e) {
const content = JSON.parse(e.target.result);
for (const key of Object.keys(content)) localStorage.setItem(key, content[key]);
for (const key of Object.keys(content)) {
localStorage.setItem(key, content[key]);
}
toast(this.props.toastLanguage.imported);
}