forked from input-output-hk/daedalus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request input-output-hk#2920 from input-output-hk/fix/ddw-…
…923-stake-pool-list-table-view-adjustments
- Loading branch information
Showing
15 changed files
with
125 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
source/renderer/app/components/staking/stake-pools/StakePoolsTableHeader.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import React from 'react'; | ||
import { observer } from 'mobx-react'; | ||
import classNames from 'classnames'; | ||
import { HeaderGroup } from 'react-table'; | ||
import { StakePoolsTableHeaderCell } from './StakePoolsTableHeaderCell'; | ||
import StakePool from '../../../domains/StakePool'; | ||
import { | ||
useInViewPort, | ||
StakePoolsOrder, | ||
StakePoolSortableProps, | ||
} from './hooks'; | ||
import styles from './StakePoolsTable.scss'; | ||
|
||
type Props = { | ||
headerGroups: HeaderGroup<StakePool>[]; | ||
stakePoolsOrder: StakePoolsOrder; | ||
stakePoolsSortBy: StakePoolSortableProps; | ||
onHandleSort: (name: string) => void; | ||
onTableHeaderMouseEnter: () => void; | ||
onTableHeaderMouseLeave: () => void; | ||
}; | ||
|
||
export const Component = ({ | ||
stakePoolsSortBy, | ||
stakePoolsOrder, | ||
headerGroups, | ||
onHandleSort, | ||
onTableHeaderMouseEnter, | ||
onTableHeaderMouseLeave, | ||
}: Props) => { | ||
const { setTargetRef, isInViewport } = useInViewPort(); | ||
|
||
return ( | ||
<> | ||
<div ref={setTargetRef} /> | ||
<div | ||
className={classNames( | ||
styles.thead, | ||
!isInViewport && styles.stickyHeader | ||
)} | ||
onMouseEnter={onTableHeaderMouseEnter} | ||
onMouseLeave={onTableHeaderMouseLeave} | ||
> | ||
{headerGroups.map((headerGroup) => ( | ||
/* eslint-disable-next-line react/jsx-key */ | ||
<div {...headerGroup.getHeaderGroupProps()} className={styles.tr}> | ||
{headerGroup.headers.map((column) => ( | ||
<StakePoolsTableHeaderCell | ||
{...column.getHeaderProps({ | ||
style: { width: undefined }, | ||
})} | ||
stakePoolsSortBy={stakePoolsSortBy} | ||
stakePoolsOrder={stakePoolsOrder} | ||
onHandleSort={onHandleSort} | ||
name={column.id} | ||
key={column.id} | ||
> | ||
{column.render('Header')} | ||
</StakePoolsTableHeaderCell> | ||
))} | ||
</div> | ||
))} | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export const StakePoolsTableHeader = observer(Component); |
1 change: 1 addition & 0 deletions
1
source/renderer/app/components/staking/stake-pools/hooks/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
source/renderer/app/components/staking/stake-pools/hooks/useInViewPort.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { useRef, useState, useCallback } from 'react'; | ||
|
||
export const useInViewPort = () => { | ||
const [isInViewport, setIsInViewport] = useState(true); | ||
const targetRef = useRef(null); | ||
const observerRef = useRef( | ||
new IntersectionObserver((entries) => { | ||
entries.forEach((entry) => { | ||
setIsInViewport(entry.isIntersecting); | ||
}); | ||
}) | ||
); | ||
|
||
// React will call the ref callback twice. Once when the component mounts and again when it unmounts. | ||
// https://reactjs.org/docs/hooks-faq.html#how-can-i-measure-a-dom-node | ||
const setTargetRef = useCallback((target: HTMLElement) => { | ||
if (targetRef.current) { | ||
observerRef.current.unobserve(targetRef.current); | ||
} | ||
|
||
if (target) { | ||
observerRef.current.observe(target); | ||
} | ||
|
||
targetRef.current = target; | ||
}, []); | ||
|
||
return { isInViewport, setTargetRef }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters