Clean up StarterKit view

And show the contents of `/etc/hostname` to make sure cockpit.js is
loaded correctly.
This commit is contained in:
Lars Karlitski 2017-10-17 17:39:48 +02:00 committed by Martin Pitt
parent ce7a2d3870
commit 8ff4b33bb5
2 changed files with 13 additions and 18 deletions

View file

@ -18,18 +18,9 @@
* along with Cockpit; If not, see <http://www.gnu.org/licenses/>.
*/
import 'cockpit';
import React from 'react';
import { StarterKit } from './starter-kit-view.jsx';
import { StarterKit } from './starter-kit.jsx';
function render() {
React.render(
React.createElement(
StarterKit,
{title: "Sample Page"}
),
document.getElementById('app')
);
}
document.addEventListener("DOMContentLoaded", render);
document.addEventListener("DOMContentLoaded", function () {
React.render(React.createElement(StarterKit, {}), document.getElementById('app'));
});

View file

@ -17,21 +17,25 @@
* You should have received a copy of the GNU Lesser General Public License
* along with Cockpit; If not, see <http://www.gnu.org/licenses/>.
*/
import 'cockpit';
import React from 'react';
export class StarterKit extends React.Component {
constructor() {
super();
// a good place to initialize this.state
cockpit.file('/etc/hostname').read().done((content) => {
this.setState({ 'hostname': content.trim() });
});
}
render() {
let title = this.props.title?(<a href="#">{this.props.title}</a>):"Empty title";
return (
<div class="container-fluid">
<h3>{title}</h3>
<div className="container-fluid">
<h2>Starter Kit</h2>
<div>
<span>Some content</span>
<span>Running on {this.state.hostname}</span>
</div>
</div>
);