Skip to content

Commit 30ea9cd

Browse files
authored
fix: Remove window.onscroll in Layout component (#549)
1 parent fb050c5 commit 30ea9cd

2 files changed

Lines changed: 2 additions & 37 deletions

File tree

src/components/Layout/SideNav/index.jsx

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ const changeKey = {
4545
class SideNav extends React.Component {
4646
static propTypes = {
4747
className: PropTypes.string,
48-
hasSubNav: PropTypes.bool,
49-
isScroll: PropTypes.bool
48+
hasSubNav: PropTypes.bool
5049
};
5150

5251
static defaultProps = {};
@@ -291,24 +290,6 @@ class SideNav extends React.Component {
291290
);
292291
}
293292

294-
renderHeader() {
295-
const { isScroll } = this.props;
296-
const { username } = this.props.user;
297-
298-
return (
299-
<div
300-
className={classnames(styles.header, {
301-
[styles.headerShadow]: isScroll
302-
})}
303-
>
304-
<Popover content={<MenuLayer />} className={styles.user}>
305-
{username}
306-
<Icon name="caret-down" className={styles.iconDark} type="dark" />
307-
</Popover>
308-
</div>
309-
);
310-
}
311-
312293
render() {
313294
const { hasSubNav, user } = this.props;
314295
const { isDev, isAdmin } = user;

src/components/Layout/index.jsx

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ class Layout extends Component {
4444
isHome: false
4545
};
4646

47-
state = {
48-
isScroll: false
49-
};
50-
5147
componentDidMount() {
5248
const { sock, listenToJob } = this.props;
5349

@@ -62,8 +58,6 @@ class Layout extends Component {
6258
...resource
6359
});
6460
});
65-
66-
window.onscroll = this.handleScroll;
6761
}
6862

6963
componentWillUnmount() {
@@ -72,17 +66,8 @@ class Layout extends Component {
7266
if (sock && !isEmpty(sock._events)) {
7367
sock._events = {};
7468
}
75-
76-
window.onscroll = null;
7769
}
7870

79-
handleScroll = async () => {
80-
const scrollTop = getScrollTop();
81-
scrollTop > 0
82-
? this.setState({ isScroll: true })
83-
: this.setState({ isScroll: false });
84-
};
85-
8671
goBack = () => {
8772
const { history } = this.props;
8873
history.goBack();
@@ -105,7 +90,6 @@ class Layout extends Component {
10590

10691
const { isNormal, isDev, isAdmin } = this.props.user;
10792
const hasMenu = (isDev || isAdmin) && !isHome;
108-
const { isScroll } = this.state;
10993
const paths = ['/dashboard', '/profile', '/ssh_keys', '/dev/apps'];
11094
const isCenterPage = Boolean(pageTitle); // detail page, only one level menu
11195
const hasSubNav = hasMenu && !isCenterPage && !paths.includes(match.path);
@@ -124,7 +108,7 @@ class Layout extends Component {
124108
{noNotification ? null : <Notification />}
125109
{backBtn}
126110

127-
{hasMenu && <SideNav isScroll={isScroll} hasSubNav={hasSubNav} />}
111+
{hasMenu && <SideNav hasSubNav={hasSubNav} />}
128112
{isNormal
129113
&& !isHome && <TitleBanner title={title} hasSearch={hasSearch} />}
130114

0 commit comments

Comments
 (0)