From 9d7a84e43ed36a470beb19ee536373bf0e0d4443 Mon Sep 17 00:00:00 2001 From: Aurelien Benel Date: Sat, 27 Apr 2019 16:07:35 +0200 Subject: [PATCH] FIX: No manual refresh should be necessary on log in/out (#77). TODO: Still needs more refactoring to use React automatic update instead of ad hoc `_updateContent` method. --- src/sidebar/jsx/Authenticated.jsx | 8 +++++-- src/sidebar/jsx/Display.jsx | 39 ++++++++++++++++++++----------- src/sidebar/sidebar.jsx | 14 +++++------ 3 files changed, 38 insertions(+), 23 deletions(-) diff --git a/src/sidebar/jsx/Authenticated.jsx b/src/sidebar/jsx/Authenticated.jsx index 683338a..c6039d8 100644 --- a/src/sidebar/jsx/Authenticated.jsx +++ b/src/sidebar/jsx/Authenticated.jsx @@ -69,7 +69,8 @@ class Authenticated extends Component { password: this.password.value }) .then(() => { - this.setState({user}) + this.setState({user}); + this.props.onLogin({user}); }); } @@ -77,7 +78,10 @@ class Authenticated extends Component { browser.runtime.sendMessage({ aim:'closeSession' }) - .then(() => this.setState({user: ''})); + .then(() => { + this.setState({user: ''}); + this.props.onLogin({user: ''}); + }); } componentDidMount() { diff --git a/src/sidebar/jsx/Display.jsx b/src/sidebar/jsx/Display.jsx index 6dd0068..971c16a 100644 --- a/src/sidebar/jsx/Display.jsx +++ b/src/sidebar/jsx/Display.jsx @@ -1,24 +1,35 @@ /*global browser */ import React from 'react'; +import Authenticated from './Authenticated.jsx'; import Viewpoint from './Viewpoint.jsx'; import Topic from './Topic.jsx'; import ViewpointModel from '../../backgroundScripts/Viewpoint.js' export default class Display extends React.Component { - constructor(props) { - super(props); - this.state = {selectedViewpoint: null, viewpointName:''}; - browser.contextMenus.removeAll(); - this._deleteFrag=this._deleteFrag.bind(this); - this._createFrag=this._createFrag.bind(this); - this._moveFrag=this._moveFrag.bind(this); - this._contextMenuListener=this._contextMenuListener.bind(this); - this._handleBack = this._handleBack.bind(this); - this._handleCreateViewpoint = this._handleCreateViewpoint.bind(this); - this._handleViewpointName = this._handleViewpointName.bind(this); - this._renameTopic=this._renameTopic.bind(this); - } + constructor() { + super(); + this.state = { + selectedViewpoint: null, + viewpointName: '', + user: '' + }; + browser.contextMenus.removeAll(); + this._deleteFrag = this._deleteFrag.bind(this); + this._createFrag = this._createFrag.bind(this); + this._moveFrag = this._moveFrag.bind(this); + this._contextMenuListener = this._contextMenuListener.bind(this); + this._handleBack = this._handleBack.bind(this); + this._handleCreateViewpoint = this._handleCreateViewpoint.bind(this); + this._handleViewpointName = this._handleViewpointName.bind(this); + this._renameTopic = this._renameTopic.bind(this); + this._loginListener = this._loginListener.bind(this); + } + + _loginListener(user) { + this.setState({user}); + this.props.update(this.props.tabId, true); + } _contextMenuListener(info,tab) { if (info.menuItemId=="highlightnew" && this.state.selectedViewpoint) { @@ -43,6 +54,7 @@ export default class Display extends React.Component { let topics = this._getTopics(labels); return (
+

{vp.name}