1
1
import React , { Component , Fragment } from "react" ;
2
2
import ReactDOM from "react-dom" ;
3
3
import { connect } from "react-redux" ;
4
+ import { TabIdentifierClient } from "chrome-tab-identifier" ;
4
5
5
6
import Toggler from "../../components/Toggler" ;
6
7
import Pane from "../../components/Pane" ;
@@ -17,9 +18,9 @@ import WebWorker from "./WebWorker";
17
18
import "./App.css" ;
18
19
19
20
const importFileIconCSS = `${ browserKey ( ) } -extension://${ chrome . i18n . getMessage (
20
- "@@extension_id"
21
+ "@@extension_id" ,
21
22
) } /libs/file-icons.css`;
22
-
23
+ const tabIdClient = new TabIdentifierClient ( ) ;
23
24
const parentDiv = document . querySelector ( "body" ) ;
24
25
25
26
class App extends Component {
@@ -29,6 +30,12 @@ class App extends Component {
29
30
firstPageLoad : true ,
30
31
reloading : true ,
31
32
showSearchbar : false ,
33
+ tabId : null ,
34
+ } ;
35
+ this . toggleOpenedThisTab = ( ) => {
36
+ this . props . toggleOpened ( {
37
+ tabId : this . state . tabId ,
38
+ } ) ;
32
39
} ;
33
40
this . setFirstPageLoad = ( firstPageLoad ) => {
34
41
this . setState ( { firstPageLoad } ) ;
@@ -49,50 +56,63 @@ class App extends Component {
49
56
}
50
57
51
58
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
+ } ) ;
57
64
}
58
65
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
+ }
64
82
}
65
83
}
66
84
67
85
render ( ) {
86
+ const { tabId } = this . state ;
87
+ if ( ! tabId ) return null ;
68
88
if ( ! this . shouldShowSpanTree ( ) ) {
69
- if ( this . props . opened ) this . props . toggleOpened ( ) ;
89
+ if ( this . props . opened [ tabId ] ) this . toggleOpenedThisTab ( ) ;
70
90
applyClosedPageStyling ( ) ;
71
91
return null ;
72
92
}
73
93
74
94
return (
75
95
< Fragment >
76
96
< link rel = "stylesheet" type = "text/css" href = { importFileIconCSS } />
77
- { this . props . opened
97
+ { this . props . opened [ tabId ]
78
98
? ReactDOM . createPortal (
79
99
< Pane
80
- toggleOpened = { this . props . toggleOpened }
100
+ toggleOpened = { this . toggleOpenedThisTab }
81
101
width = { this . props . width }
82
102
firstPageLoad = { this . state . firstPageLoad }
83
103
setFirstPageLoad = { this . setFirstPageLoad }
84
104
reloading = { this . state . reloading }
85
105
setReloading = { this . setReloading }
86
106
setShowSearchbarTrue = { ( ) => this . setShowSearchbar ( true ) }
87
107
/> ,
88
- parentDiv
108
+ parentDiv ,
89
109
)
90
110
: ReactDOM . createPortal (
91
111
< Toggler
92
- handleClick = { this . props . toggleOpened }
112
+ handleClick = { this . toggleOpenedThisTab }
93
113
pinned = { this . props . pinned }
94
114
/> ,
95
- document . getElementById ( "rcr-anchor" )
115
+ document . getElementById ( "rcr-anchor" ) ,
96
116
) }
97
117
< SearchBar
98
118
worker = { this . searchBarWorker }
0 commit comments