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.
This commit is contained in:
Emi Matchu 2020-09-12 18:32:06 -07:00
parent 383d514397
commit 056b238462

View file

@ -12,7 +12,6 @@ import gql from "graphql-tag";
import { useQuery } from "@apollo/client"; import { useQuery } from "@apollo/client";
import { useParams } from "react-router-dom"; import { useParams } from "react-router-dom";
import HangerSpinner from "./components/HangerSpinner";
import { import {
ItemBadgeList, ItemBadgeList,
ItemThumbnail, ItemThumbnail,
@ -34,7 +33,7 @@ function ItemPage() {
} }
function ItemPageHeader({ itemId }) { function ItemPageHeader({ itemId }) {
const { loading, error, data } = useQuery( const { error, data } = useQuery(
gql` gql`
query ItemPage($itemId: ID!) { query ItemPage($itemId: ID!) {
item(id: $itemId) { item(id: $itemId) {
@ -45,59 +44,16 @@ function ItemPageHeader({ itemId }) {
} }
} }
`, `,
{ variables: { itemId } } { variables: { itemId }, returnPartialData: true }
); );
usePageTitle(data?.item?.name); usePageTitle(data?.item?.name);
if (loading) {
return (
<Box
display="flex"
alignItems="center"
justifyContent="flex-start"
width="100%"
>
<Skeleton height="80px" width="80px" marginRight="4" flex="0 0 auto" />
<Box display="flex" flexDirection="column" alignItems="flex-start">
<Skeleton>
<Heading1 lineHeight="1.1" maxHeight="1.1em">
Item name goes here
</Heading1>
</Skeleton>
<ItemBadgeList>
<Skeleton>
<NpBadge />
</Skeleton>
<Skeleton>
<LinkBadge href="/">Old DTI</LinkBadge>
</Skeleton>
<Skeleton>
<LinkBadge href="/">Jellyneo</LinkBadge>
</Skeleton>
<Skeleton>
<LinkBadge href="/">Shop Wiz</LinkBadge>
</Skeleton>
<Skeleton>
<LinkBadge href="/">Super Wiz</LinkBadge>
</Skeleton>
<Skeleton>
<LinkBadge href="/">Trades</LinkBadge>
</Skeleton>
<Skeleton>
<LinkBadge href="/">Auctions</LinkBadge>
</Skeleton>
</ItemBadgeList>
</Box>
</Box>
);
}
if (error) { if (error) {
return <Box color="red.400">{error.message}</Box>; return <Box color="red.400">{error.message}</Box>;
} }
const { item } = data; const item = data?.item;
return ( return (
<Box <Box
@ -106,15 +62,13 @@ function ItemPageHeader({ itemId }) {
justifyContent="flex-start" justifyContent="flex-start"
width="100%" width="100%"
> >
<ItemThumbnail <Skeleton isLoaded={item?.thumbnailUrl} marginRight="4">
item={item} <ItemThumbnail item={item} size="lg" isActive flex="0 0 auto" />
size="lg" </Skeleton>
isActive
marginRight="4"
flex="0 0 auto"
/>
<Box> <Box>
<Heading1 lineHeight="1.1">{item.name}</Heading1> <Skeleton isLoaded={item?.name}>
<Heading1 lineHeight="1.1">{item?.name || "Item name here"}</Heading1>
</Skeleton>
<ItemPageBadges item={item} /> <ItemPageBadges item={item} />
</Box> </Box>
</Box> </Box>
@ -122,61 +76,77 @@ function ItemPageHeader({ itemId }) {
} }
function ItemPageBadges({ item }) { function ItemPageBadges({ item }) {
const searchBadgesAreLoaded = item?.name != null && item?.isNc != null;
return ( return (
<ItemBadgeList> <ItemBadgeList>
{item.isNc ? <NcBadge /> : <NpBadge />} <Skeleton isLoaded={item?.isNc != null}>
<LinkBadge href={`https://impress.openneo.net/items/${item.id}`}> {item?.isNc ? <NcBadge /> : <NpBadge />}
Old DTI </Skeleton>
</LinkBadge> <Skeleton isLoaded={searchBadgesAreLoaded}>
<LinkBadge <LinkBadge href={`https://impress.openneo.net/items/${item.id}`}>
href={ Old DTI
"https://items.jellyneo.net/search/?name=" + </LinkBadge>
encodeURIComponent(item.name) + </Skeleton>
"&name_type=3" <Skeleton isLoaded={searchBadgesAreLoaded}>
}
>
Jellyneo
</LinkBadge>
{!item.isNc && (
<LinkBadge <LinkBadge
href={ href={
"http://www.neopets.com/market.phtml?type=wizard&string=" + "https://items.jellyneo.net/search/?name=" +
encodeURIComponent(item.name) encodeURIComponent(item.name) +
"&name_type=3"
} }
> >
Shop Wiz Jellyneo
</LinkBadge> </LinkBadge>
)} </Skeleton>
{!item.isNc && ( <Skeleton isLoaded={searchBadgesAreLoaded}>
<LinkBadge {!item?.isNc && (
href={ <LinkBadge
"http://www.neopets.com/portal/supershopwiz.phtml?string=" + href={
encodeURIComponent(item.name) "http://www.neopets.com/market.phtml?type=wizard&string=" +
} encodeURIComponent(item.name)
> }
Super Wiz >
</LinkBadge> Shop Wiz
)} </LinkBadge>
{!item.isNc && ( )}
<LinkBadge </Skeleton>
href={ <Skeleton isLoaded={searchBadgesAreLoaded}>
"http://www.neopets.com/island/tradingpost.phtml?type=browse&criteria=item_exact&search_string=" + {!item?.isNc && (
encodeURIComponent(item.name) <LinkBadge
} href={
> "http://www.neopets.com/portal/supershopwiz.phtml?string=" +
Trades encodeURIComponent(item.name)
</LinkBadge> }
)} >
{!item.isNc && ( Super Wiz
<LinkBadge </LinkBadge>
href={ )}
"http://www.neopets.com/genie.phtml?type=process_genie&criteria=exact&auctiongenie=" + </Skeleton>
encodeURIComponent(item.name) <Skeleton isLoaded={searchBadgesAreLoaded}>
} {!item?.isNc && (
> <LinkBadge
Auctions href={
</LinkBadge> "http://www.neopets.com/island/tradingpost.phtml?type=browse&criteria=item_exact&search_string=" +
)} encodeURIComponent(item.name)
}
>
Trades
</LinkBadge>
)}
</Skeleton>
<Skeleton isLoaded={searchBadgesAreLoaded}>
{!item?.isNc && (
<LinkBadge
href={
"http://www.neopets.com/genie.phtml?type=process_genie&criteria=exact&auctiongenie=" +
encodeURIComponent(item.name)
}
>
Auctions
</LinkBadge>
)}
</Skeleton>
</ItemBadgeList> </ItemBadgeList>
); );
} }