From 6f501b0c7e445f8f88d3fa12fe1dcb432cccdc90 Mon Sep 17 00:00:00 2001 From: Lars Karlitski Date: Tue, 17 Oct 2017 17:39:48 +0200 Subject: [PATCH] Clean up StarterKit view And show the contents of `/etc/hostname` to make sure cockpit.js is loaded correctly. --- src/index.es6 | 17 ++++------------- src/{starter-kit-view.jsx => starter-kit.jsx} | 14 +++++++++----- 2 files changed, 13 insertions(+), 18 deletions(-) rename src/{starter-kit-view.jsx => starter-kit.jsx} (76%) diff --git a/src/index.es6 b/src/index.es6 index 0b43cdc..0285600 100644 --- a/src/index.es6 +++ b/src/index.es6 @@ -18,18 +18,9 @@ * along with Cockpit; If not, see . */ -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')); +}); diff --git a/src/starter-kit-view.jsx b/src/starter-kit.jsx similarity index 76% rename from src/starter-kit-view.jsx rename to src/starter-kit.jsx index 732744a..edbcf8d 100644 --- a/src/starter-kit-view.jsx +++ b/src/starter-kit.jsx @@ -17,21 +17,25 @@ * You should have received a copy of the GNU Lesser General Public License * along with Cockpit; If not, see . */ + +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?({this.props.title}):"Empty title"; return ( -
-

{title}

+
+

Starter Kit

- Some content + Running on {this.state.hostname}
);