Options page cleanup + reset without form submit

This commit is contained in:
hensm
2019-02-15 08:23:56 +00:00
parent 48c5a21e98
commit 38f2cb6bd3
2 changed files with 34 additions and 24 deletions

View File

@@ -44,7 +44,8 @@ class App extends Component {
super(props); super(props);
this.state = { this.state = {
options: props.options hasLoaded: false
, options: null
, bridgeInfo: null , bridgeInfo: null
, platform: null , platform: null
, bridgeLoading: true , bridgeLoading: true
@@ -63,13 +64,21 @@ class App extends Component {
} }
async componentDidMount () { async componentDidMount () {
const { options } = await browser.storage.sync.get("options");
this.setState({
hasLoaded: true
, options
});
const bridgeInfo = await getBridgeInfo(); const bridgeInfo = await getBridgeInfo();
const platform = await browser.runtime.getPlatformInfo(); const platform = await browser.runtime.getPlatformInfo();
this.setState({ this.setState({
bridgeInfo bridgeInfo
, platform: platform.os , platform: platform.os
, bridgeLoading: false , bridgeLoading: false
}); })
} }
/** /**
@@ -83,11 +92,8 @@ class App extends Component {
handleReset () { handleReset () {
this.setState({ this.setState({
options: defaultOptions options: { ...defaultOptions }
}); });
// TODO: Propagate state properly
this.form.submit();
} }
async handleFormSubmit (ev) { async handleFormSubmit (ev) {
@@ -128,7 +134,9 @@ class App extends Component {
} catch (err) {} } catch (err) {}
} }
handleFormChange () { handleFormChange (ev) {
ev.preventDefault();
this.setState({ this.setState({
isFormValid: this.form.checkValidity() isFormValid: this.form.checkValidity()
}); });
@@ -168,6 +176,10 @@ class App extends Component {
} }
render () { render () {
if (!this.state.hasLoaded) {
return;
}
return ( return (
<div> <div>
<Bridge info={ this.state.bridgeInfo } <Bridge info={ this.state.bridgeInfo }
@@ -333,10 +345,6 @@ class App extends Component {
} }
(async () => { ReactDOM.render(
const { options } = await browser.storage.sync.get("options"); <App />
, document.querySelector("#root"));
ReactDOM.render(
<App options={options} />
, document.querySelector("#root"));
})()

View File

@@ -197,17 +197,19 @@ class App extends Component {
} }
render () { render () {
return do { if (!this.state.hasLoaded) {
if (this.state.hasLoaded) { return;
<Updater description={ this.state.description }
additionalDescription={ this.state.additionalDescription }
downloadTotal={ this.state.downloadTotal }
downloadCurrent={ this.state.downloadCurrent }
isDownloading={ this.state.isDownloading }
onCancel={ this.onCancel }
onInstall={ this.onInstall } />
}
} }
return (
<Updater description={ this.state.description }
additionalDescription={ this.state.additionalDescription }
downloadTotal={ this.state.downloadTotal }
downloadCurrent={ this.state.downloadCurrent }
isDownloading={ this.state.isDownloading }
onCancel={ this.onCancel }
onInstall={ this.onInstall } />
);
} }
} }