From a1d5669ac66952e3a647fa4d6e92d19b14f99c06 Mon Sep 17 00:00:00 2001 From: Matchu Date: Fri, 31 Jul 2020 23:40:05 -0700 Subject: [PATCH] split item query & colors query in Support UI My hope is that this can help with perf! The colors are very likely to be cached, and we don't need to re-request them from the server here! --- .../WardrobePage/support/ItemSupportDrawer.js | 56 +++++++++++++------ 1 file changed, 38 insertions(+), 18 deletions(-) diff --git a/src/app/WardrobePage/support/ItemSupportDrawer.js b/src/app/WardrobePage/support/ItemSupportDrawer.js index bd0849c..ecb2081 100644 --- a/src/app/WardrobePage/support/ItemSupportDrawer.js +++ b/src/app/WardrobePage/support/ItemSupportDrawer.js @@ -75,15 +75,9 @@ function ItemSupportDrawer({ item, isOpen, onClose }) { function SpecialColorFields({ item }) { const supportSecret = useSupportSecret(); - const { loading, error, data } = useQuery( + const { loading: itemLoading, error: itemError, data: itemData } = useQuery( gql` - query ItemSupportDrawerSpecialColorFields($itemId: ID!) { - allColors { - id - name - isStandard - } - + query ItemSupportDrawerManualSpecialColor($itemId: ID!) { item(id: $itemId) { manualSpecialColor { id @@ -94,9 +88,25 @@ function SpecialColorFields({ item }) { { variables: { itemId: item.id } } ); + const { + loading: colorsLoading, + error: colorsError, + data: colorsData, + } = useQuery( + gql` + query ItemSupportDrawerAllColors { + allColors { + id + name + isStandard + } + } + ` + ); + const [ mutate, - { loading: loading2, error: error2, data: data2 }, + { loading: mutationLoading, error: mutationError, data: mutationData }, ] = useMutation(gql` mutation ItemSupportDrawerSetManualSpecialColor( $itemId: ID! @@ -116,24 +126,29 @@ function SpecialColorFields({ item }) { } `); - const nonStandardColors = data?.allColors?.filter((c) => !c.isStandard) || []; + const nonStandardColors = + colorsData?.allColors?.filter((c) => !c.isStandard) || []; nonStandardColors.sort((a, b) => a.name.localeCompare(b.name)); return ( - + Special color - {error && {error.message}} - {error2 && {error2.message}} - {!error && ( + {colorsError && ( + {colorsError.message} + )} + {itemError && {itemError.message}} + {mutationError && ( + {mutationError.message} + )} + {!colorsError && !itemError && !mutationError && ( This controls which previews we show on the{" "}