From f1d6a1fffcf31f09d22181f2138494df1d8d1cb6 Mon Sep 17 00:00:00 2001 From: Joel Denning Date: Tue, 13 Aug 2019 11:16:53 -0600 Subject: [PATCH] Automatically updating the UI when js api makes change to overrides. --- src/ui/full-ui.component.js | 7 +++++++ src/ui/list/list.component.js | 6 ++++++ src/ui/popup.component.js | 3 +++ 3 files changed, 16 insertions(+) diff --git a/src/ui/full-ui.component.js b/src/ui/full-ui.component.js index 5b5d049..1407ac7 100644 --- a/src/ui/full-ui.component.js +++ b/src/ui/full-ui.component.js @@ -5,6 +5,13 @@ export default class FullUI extends Component { state = { showingPopup: false }; + componentDidMount() { + window.addEventListener("import-map-overrides:change", this.doUpdate); + } + componentWillUnmount() { + window.removeEventListener("import-map-overrides:change", this.doUpdate); + } + doUpdate = () => this.forceUpdate(); render(props, state) { const shouldShow = !props.customElement.hasAttribute("show-when-local-storage") || diff --git a/src/ui/list/list.component.js b/src/ui/list/list.component.js index bd91bb0..337a972 100644 --- a/src/ui/list/list.component.js +++ b/src/ui/list/list.component.js @@ -32,6 +32,10 @@ export default class List extends Component { notOverriddenMapPromise.then(notOverriddenMap => { this.setState({ notOverriddenMap }); }); + window.addEventListener("import-map-overrides:change", this.doUpdate); + } + componentWillUnmount() { + window.removeEventListener("import-map-overrides:change", this.doUpdate); } componentDidUpdate(prevProps, prevState) { if (!prevState.dialogModule && this.state.dialogModule) { @@ -156,6 +160,8 @@ export default class List extends Component { this.setState({ dialogModule: null }); }; + doUpdate = () => this.forceUpdate(); + addNewModule = (name, url) => { if (name && url) { window.importMapOverrides.addOverride(name, url); diff --git a/src/ui/popup.component.js b/src/ui/popup.component.js index 6088a6b..0209d4e 100644 --- a/src/ui/popup.component.js +++ b/src/ui/popup.component.js @@ -4,10 +4,13 @@ import List from "./list/list.component"; export default class Popup extends Component { componentDidMount() { window.addEventListener("keydown", this.keydownListener); + window.addEventListener("import-map-overrides:change", this.doUpdate); } componentWillUnmount() { window.removeEventListener("keydown", this.keydownListener); + window.removeEventListener("import-map-overrides:change", this.doUpdate); } + doUpdate = () => this.forceUpdate(); render(props) { return (