Skip to content

Commit

Permalink
Handle the promise of a subscription
Browse files Browse the repository at this point in the history
Signed-off-by: austin5219 <[email protected]>
  • Loading branch information
austin5219 committed Oct 17, 2024
1 parent 905fb28 commit 4070e08
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions ui/src/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,18 @@ export class App extends React.Component<
this.navigationManager = new NavigationManager(history);
this.navItems = navItems;
this.routes = routes;
this.popupPropsSubscription = null;
this.unauthorizedSubscription = null;
services.extensions.addEventListener('systemLevel', this.onAddSystemLevelExtension.bind(this));
}

public async componentDidMount() {
this.popupPropsSubscription = this.popupManager.popupProps.subscribe(popupProps => this.setState({popupProps}));
this.unauthorizedSubscription = this.subscribeUnauthorized();
this.popupManager.popupProps.subscribe(popupProps => this.setState({popupProps})).then((subscription) => {
this.popupPropsSubscription = subscription;
});
this.subscribeUnauthorized().then((subscription) => {
this.unauthorizedSubscription = subscription;
});
const authSettings = await services.authService.settings();
const {trackingID, anonymizeUsers} = authSettings.googleAnalytics || {trackingID: '', anonymizeUsers: true};
const {loggedIn, username} = await services.users.get();
Expand Down Expand Up @@ -151,8 +157,12 @@ export class App extends React.Component<
}

public componentWillUnmount() {
this.popupPropsSubscription.unsubscribe();
this.unauthorizedSubscription.unsubscribe();
if (this.popupPropsSubscription) {
this.popupPropsSubscription.unsubscribe();
}
if (this.unauthorizedSubscription) {
this.unauthorizedSubscription.unsubscribe();
}
}

public render() {
Expand Down

0 comments on commit 4070e08

Please sign in to comment.