From 056b238462e936a5eaee6b57a98ae34d3a74b18a Mon Sep 17 00:00:00 2001 From: Matchu Date: Sat, 12 Sep 2020 18:32:06 -0700 Subject: [PATCH] better partial item data loading Here, we add loading skeletons to lots of individual elements, instead of doing a whole item placeholder skeleton. That helps when coming from pages where we have some data, like name and thumbnail, but things is isNc are still missing. --- src/app/ItemPage.js | 176 ++++++++++++++++++-------------------------- 1 file changed, 73 insertions(+), 103 deletions(-) diff --git a/src/app/ItemPage.js b/src/app/ItemPage.js index d0ebef3..85e3f57 100644 --- a/src/app/ItemPage.js +++ b/src/app/ItemPage.js @@ -12,7 +12,6 @@ import gql from "graphql-tag"; import { useQuery } from "@apollo/client"; import { useParams } from "react-router-dom"; -import HangerSpinner from "./components/HangerSpinner"; import { ItemBadgeList, ItemThumbnail, @@ -34,7 +33,7 @@ function ItemPage() { } function ItemPageHeader({ itemId }) { - const { loading, error, data } = useQuery( + const { error, data } = useQuery( gql` query ItemPage($itemId: ID!) { item(id: $itemId) { @@ -45,59 +44,16 @@ function ItemPageHeader({ itemId }) { } } `, - { variables: { itemId } } + { variables: { itemId }, returnPartialData: true } ); usePageTitle(data?.item?.name); - if (loading) { - return ( - - - - - - Item name goes here - - - - - - - - Old DTI - - - Jellyneo - - - Shop Wiz - - - Super Wiz - - - Trades - - - Auctions - - - - - ); - } - if (error) { return {error.message}; } - const { item } = data; + const item = data?.item; return ( - + + + - {item.name} + + {item?.name || "Item name here"} + @@ -122,61 +76,77 @@ function ItemPageHeader({ itemId }) { } function ItemPageBadges({ item }) { + const searchBadgesAreLoaded = item?.name != null && item?.isNc != null; + return ( - {item.isNc ? : } - - Old DTI - - - Jellyneo - - {!item.isNc && ( + + {item?.isNc ? : } + + + + Old DTI + + + - Shop Wiz + Jellyneo - )} - {!item.isNc && ( - - Trades - - )} - {!item.isNc && ( - - Auctions - - )} + + + {!item?.isNc && ( + + Shop Wiz + + )} + + + {!item?.isNc && ( + + Trades + + )} + + + {!item?.isNc && ( + + Auctions + + )} + ); }