Skip to content

Commit c91d25c

Browse files
committed
implement list virtualization
1 parent 5777dc9 commit c91d25c

6 files changed

Lines changed: 41 additions & 10 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"react-spinners": "^0.10.4",
2828
"react-toggle": "^4.1.1",
2929
"react-tooltip": "^4.2.21",
30+
"react-virtuoso": "^2.16.3",
3031
"styled-components": "2",
3132
"timeago.js": "^4.0.2",
3233
"web-vitals": "^0.2.4"

public/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "Hackertab.dev",
33
"description": "The Developer’s Homepage",
4-
"version": "1.13.0",
4+
"version": "2.0.0",
55
"manifest_version": 2,
66
"chrome_url_overrides": {
77
"newtab": "index.html"

src/App.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ a {
333333
visibility: visible;
334334
}
335335

336-
.blockRow:not(:last-child) {
336+
.blockContent > div > div > div:not(:last-child), .blockRow:not(:last-child) {
337337
border-bottom: 1px solid var(--card-content-divider);
338338
}
339339

src/components/CardComponent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function CardComponent({ icon, title, children, fullBlock, link }) {
2222
</a>
2323
)}
2424
</div>
25-
<div className="blockContent scrollable">{children}</div>
25+
{children}
2626
</div>
2727
)
2828
}

src/components/ListComponent.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ import React, { useState, useEffect } from 'react'
22
import CarbonAd from './CarbonAd'
33
import { trackException } from '../utils/Analytics'
44
import Placeholder from './Placeholder'
5+
import { Virtuoso } from 'react-virtuoso'
6+
7+
function ListHeader(withAds) {
8+
if (!withAds) {
9+
return null
10+
}
11+
return <CarbonAd key={'carbonAd0'} />
12+
}
513

614
function ListComponent({ fetchData, refresh, renderItem, withAds, placeholder = <Placeholder /> }) {
715
const [items, setItems] = useState([])
@@ -34,13 +42,15 @@ function ListComponent({ fetchData, refresh, renderItem, withAds, placeholder =
3442
if (!items) {
3543
return
3644
}
37-
return items.map((item, index) => {
38-
let content = [renderItem(item, index)]
39-
if (withAds && index == 0) {
40-
content.unshift(<CarbonAd key={'carbonAd0'} />)
41-
}
42-
return content
43-
})
45+
46+
return (
47+
<Virtuoso
48+
className="blockContent scrollable"
49+
components={{ Header: () => ListHeader(withAds) }}
50+
data={items}
51+
itemContent={(index, item) => renderItem(item, index)}
52+
/>
53+
)
4454
}
4555

4656
function Placeholders() {

yarn.lock

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2168,6 +2168,18 @@
21682168
"@typescript-eslint/types" "4.8.1"
21692169
eslint-visitor-keys "^2.0.0"
21702170

2171+
"@virtuoso.dev/react-urx@^0.2.12":
2172+
version "0.2.13"
2173+
resolved "https://registry.yarnpkg.com/@virtuoso.dev/react-urx/-/react-urx-0.2.13.tgz#e2cfc42d259d2a002695e7517d34cb97b64ee9c4"
2174+
integrity sha512-MY0ugBDjFb5Xt8v2HY7MKcRGqw/3gTpMlLXId2EwQvYJoC8sP7nnXjAxcBtTB50KTZhO0SbzsFimaZ7pSdApwA==
2175+
dependencies:
2176+
"@virtuoso.dev/urx" "^0.2.13"
2177+
2178+
"@virtuoso.dev/urx@^0.2.12", "@virtuoso.dev/urx@^0.2.13":
2179+
version "0.2.13"
2180+
resolved "https://registry.yarnpkg.com/@virtuoso.dev/urx/-/urx-0.2.13.tgz#a65e7e8d923cb03397ac876bfdd45c7f71c8edf1"
2181+
integrity sha512-iirJNv92A1ZWxoOHHDYW/1KPoi83939o83iUBQHIim0i3tMeSKEh+bxhJdTHQ86Mr4uXx9xGUTq69cp52ZP8Xw==
2182+
21712183
"@webassemblyjs/ast@1.9.0":
21722184
version "1.9.0"
21732185
resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.9.0.tgz#bd850604b4042459a5a41cd7d338cbed695ed964"
@@ -9941,6 +9953,14 @@ react-transition-group@^4.3.0:
99419953
loose-envify "^1.4.0"
99429954
prop-types "^15.6.2"
99439955

9956+
react-virtuoso@^2.16.3:
9957+
version "2.16.3"
9958+
resolved "https://registry.yarnpkg.com/react-virtuoso/-/react-virtuoso-2.16.3.tgz#d45920d3f21507471636200bed8689b3d84fea64"
9959+
integrity sha512-FymNswwx9taZGHbnmgIWlvEp42DFHQG++r85JBRS5bKP7jAokSknlYJ6QwTdYcix7ShPsH3fKBlPl23RG/spIQ==
9960+
dependencies:
9961+
"@virtuoso.dev/react-urx" "^0.2.12"
9962+
"@virtuoso.dev/urx" "^0.2.12"
9963+
99449964
react@^17.0.1:
99459965
version "17.0.1"
99469966
resolved "https://registry.yarnpkg.com/react/-/react-17.0.1.tgz#6e0600416bd57574e3f86d92edba3d9008726127"

0 commit comments

Comments
 (0)