122 lines
3.5 KiB
React
Raw Normal View History

2016-04-19 21:45:49 -04:00
import React from 'react';
import {IndexLink} from 'react-router';
2016-04-19 21:45:49 -04:00
import ModList from './Mods/ListMods.jsx';
import InstalledMods from './Mods/InstalledMods.jsx';
2016-05-12 20:33:53 -04:00
import ModPacks from './Mods/ModPacks.jsx'
2016-04-19 21:45:49 -04:00
class ModsContent extends React.Component {
constructor(props) {
super(props);
this.componentDidMount = this.componentDidMount.bind(this);
this.toggleMod = this.toggleMod.bind(this);
this.loadInstalledModList = this.loadInstalledModList.bind(this);
2016-05-12 20:33:53 -04:00
this.loadModPackList = this.loadModPackList.bind(this);
2016-04-19 21:45:49 -04:00
this.state = {
installedMods: [],
2016-05-12 20:33:53 -04:00
listMods: [],
modPacks: [],
2016-04-19 21:45:49 -04:00
};
}
componentDidMount() {
this.loadModList();
this.loadInstalledModList();
2016-05-12 20:33:53 -04:00
this.loadModPackList();
2016-04-19 21:45:49 -04:00
}
loadModList() {
$.ajax({
url: "/api/mods/list",
dataType: "json",
success: (data) => {
console.log(data)
if (data.success == true) {
this.setState({listMods: data.data.mods})
} else {
this.setState({listMods: []})
}
2016-04-19 21:45:49 -04:00
},
error: (xhr, status, err) => {
console.log('api/mods/list', status, err.toString());
}
});
}
loadInstalledModList() {
$.ajax({
url: "/api/mods/list/installed",
dataType: "json",
success: (data) => {
this.setState({installedMods: data.data})
2016-04-19 21:45:49 -04:00
},
error: (xhr, status, err) => {
console.log('api/mods/list', status, err.toString());
}
});
}
2016-05-12 20:33:53 -04:00
loadModPackList() {
$.ajax({
url: "/api/mods/packs/list",
dataType: "json",
success: (resp) => {
if (resp.success === true) {
this.setState({modPacks: resp.data})
console.log(this.state)
} else {
this.setState({modPacks: []})
}
}
})
}
2016-04-19 21:45:49 -04:00
toggleMod(modName) {
$.ajax({
url: "/api/mods/toggle/" + modName,
dataType: "json",
success: (data) => {
this.setState({listMods: data.data.mods})
2016-04-19 21:45:49 -04:00
},
error: (xhr, status, err) => {
console.log('api/mods/toggle', status, err.toString());
}
});
}
render() {
return(
<div className="content-wrapper">
<section className="content-header">
<h1>
Mods
<small>Manage your mods</small>
</h1>
<ol className="breadcrumb">
<li><IndexLink to="/"><i className="fa fa-dashboard fa-fw"></i>Server Control</IndexLink></li>
2016-04-19 21:45:49 -04:00
<li className="active">Here</li>
</ol>
</section>
<section className="content">
2016-04-19 21:45:49 -04:00
<InstalledMods
{...this.state}
loadInstalledModList={this.loadInstalledModList}
2016-04-19 21:45:49 -04:00
/>
<ModList
{...this.state}
toggleMod={this.toggleMod}
/>
2016-05-12 20:33:53 -04:00
<ModPacks
2016-05-13 23:48:39 -04:00
{...this.state}
loadModPackList={this.loadModPackList}
2016-05-12 20:33:53 -04:00
/>
2016-04-19 21:45:49 -04:00
</section>
</div>
)
}
}
export default ModsContent