Skip to content

Commit 50afdb5

Browse files
committed
(refs #1)Show tree of selected branch
1 parent bd1421f commit 50afdb5

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

scripts/components/Root.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,31 @@ export default class Root extends Directory {
88
// FIXME: exists altanarive way?
99
const baseUrl = document.querySelector('header.main-header a.logo').getAttribute('href');
1010
const relPath = document.location.pathname.replace(baseUrl, '');
11+
let rootPath;
12+
let branch;
13+
if (['tree', 'blob'].some(s => relPath.includes(`/${s}/`))) {
14+
const m = relPath.match(/(^\/?[^/]+\/[^/]+)\/(?:tree|blob)\/([^/]+)/);
15+
rootPath = m[1];
16+
branch = m[2];
17+
} else {
18+
rootPath = relPath.match(/^\/?[^/]+\/[^/]+/);
19+
branch = '';
20+
}
1121
this.setState({
12-
rootPath: `${baseUrl}${relPath.match(/^\/?[^/]+\/[^/]+/)}`,
22+
rootPath: `${baseUrl}${rootPath}`,
23+
branch,
1324
});
1425
}
1526

1627
getLocalStorageKey() {
17-
return this.state.rootPath;
28+
return `${this.state.rootPath}/${this.state.branch}`;
1829
}
1930

2031
render() {
2132
const arrow = this.state.expanded ? 'octicon octicon-chevron-down' : 'octicon octicon-chevron-right';
2233
return (
2334
<div className="tree-node">
24-
<button className="root-expander" onClick={() => this.toggleFolder(`${this.state.rootPath}/explore/`)} >
35+
<button className="root-expander" onClick={() => this.toggleFolder(`${this.state.rootPath}/explore/${this.state.branch}`)} >
2536
<i className={arrow} />
2637
</button>
2738
<a href={this.state.rootPath} className="submenu-files" >

0 commit comments

Comments
 (0)