Skip to content

Commit e38ac11

Browse files
author
Lucas Araujo
committed
[DDW-923] Check if header is stuck
1 parent 3c981a7 commit e38ac11

File tree

3 files changed

+54
-5
lines changed

3 files changed

+54
-5
lines changed

source/renderer/app/components/staking/stake-pools/StakePoolsTable.scss

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,18 @@
9999
thead {
100100
background: var(--theme-bordered-box-background-color);
101101
border-radius: 4px 4px 0 0;
102-
box-shadow: 0 10px 10px -10px rgba(0, 0, 0, 0.2);
103102
display: block;
104103
margin: -20px -20px 0;
105104
padding: 0 20px;
106105
position: sticky;
107106
top: 0;
107+
transition: box-shadow 0.3s ease-in-out;
108108
z-index: 999;
109109

110+
&.isHeaderStuck {
111+
box-shadow: 0 10px 10px -10px rgba(0, 0, 0, 0.2);
112+
}
113+
110114
tr {
111115
border: 0;
112116
display: flex;
@@ -144,7 +148,7 @@
144148
}
145149
}
146150

147-
tr {
151+
tr:not(:last-child) {
148152
border-bottom: 1px solid var(--theme-staking-table-border-color);
149153
}
150154

source/renderer/app/components/staking/stake-pools/StakePoolsTable.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import LoadingSpinner from '../../widgets/LoadingSpinner';
1010
import BorderedBox from '../../widgets/BorderedBox';
1111
import { StakePoolsTableHeader } from './StakePoolsTableHeader';
1212
import { StakePoolsTableBody } from './StakePoolsTableBody';
13+
import { InView } from '../../widgets/InView';
1314

1415
const messages = defineMessages({
1516
tableHeaderRank: {
@@ -152,11 +153,14 @@ type State = {
152153
isPreloading: boolean;
153154
stakePoolsOrder: string;
154155
stakePoolsSortBy: string;
156+
isHeaderStuck: boolean;
155157
};
156158
const initialState = {
157159
isPreloading: true,
158160
stakePoolsOrder: 'asc',
159161
stakePoolsSortBy: 'ranking',
162+
isHeaderStuck: false,
163+
isTest: true,
160164
};
161165

162166
@observer
@@ -176,10 +180,11 @@ class StakePoolsTable extends Component<Props, State> {
176180
componentDidMount() {
177181
this._isMounted = true;
178182
setTimeout(() => {
179-
if (this._isMounted)
183+
if (this._isMounted) {
180184
this.setState({
181185
isPreloading: false,
182186
});
187+
}
183188
}, 0);
184189
}
185190

@@ -215,11 +220,15 @@ class StakePoolsTable extends Component<Props, State> {
215220
listName,
216221
onSelect,
217222
selectedPoolId,
218-
currentLocale,
219223
onTableHeaderMouseEnter,
220224
onTableHeaderMouseLeave,
221225
} = this.props;
222-
const { isPreloading, stakePoolsSortBy, stakePoolsOrder } = this.state;
226+
const {
227+
isPreloading,
228+
stakePoolsSortBy,
229+
stakePoolsOrder,
230+
isHeaderStuck,
231+
} = this.state;
223232
const { intl } = this.context;
224233
const componentClasses = classNames([styles.component, listName]);
225234
if (stakePoolsList.length > PRELOADER_THRESHOLD && isPreloading)
@@ -375,8 +384,14 @@ class StakePoolsTable extends Component<Props, State> {
375384
<div className={componentClasses}>
376385
{sortedStakePoolList.length > 0 && (
377386
<BorderedBox>
387+
<InView
388+
onChange={(visible) =>
389+
this.setState({ isHeaderStuck: !visible })
390+
}
391+
/>
378392
<table>
379393
<thead
394+
className={isHeaderStuck ? styles.isHeaderStuck : ''}
380395
onMouseEnter={onTableHeaderMouseEnter}
381396
onMouseLeave={onTableHeaderMouseLeave}
382397
>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React, { useRef, useCallback } from 'react';
2+
3+
type Props = {
4+
onChange: (visible: boolean) => void;
5+
};
6+
7+
export const InView = ({ onChange }: Props) => {
8+
const elementRef = useRef(null);
9+
const observerRef = useRef(
10+
new IntersectionObserver((entries) => {
11+
entries.forEach((entry) => {
12+
onChange(entry.isIntersecting);
13+
});
14+
})
15+
);
16+
17+
const setElementRef = useCallback((element) => {
18+
if (elementRef.current) {
19+
observerRef.current.unobserve(elementRef.current);
20+
}
21+
22+
if (element) {
23+
observerRef.current.observe(element);
24+
}
25+
26+
elementRef.current = element;
27+
}, []);
28+
29+
return <div ref={setElementRef} />;
30+
};

0 commit comments

Comments
 (0)