Skip to content

Commit 5d331b9

Browse files
committed
reverse virtuallist refactor
1 parent 4983475 commit 5d331b9

File tree

3 files changed

+23
-38
lines changed

3 files changed

+23
-38
lines changed

Diff for: packages/@uppy/dashboard/src/components/FileList.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { h } from 'preact'
22
import { useMemo } from 'preact/hooks'
3+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
4+
// @ts-ignore untyped
35
import VirtualList from '@uppy/utils/lib/VirtualList'
46
import FileItem from './FileItem/index.tsx'
57

Diff for: packages/@uppy/utils/src/VirtualList.tsx renamed to packages/@uppy/utils/src/VirtualList.jsx

+20-37
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
* - Tweaked styles for Uppy's Dashboard use case
2727
*/
2828

29-
import { h, Component } from 'preact'
30-
import type { HTMLAttributes } from 'preact/compat'
29+
import { h, Component } from 'preact'
3130

3231
const STYLE_INNER = {
3332
position: 'relative',
@@ -52,21 +51,8 @@ const STYLE_CONTENT = {
5251
overflow: 'visible',
5352
}
5453

55-
type Props<T> = Omit<HTMLAttributes<HTMLDivElement>, 'data'> & {
56-
data: T[]
57-
rowHeight: number
58-
renderRow: (item: T) => h.JSX.Element
59-
// eslint-disable-next-line react/require-default-props
60-
overscanCount?: number | undefined
61-
}
62-
63-
class VirtualList<T> extends Component<
64-
Props<T>,
65-
{ offset: number; height: number }
66-
> {
67-
focusElement: HTMLElement | null
68-
69-
constructor(props: Props<T>) {
54+
class VirtualList extends Component {
55+
constructor (props) {
7056
super(props)
7157

7258
// The currently focused node, used to retain focus when the visible rows change.
@@ -79,61 +65,58 @@ class VirtualList<T> extends Component<
7965
}
8066
}
8167

82-
componentDidMount(): void {
68+
componentDidMount () {
8369
this.resize()
8470
window.addEventListener('resize', this.handleResize)
8571
}
8672

8773
// TODO: refactor to stable lifecycle method
8874
// eslint-disable-next-line
89-
componentWillUpdate() {
90-
if (this.base!.contains(document.activeElement)) {
91-
this.focusElement = document.activeElement as HTMLElement
75+
componentWillUpdate () {
76+
if (this.base.contains(document.activeElement)) {
77+
this.focusElement = document.activeElement
9278
}
9379
}
9480

95-
componentDidUpdate(): void {
81+
componentDidUpdate () {
9682
// Maintain focus when rows are added and removed.
97-
if (
98-
this.focusElement &&
99-
this.focusElement.parentNode &&
100-
document.activeElement !== this.focusElement
101-
) {
102-
this.focusElement!.focus()
83+
if (this.focusElement && this.focusElement.parentNode
84+
&& document.activeElement !== this.focusElement) {
85+
this.focusElement.focus()
10386
}
10487
this.focusElement = null
10588
this.resize()
10689
}
10790

108-
componentWillUnmount(): void {
91+
componentWillUnmount () {
10992
window.removeEventListener('resize', this.handleResize)
11093
}
11194

112-
handleScroll = (): void => {
113-
this.setState({ offset: (this.base! as HTMLElement).scrollTop })
95+
handleScroll = () => {
96+
this.setState({ offset: this.base.scrollTop })
11497
}
11598

116-
handleResize = (): void => {
99+
handleResize = () => {
117100
this.resize()
118101
}
119102

120-
resize(): void {
103+
resize () {
121104
const { height } = this.state
122105

123-
if (height !== (this.base! as HTMLElement).offsetHeight) {
106+
if (height !== this.base.offsetHeight) {
124107
this.setState({
125-
height: (this.base! as HTMLElement).offsetHeight,
108+
height: this.base.offsetHeight,
126109
})
127110
}
128111
}
129112

130-
render({
113+
render ({
131114
data,
132115
rowHeight,
133116
renderRow,
134117
overscanCount = 10,
135118
...props
136-
}: Props<T>): h.JSX.Element {
119+
}) {
137120
const { offset, height } = this.state
138121
// first visible row index
139122
let start = Math.floor(offset / rowHeight)

Diff for: packages/@uppy/utils/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
"emitDeclarationOnly": false,
66
"noEmit": true,
77
},
8-
"include": ["src/*.ts", "src/*.tsx"],
8+
"include": ["src/*.ts"],
99
"references": [],
1010
}

0 commit comments

Comments
 (0)