From 8567f9d4b85f1cb508e4bf3203b3d38048517518 Mon Sep 17 00:00:00 2001 From: Matchu Date: Thu, 14 Jan 2021 04:58:15 -0800 Subject: [PATCH] Try a grid-based view for item lists I took out virtualization for now too, I wanna see how this non-Chakra UI version, with fewer nodes and no tooltips etc, performs on large lists in production. --- package.json | 1 - src/app/UserItemsPage.js | 82 ++------------------- src/app/components/ItemCard.js | 130 +++++++++++++++++++++++++-------- yarn.lock | 30 -------- 4 files changed, 106 insertions(+), 137 deletions(-) diff --git a/package.json b/package.json index 6871719..0f06378 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,6 @@ "react-router-dom": "^5.1.2", "react-scripts": "^4.0.1", "react-transition-group": "^4.3.0", - "react-virtualized": "^9.22.2", "simple-markdown": "^0.7.2", "xmlrpc": "^1.3.2" }, diff --git a/src/app/UserItemsPage.js b/src/app/UserItemsPage.js index c1b4fed..9147a26 100644 --- a/src/app/UserItemsPage.js +++ b/src/app/UserItemsPage.js @@ -18,7 +18,6 @@ import { Wrap, WrapItem, VStack, - useBreakpointValue, useToast, } from "@chakra-ui/react"; import { @@ -32,19 +31,12 @@ import { import gql from "graphql-tag"; import { useHistory, useParams } from "react-router-dom"; import { useQuery, useLazyQuery, useMutation } from "@apollo/client"; -import { AutoSizer, Grid, WindowScroller } from "react-virtualized"; import SimpleMarkdown from "simple-markdown"; import DOMPurify from "dompurify"; import HangerSpinner from "./components/HangerSpinner"; import { Heading1, Heading2, Heading3 } from "./util"; -import ItemCard, { - ItemBadgeList, - ItemKindBadge, - YouOwnThisBadge, - YouWantThisBadge, - getZoneBadges, -} from "./components/ItemCard"; +import ItemCard from "./components/ItemCard"; import SupportOnly from "./WardrobePage/support/SupportOnly"; import useSupport from "./WardrobePage/support/useSupport"; import useCurrentUser from "./components/useCurrentUser"; @@ -467,24 +459,13 @@ function ClosetList({ closetList, isCurrentUser, showHeading }) { )} {sortedItems.length > 0 ? ( - + {sortedItems.map((item) => ( - - - {hasYouOwnThisBadge(item) && } - {hasYouWantThisBadge(item) && } - {getZoneBadges(item.allOccupiedZones, { - variant: "occupies", - })} - - } - /> + + + ))} - + ) : ( This list is empty! )} @@ -492,57 +473,6 @@ function ClosetList({ closetList, isCurrentUser, showHeading }) { ); } -function VirtualizedItemCardList({ children }) { - const columnCount = useBreakpointValue({ base: 1, md: 2, lg: 3 }); - const rowCount = Math.ceil(children.length / columnCount); - - return ( - - {({ width }) => ( - - {({ - height, - isScrolling, - onChildScroll, - scrollTop, - registerChild, - }) => ( - registerChild(el)} - > - ( - 0 ? "6" : "0"} - > - {children[rowIndex * columnCount + columnIndex]} - - )} - columnCount={columnCount} - columnWidth={width / columnCount} - rowCount={rowCount} - rowHeight={100} - width={width} - height={height} - autoHeight - isScrolling={isScrolling} - onScroll={onChildScroll} - scrollTop={scrollTop} - /> - - )} - - )} - - ); -} - const unsafeMarkdownRules = { autolink: SimpleMarkdown.defaultRules.autolink, br: SimpleMarkdown.defaultRules.br, diff --git a/src/app/components/ItemCard.js b/src/app/components/ItemCard.js index 29da926..1915425 100644 --- a/src/app/components/ItemCard.js +++ b/src/app/components/ItemCard.js @@ -16,31 +16,99 @@ import { Link } from "react-router-dom"; import { safeImageUrl, useCommonStyles } from "../util"; -function ItemCard({ item, badges, ...props }) { +function ItemCard({ item, badges, variant = "list", ...props }) { const { brightBackground } = useCommonStyles(); + const theme = useTheme(); - return ( - - - - ); + switch (variant) { + case "grid": + return ( + // ItemCard renders in large lists of 1k+ items, so we get a big perf + // win by using Emotion directly instead of Chakra's styled-system Box. + + {({ css }) => ( + +
+ {`Thumbnail +
+ {item.name} +
+
+ + )} +
+ ); + case "list": + return ( + + + + ); + default: + throw new Error(`Unexpected ItemCard variant: ${variant}`); + } } export function ItemCardContent({ @@ -53,13 +121,15 @@ export function ItemCardContent({ }) { return ( - - + + + +