Commit 6314256e authored by Laurent Wouters's avatar Laurent Wouters
Browse files

[feature] Implementing the side bar

parent 44dd17a0ee5a
......@@ -24,9 +24,14 @@ import { definition } from "@logilab/libview";
import {
getViewRegistry,
getCurrentResource,
Message
Message,
getObservationsFor
} from "../common/messages";
import { ResourceData } from "../common/data";
import {
ResourceData,
DocumentObservations,
DocumentStatus
} from "../common/data";
import { ConfigLoading } from "../common/config/ConfigLoading";
import { CurrentTabDataSources } from "../common/config/CurrentTabDataSources";
import { CurrentTabViews } from "../common/config/CurrentTabViews";
......@@ -68,6 +73,7 @@ class Sidebar extends React.Component<{}, State> {
registry: null
};
this.onTabActivated = this.onTabActivated.bind(this);
this.onTabUpdated = this.onTabUpdated.bind(this);
this.reloadTabData = this.reloadTabData.bind(this);
// load for the current tab
getCurrentTabId().then((tabId: number) => {
......@@ -77,6 +83,7 @@ class Sidebar extends React.Component<{}, State> {
});
// listen for change of the current tab
chrome.tabs.onActivated.addListener(this.onTabActivated);
chrome.tabs.onUpdated.addListener(this.onTabUpdated);
// listen to messages
let self = this;
chrome.runtime.onMessage.addListener(
......@@ -101,13 +108,44 @@ class Sidebar extends React.Component<{}, State> {
this.reloadTabData(activeInfo.tabId);
}
onTabUpdated(
tabId: number,
changeInfo: chrome.tabs.TabChangeInfo,
tab: chrome.tabs.Tab
) {
if (this.state.tabId != tabId)
// not the currently selected tab
return;
this.state.pane = "loading";
this.setState(this.state);
this.reloadTabData(tabId);
}
reloadTabData(tabId: number) {
Promise.all([getCurrentResource(tabId), getViewRegistry()]).then(
(values: [ResourceData, definition.ViewRegistry]) => {
this.state.data = values[0];
this.state.registry = values[1];
this.state.pane = "main";
this.setState(this.state);
Promise.all([
getObservationsFor(tabId),
getCurrentResource(tabId),
getViewRegistry()
]).then(
(
values: [DocumentObservations, ResourceData, definition.ViewRegistry]
) => {
let observations = values[0];
if (observations.status != DocumentStatus.off) {
let data = values[1];
if (data == null) {
// wait till we have data
setTimeout(() => this.reloadTabData(tabId), 1000);
} else {
this.state.data = values[1];
this.state.registry = values[2];
this.state.pane = "main";
this.setState(this.state);
}
} else {
this.state.pane = "nodata";
this.setState(this.state);
}
}
);
}
......@@ -115,7 +153,11 @@ class Sidebar extends React.Component<{}, State> {
render() {
if (this.state.pane == "loading") {
return <ConfigLoading />;
} else if (this.state.data == null || this.state.data == undefined) {
} else if (
this.state.pane == "nodata" ||
this.state.data == null ||
this.state.data == undefined
) {
return (
<div
style={{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment