Skip to content

Commit

Permalink
Automatically updating the UI when js api makes change to overrides.
Browse files Browse the repository at this point in the history
  • Loading branch information
joeldenning committed Aug 13, 2019
1 parent 6363869 commit f1d6a1f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/ui/full-ui.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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") ||
Expand Down
6 changes: 6 additions & 0 deletions src/ui/list/list.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/ui/popup.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div className="imo-popup">
Expand Down

0 comments on commit f1d6a1f

Please sign in to comment.