-
Notifications
You must be signed in to change notification settings - Fork 279
/
Copy pathScreen.jsx
143 lines (130 loc) · 4.24 KB
/
Screen.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import React from 'react';
import { Helmet } from 'react-helmet';
import c from 'classnames';
import { Hotkeys, Hotkey } from '@blueprintjs/core';
// See @alxmiron at https://github.com/palantir/blueprint/issues/3604
import { HotkeysTarget } from '@blueprintjs/core/lib/esnext/components/hotkeys/hotkeysTarget.js';
import { compose } from 'redux';
import { connect } from 'react-redux';
import { withRouter } from 'react-router';
import AuthenticationDialog from 'src/dialogs/AuthenticationDialog/AuthenticationDialog';
import EntityPreview from 'src/components/Entity/EntityPreview';
import Navbar from 'src/components/Navbar/Navbar';
import Footer from 'src/components/Footer/Footer';
import SearchTips from 'src/components/SearchTips/SearchTips';
import { selectSession, selectMetadata } from 'src/selectors';
import './Screen.scss';
export class Screen extends React.Component {
constructor(props) {
super(props);
this.state = {
searchTipsOpen: false,
};
this.onToggleSearchTips = this.onToggleSearchTips.bind(this);
this.toggleAuthentication = this.toggleAuthentication.bind(this);
this.navbarRef = React.createRef();
}
componentDidMount() {
window.scrollTo(0, 0);
}
componentDidUpdate(prevProps) {
if (this.props.location && (this.props.location.pathname !== prevProps.location.pathname)) {
window.scrollTo(0, 0);
}
}
onToggleSearchTips() {
this.setState(({ searchTipsOpen }) => ({ searchTipsOpen: !searchTipsOpen }));
}
toggleAuthentication = event => event.preventDefault();
focusSearchBox = () => {
const searchBox = document.querySelector('#search-box');
if (searchBox) {
searchBox.focus();
}
}
renderHotkeys() {
const { hotKeys = [] } = this.props;
return (
<Hotkeys>
<Hotkey combo="/" label="Search" global onKeyUp={this.focusSearchBox} />
{hotKeys.map(hotKey => (
<Hotkey
key={hotKey.combo + hotKey.group}
{...hotKey}
/>
))}
</Hotkeys>
);
}
render() {
const {
session, metadata, query, requireSession,
isHomepage, title, description, className, searchScopes,
} = this.props;
const { searchTipsOpen } = this.state;
const hasMetadata = metadata && metadata.app && metadata.app.title;
const forceAuth = requireSession && !session.loggedIn;
const mainClass = isHomepage ? 'main-homepage' : 'main';
const titleTemplate = hasMetadata ? `%s - ${metadata.app.title}` : '%s';
const defaultTitle = hasMetadata ? metadata.app.title : 'Aleph';
return (
<div className={c('Screen', className)}>
<Helmet titleTemplate={titleTemplate} defaultTitle={defaultTitle}>
{ !!title && (
<title>{title}</title>
)}
{ !!description && (
<meta name="description" content={description} />
)}
{ !!metadata.app.favicon && (
<link rel="shortcut icon" href={metadata.app.favicon} />
)}
</Helmet>
<Navbar
navbarRef={this.navbarRef}
metadata={metadata}
session={session}
query={query}
isHomepage={isHomepage}
searchScopes={searchScopes}
onToggleSearchTips={this.onToggleSearchTips}
/>
{ (hasMetadata && !!metadata.app.banner) && (
<div className="app-banner bp3-callout bp3-intent-warning bp3-icon-warning-sign">
{metadata.app.banner}
</div>
)}
{!forceAuth && (
<>
<main className={mainClass}>
{this.props.children}
</main>
<EntityPreview />
</>
)}
{forceAuth && (
<AuthenticationDialog
auth={metadata.auth}
isOpen
toggleDialog={this.toggleAuthentication}
/>
)}
<SearchTips
isOpen={searchTipsOpen}
onToggle={this.onToggleSearchTips}
navbarRef={this.navbarRef}
/>
<Footer isHomepage={isHomepage} metadata={metadata} />
</div>
);
}
}
const mapStateToProps = state => ({
metadata: selectMetadata(state),
session: selectSession(state),
});
export default compose(
withRouter,
connect(mapStateToProps),
HotkeysTarget,
)(Screen);