aboutsummaryrefslogtreecommitdiff
path: root/src/components/Feed/Feed.tsx
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2020-07-03 16:13:36 +0300
committereug-vs <eug-vs@keemail.me>2020-07-03 16:26:28 +0300
commitb9ab4b1c608c7022d15a264ec123f2c1a476c33d (patch)
tree0a01dbe3ba7a5450ad647fb92ff382969816037c /src/components/Feed/Feed.tsx
parentfc552cbf3ffcba6d2cc7003936f4b55378541525 (diff)
downloadwhich-ui-b9ab4b1c608c7022d15a264ec123f2c1a476c33d.tar.gz
feat: successfully virtualize list
Diffstat (limited to 'src/components/Feed/Feed.tsx')
-rw-r--r--src/components/Feed/Feed.tsx49
1 files changed, 37 insertions, 12 deletions
diff --git a/src/components/Feed/Feed.tsx b/src/components/Feed/Feed.tsx
index 7636573..785dd79 100644
--- a/src/components/Feed/Feed.tsx
+++ b/src/components/Feed/Feed.tsx
@@ -1,26 +1,51 @@
import React from 'react';
-import { makeStyles } from '@material-ui/core/styles';
import { Poll } from 'which-types';
import PollCard from '../PollCard/PollCard';
+import { WindowScroller, AutoSizer, List } from 'react-virtualized';
interface PropTypes {
polls: Poll[];
}
-const useStyles = makeStyles(theme => ({
- root: {
- position: 'relative',
- maxWidth: theme.spacing(75),
- margin: '0 auto'
- }
-}));
+interface RenderPropTypes {
+ index: number;
+ key: string;
+ style: React.CSSProperties;
+}
const Feed: React.FC<PropTypes> = ({ polls }) => {
- const classes = useStyles();
+
+ const RenderItem: React.FC<RenderPropTypes> = ({ index, style, key }) => {
+ const poll = polls[index];
+ return (
+ <div key={key} style={style}>
+ <PollCard initialPoll={poll} />
+ </div>
+ )
+ };
+
return (
- <div className={classes.root}>
- {polls.map(poll => <PollCard initialPoll={poll} key={poll._id} />)}
- </div>
+ <WindowScroller>
+ {({height, isScrolling, registerChild, onChildScroll, scrollTop}) => (
+ <AutoSizer disableHeight>
+ {({width}) => (
+ <div ref={registerChild}>
+ <List
+ autoHeight
+ height={height}
+ isScrolling={isScrolling}
+ onScroll={onChildScroll}
+ rowCount={polls.length}
+ rowHeight={600}
+ rowRenderer={RenderItem}
+ scrollTop={scrollTop}
+ width={width}
+ />
+ </div>
+ )}
+ </AutoSizer>
+ )}
+ </WindowScroller>
);
};