11import React , { Component , Fragment } from "react" ;
22import ReactDOM from "react-dom" ;
33import { connect } from "react-redux" ;
4+ import { TabIdentifierClient } from "chrome-tab-identifier" ;
45
56import Toggler from "../../components/Toggler" ;
67import Pane from "../../components/Pane" ;
@@ -17,9 +18,9 @@ import WebWorker from "./WebWorker";
1718import "./App.css" ;
1819
1920const importFileIconCSS = `${ browserKey ( ) } -extension://${ chrome . i18n . getMessage (
20- "@@extension_id"
21+ "@@extension_id" ,
2122) } /libs/file-icons.css`;
22-
23+ const tabIdClient = new TabIdentifierClient ( ) ;
2324const parentDiv = document . querySelector ( "body" ) ;
2425
2526class App extends Component {
@@ -29,6 +30,12 @@ class App extends Component {
2930 firstPageLoad : true ,
3031 reloading : true ,
3132 showSearchbar : false ,
33+ tabId : null ,
34+ } ;
35+ this . toggleOpenedThisTab = ( ) => {
36+ this . props . toggleOpened ( {
37+ tabId : this . state . tabId ,
38+ } ) ;
3239 } ;
3340 this . setFirstPageLoad = ( firstPageLoad ) => {
3441 this . setState ( { firstPageLoad } ) ;
@@ -49,50 +56,63 @@ class App extends Component {
4956 }
5057
5158 componentDidMount ( ) {
52- if ( this . props . opened && this . shouldShowSpanTree ( ) ) {
53- applyOpenedPageStyling ( this . props . width ) ;
54- } else {
55- applyClosedPageStyling ( ) ;
56- }
59+ tabIdClient . getTabId ( ) . then ( ( tab ) => {
60+ this . setState ( {
61+ tabId : tab ,
62+ } ) ;
63+ } ) ;
5764 }
5865
59- componentDidUpdate ( _prevProps , _prevState ) {
60- if ( this . props . opened && this . shouldShowSpanTree ( ) ) {
61- applyOpenedPageStyling ( this . props . width ) ;
62- } else {
63- applyClosedPageStyling ( ) ;
66+ componentDidUpdate ( _prevProps , prevState ) {
67+ const { tabId } = this . state ;
68+ if ( tabId !== prevState . tabId ) {
69+ if ( this . props . opened [ tabId ] && this . shouldShowSpanTree ( ) ) {
70+ applyOpenedPageStyling ( this . props . width ) ;
71+ } else {
72+ applyClosedPageStyling ( ) ;
73+ }
74+ }
75+
76+ if ( tabId ) {
77+ if ( this . props . opened [ tabId ] && this . shouldShowSpanTree ( ) ) {
78+ applyOpenedPageStyling ( this . props . width ) ;
79+ } else {
80+ applyClosedPageStyling ( ) ;
81+ }
6482 }
6583 }
6684
6785 render ( ) {
86+ const { tabId } = this . state ;
87+ if ( ! tabId ) return null ;
6888 if ( ! this . shouldShowSpanTree ( ) ) {
69- if ( this . props . opened ) this . props . toggleOpened ( ) ;
89+ if ( this . props . opened [ tabId ] ) this . toggleOpenedThisTab ( ) ;
7090 applyClosedPageStyling ( ) ;
7191 return null ;
7292 }
7393
7494 return (
7595 < Fragment >
7696 < link rel = "stylesheet" type = "text/css" href = { importFileIconCSS } />
77- { this . props . opened
97+ { this . props . opened [ tabId ]
7898 ? ReactDOM . createPortal (
7999 < Pane
80- toggleOpened = { this . props . toggleOpened }
100+ toggleOpened = { this . toggleOpenedThisTab }
81101 width = { this . props . width }
82102 firstPageLoad = { this . state . firstPageLoad }
83103 setFirstPageLoad = { this . setFirstPageLoad }
84104 reloading = { this . state . reloading }
85105 setReloading = { this . setReloading }
86106 setShowSearchbarTrue = { ( ) => this . setShowSearchbar ( true ) }
87107 /> ,
88- parentDiv
108+ parentDiv ,
89109 )
90110 : ReactDOM . createPortal (
91111 < Toggler
92- handleClick = { this . props . toggleOpened }
112+ handleClick = { this . toggleOpenedThisTab }
93113 pinned = { this . props . pinned }
94114 /> ,
95- document . getElementById ( "rcr-anchor" )
115+ document . getElementById ( "rcr-anchor" ) ,
96116 ) }
97117 < SearchBar
98118 worker = { this . searchBarWorker }
0 commit comments