From 2debbed9d8795f53339af6d4ad06ab48ecbd6617 Mon Sep 17 00:00:00 2001 From: Jian Date: Tue, 19 May 2020 14:47:12 -0400 Subject: [PATCH 01/10] Add a use hook in ArtistAuctionResultItem to find out whether filter context has changed. --- .../Routes/AuctionResults/ArtistAuctionResultItem.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResultItem.tsx b/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResultItem.tsx index d6d0a34c26..f766265706 100644 --- a/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResultItem.tsx +++ b/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResultItem.tsx @@ -1,4 +1,4 @@ -import { Intent, ContextModule } from "@artsy/cohesion" +import { ContextModule, Intent } from "@artsy/cohesion" import { ArrowDownIcon, ArrowUpIcon, @@ -26,6 +26,9 @@ import { ImageWithFallback, renderFallbackImage, } from "./Components/ImageWithFallback" +import { useAuctionResultsFilterContext } from "./AuctionResultsFilterContext" +import { isEqual } from "lodash" +import { usePrevious } from "Utils/Hooks/usePrevious" export interface Props extends SystemContextProps { expanded?: boolean @@ -70,6 +73,10 @@ export const ArtistAuctionResultItem: SFC = props => { }) } + const filterContext = useAuctionResultsFilterContext() + const previousFilterContext = usePrevious(filterContext) + const filtersHaveUpdated = !isEqual(filterContext, previousFilterContext) + return ( <> @@ -300,6 +307,7 @@ const getProps = (props: Props) => { const renderPricing = (salePrice, saleDate, user, mediator, size) => { const textSize = size === "xs" ? "2" : "3t" + if (user) { const textAlign = size === "xs" ? "left" : "right" const dateOfSale = DateTime.fromISO(saleDate) From 219667ff54a6efce5d85d10f6823aedd3247ac41 Mon Sep 17 00:00:00 2001 From: Jian Date: Tue, 19 May 2020 19:45:07 -0400 Subject: [PATCH 02/10] Add filtersHaveUpdated to Props interface. Pass this Boolean all the way down to renderPricing so prices can be rendered on first load of app with no user logged in. --- .../ArtistAuctionResultItem.tsx | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResultItem.tsx b/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResultItem.tsx index f766265706..0cbb584e24 100644 --- a/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResultItem.tsx +++ b/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResultItem.tsx @@ -36,6 +36,7 @@ export interface Props extends SystemContextProps { index: number mediator?: Mediator lastChild: boolean + filtersHaveUpdated: boolean } const FullWidthBorderBox = styled(BorderBox)` @@ -87,6 +88,7 @@ export const ArtistAuctionResultItem: SFC = props => { expanded={expanded} mediator={mediator} user={user} + filtersHaveUpdated={filtersHaveUpdated} /> @@ -104,6 +106,7 @@ export const ArtistAuctionResultItem: SFC = props => { expanded={expanded} mediator={mediator} user={user} + filtersHaveUpdated={filtersHaveUpdated} /> @@ -190,7 +193,8 @@ const LargeAuctionItem: SFC = props => { saleDate, props.user, props.mediator, - "lg" + "lg", + props.filtersHaveUpdated )} @@ -228,7 +232,14 @@ const ExtraSmallAuctionItem: SFC = props => { )} - {renderPricing(salePrice, saleDate, props.user, props.mediator, "xs")} + {renderPricing( + salePrice, + saleDate, + props.user, + props.mediator, + "xs", + props.filtersHaveUpdated + )} {title} {title && date_text && ", "} @@ -305,10 +316,17 @@ const getProps = (props: Props) => { } } -const renderPricing = (salePrice, saleDate, user, mediator, size) => { +const renderPricing = ( + salePrice, + saleDate, + user, + mediator, + size, + filtersHaveUpdated +) => { const textSize = size === "xs" ? "2" : "3t" - if (user) { + if (user || !filtersHaveUpdated) { const textAlign = size === "xs" ? "left" : "right" const dateOfSale = DateTime.fromISO(saleDate) const now = DateTime.local() From aa0011b67be175daedb743563b4dc68aebcc92a9 Mon Sep 17 00:00:00 2001 From: Jian Date: Tue, 19 May 2020 19:47:28 -0400 Subject: [PATCH 03/10] Add filtersHaveUpdated. --- src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResults.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResults.tsx b/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResults.tsx index a859c73e4f..f092d8d6ce 100644 --- a/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResults.tsx +++ b/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResults.tsx @@ -2,7 +2,7 @@ import { Col, Row } from "@artsy/palette" import { ArtistAuctionResults_artist } from "__generated__/ArtistAuctionResults_artist.graphql" import { PaginationFragmentContainer as Pagination } from "Components/Pagination" import React, { useState } from "react" -import { createRefetchContainer, graphql, RelayRefetchProp } from "react-relay" +import { RelayRefetchProp, createRefetchContainer, graphql } from "react-relay" import useDeepCompareEffect from "use-deep-compare-effect" import { AuctionResultItemFragmentContainer as AuctionResultItem } from "./ArtistAuctionResultItem" import { TableSidebar } from "./Components/TableSidebar" @@ -154,6 +154,7 @@ const AuctionResultsContainer: React.FC = ({ index={index} auctionResult={node} lastChild={index === auctionResultsLength - 1} + filtersHaveUpdated={false} /> ) From 5f8b30de42b27cd9798e3bd0e7080bb0ea00077a Mon Sep 17 00:00:00 2001 From: Jian Date: Tue, 19 May 2020 21:51:30 -0400 Subject: [PATCH 04/10] test price shows on first load --- .../__tests__/AuctionResults.test.tsx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Apps/Artist/Routes/AuctionResults/__tests__/AuctionResults.test.tsx b/src/Apps/Artist/Routes/AuctionResults/__tests__/AuctionResults.test.tsx index d301de4d97..403f34e7f9 100644 --- a/src/Apps/Artist/Routes/AuctionResults/__tests__/AuctionResults.test.tsx +++ b/src/Apps/Artist/Routes/AuctionResults/__tests__/AuctionResults.test.tsx @@ -62,6 +62,12 @@ describe("AuctionResults", () => { expect(wrapper.html()).toContain("Showing 830 results") }) + it("renders either realized price or price not avail", () => { + expect(wrapper.html()).toContain( + "Price not available" || "Realized price" + ) + }) + it("renders proper select options", () => { const html = wrapper.find("SelectSmall").html() expect(html).toContain("Most recent") @@ -117,6 +123,17 @@ describe("AuctionResults", () => { }) ) }) + + it("re-shows sign up to see price", () => { + const pagination = wrapper.find("Pagination") + pagination + .find("button") + .at(2) + .simulate("click") + wrapper.update() + const html = wrapper.html() + expect(html).toContain("Sign up to see price") + }) }) describe("filters", () => { describe("medium filter", () => { From 9c14c8d6ac70bdfa303d2c728ced758b2a56e388 Mon Sep 17 00:00:00 2001 From: Jian Date: Wed, 20 May 2020 14:22:16 -0400 Subject: [PATCH 05/10] To show prices on default view. --- .../ArtistAuctionResultItem.tsx | 73 +++++++++++++++---- .../AuctionResults/ArtistAuctionResults.tsx | 5 ++ .../AuctionResultsFilterContext.tsx | 2 +- 3 files changed, 64 insertions(+), 16 deletions(-) diff --git a/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResultItem.tsx b/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResultItem.tsx index 0cbb584e24..518e832895 100644 --- a/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResultItem.tsx +++ b/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResultItem.tsx @@ -28,7 +28,7 @@ import { } from "./Components/ImageWithFallback" import { useAuctionResultsFilterContext } from "./AuctionResultsFilterContext" import { isEqual } from "lodash" -import { usePrevious } from "Utils/Hooks/usePrevious" +import { auctionResultsFilterResetState } from "./AuctionResultsFilterContext" export interface Props extends SystemContextProps { expanded?: boolean @@ -37,6 +37,7 @@ export interface Props extends SystemContextProps { mediator?: Mediator lastChild: boolean filtersHaveUpdated: boolean + paginationCount: number } const FullWidthBorderBox = styled(BorderBox)` @@ -74,9 +75,12 @@ export const ArtistAuctionResultItem: SFC = props => { }) } + // Is current filter state different from the default (reset) state? const filterContext = useAuctionResultsFilterContext() - const previousFilterContext = usePrevious(filterContext) - const filtersHaveUpdated = !isEqual(filterContext, previousFilterContext) + const filtersHaveUpdated = !isEqual( + filterContext.filters, + auctionResultsFilterResetState + ) return ( <> @@ -92,7 +96,12 @@ export const ArtistAuctionResultItem: SFC = props => { /> - {renderSmallCollapse({ ...props, expanded }, user, mediator)} + {renderSmallCollapse( + { ...props, expanded }, + user, + mediator, + filtersHaveUpdated + )} @@ -111,7 +120,12 @@ export const ArtistAuctionResultItem: SFC = props => { - {renderLargeCollapse({ ...props, expanded }, user, mediator)} + {renderLargeCollapse( + { ...props, expanded }, + user, + mediator, + filtersHaveUpdated + )} @@ -194,7 +208,8 @@ const LargeAuctionItem: SFC = props => { props.user, props.mediator, "lg", - props.filtersHaveUpdated + props.filtersHaveUpdated, + props.paginationCount )} @@ -238,7 +253,8 @@ const ExtraSmallAuctionItem: SFC = props => { props.user, props.mediator, "xs", - props.filtersHaveUpdated + props.filtersHaveUpdated, + props.paginationCount )} {title} @@ -322,11 +338,16 @@ const renderPricing = ( user, mediator, size, - filtersHaveUpdated + filtersHaveUpdated, + paginationCount ) => { const textSize = size === "xs" ? "2" : "3t" - if (user || !filtersHaveUpdated) { + // If user is logged in we show prices. Otherwise we show prices only for the default view - on page 1 and filters not changed. + // Ideally we get current page number fomr filter context 'page' property but somehow it is always '1'. + // So we resort to pagination count. If user has paginated at all, prices will be hidden. even if user comes back to page 1. + // TODO: Fix filter context so its 'page' property has the current page number, then change this code. + if (user || (!filtersHaveUpdated && paginationCount == 0)) { const textAlign = size === "xs" ? "left" : "right" const dateOfSale = DateTime.fromISO(saleDate) const now = DateTime.local() @@ -422,9 +443,17 @@ const renderEstimate = (estimatedPrice, user, mediator, size) => { } } -const renderRealizedPrice = (estimatedPrice, user, mediator, size) => { +const renderRealizedPrice = ( + estimatedPrice, + user, + mediator, + size, + filtersHaveUpdated, + paginationCount +) => { const justifyContent = size === "xs" ? "flex-start" : "flex-end" - if (user) { + // Show prices if user is logged in. Also show prices if user is at the first view - filters and pagination at default. + if (user || (!filtersHaveUpdated && paginationCount == 0)) { return ( {estimatedPrice && ( @@ -458,7 +487,7 @@ const renderRealizedPrice = (estimatedPrice, user, mediator, size) => { } } -const renderLargeCollapse = (props, user, mediator) => { +const renderLargeCollapse = (props, user, mediator, filtersHaveUpdated) => { const { expanded, auctionResult: { @@ -529,7 +558,14 @@ const renderLargeCollapse = (props, user, mediator) => { - {renderRealizedPrice(salePrice, user, mediator, "lg")} + {renderRealizedPrice( + salePrice, + user, + mediator, + "lg", + filtersHaveUpdated, + props.paginationCount + )} @@ -552,7 +588,7 @@ const renderLargeCollapse = (props, user, mediator) => { ) } -const renderSmallCollapse = (props, user, mediator) => { +const renderSmallCollapse = (props, user, mediator, filtersHaveUpdated) => { const { expanded, auctionResult: { @@ -609,7 +645,14 @@ const renderSmallCollapse = (props, user, mediator) => { - {renderRealizedPrice(salePrice, user, mediator, "xs")} + {renderRealizedPrice( + salePrice, + user, + mediator, + "xs", + filtersHaveUpdated, + props.paginationCount + )} diff --git a/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResults.tsx b/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResults.tsx index f092d8d6ce..1d27683bad 100644 --- a/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResults.tsx +++ b/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResults.tsx @@ -50,6 +50,9 @@ const AuctionResultsContainer: React.FC = ({ allowEmptyCreatedDates, } = filterContext.filters + // Count number of times user paginated. + const [paginationCount, incrementPaginationCount] = useState(0) + const loadNext = () => { const { hasNextPage, endCursor } = pageInfo @@ -60,6 +63,7 @@ const AuctionResultsContainer: React.FC = ({ const loadAfter = cursor => { setIsLoading(true) + incrementPaginationCount(paginationCount + 1) relay.refetch( { @@ -155,6 +159,7 @@ const AuctionResultsContainer: React.FC = ({ auctionResult={node} lastChild={index === auctionResultsLength - 1} filtersHaveUpdated={false} + paginationCount={paginationCount} /> ) diff --git a/src/Apps/Artist/Routes/AuctionResults/AuctionResultsFilterContext.tsx b/src/Apps/Artist/Routes/AuctionResults/AuctionResultsFilterContext.tsx index cf96ba6cb6..d39f65b958 100644 --- a/src/Apps/Artist/Routes/AuctionResults/AuctionResultsFilterContext.tsx +++ b/src/Apps/Artist/Routes/AuctionResults/AuctionResultsFilterContext.tsx @@ -71,7 +71,7 @@ export type SharedAuctionResultsFilterContextProps = Pick< onChange?: (filterState) => void } -let auctionResultsFilterResetState: AuctionResultsFilters = initialAuctionResultsFilterState +export let auctionResultsFilterResetState: AuctionResultsFilters = initialAuctionResultsFilterState export const AuctionResultsFilterContextProvider: React.FC Date: Wed, 20 May 2020 14:25:47 -0400 Subject: [PATCH 06/10] re-word --- .../Artist/Routes/AuctionResults/ArtistAuctionResultItem.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResultItem.tsx b/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResultItem.tsx index 518e832895..04a8c3c2b0 100644 --- a/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResultItem.tsx +++ b/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResultItem.tsx @@ -344,7 +344,7 @@ const renderPricing = ( const textSize = size === "xs" ? "2" : "3t" // If user is logged in we show prices. Otherwise we show prices only for the default view - on page 1 and filters not changed. - // Ideally we get current page number fomr filter context 'page' property but somehow it is always '1'. + // Ideally we get current page number from filter context 'page' property but somehow it is always '1'. // So we resort to pagination count. If user has paginated at all, prices will be hidden. even if user comes back to page 1. // TODO: Fix filter context so its 'page' property has the current page number, then change this code. if (user || (!filtersHaveUpdated && paginationCount == 0)) { @@ -452,7 +452,7 @@ const renderRealizedPrice = ( paginationCount ) => { const justifyContent = size === "xs" ? "flex-start" : "flex-end" - // Show prices if user is logged in. Also show prices if user is at the first view - filters and pagination at default. + // Show prices if user is logged in. Otherwise, show prices only on default view - filters at default and no pagination has happened. if (user || (!filtersHaveUpdated && paginationCount == 0)) { return ( From 56aaa69b5b6f6e7826d526bf6b8f97ca1db7b656 Mon Sep 17 00:00:00 2001 From: Jian Date: Wed, 20 May 2020 15:22:54 -0400 Subject: [PATCH 07/10] Pagination and filter tests to confirm that sign-up-to-see-price is shown again. --- .../__tests__/AuctionResults.test.tsx | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/src/Apps/Artist/Routes/AuctionResults/__tests__/AuctionResults.test.tsx b/src/Apps/Artist/Routes/AuctionResults/__tests__/AuctionResults.test.tsx index 403f34e7f9..5f06c41e29 100644 --- a/src/Apps/Artist/Routes/AuctionResults/__tests__/AuctionResults.test.tsx +++ b/src/Apps/Artist/Routes/AuctionResults/__tests__/AuctionResults.test.tsx @@ -137,7 +137,7 @@ describe("AuctionResults", () => { }) describe("filters", () => { describe("medium filter", () => { - it("triggers relay refetch with medium list", done => { + it("triggers relay refetch with medium list, and re-shows sign up to see price", done => { const filter = wrapper.find("MediumFilter") const checkboxes = filter.find("Checkbox") @@ -188,13 +188,17 @@ describe("AuctionResults", () => { allowEmptyCreatedDates: true, }, }) + + wrapper.update() + const html = wrapper.html() + expect(html).toContain("Sign up to see price") + done() }) }) }) describe("auction house filter", () => { - // TODO: Re-enable once we uncollapse auction house filters - it.skip("triggers relay refetch with organization list", done => { + it("triggers relay refetch with organization list, and re-shows sign up to see price", done => { const filter = wrapper.find("AuctionHouseFilter") const checkboxes = filter.find("Checkbox") @@ -226,12 +230,17 @@ describe("AuctionResults", () => { organizations: ["Phillips"], }) ) + + wrapper.update() + const html = wrapper.html() + expect(html).toContain("Sign up to see price") + done() }) }) }) describe("size filter", () => { - it("triggers relay refetch with size list and tracks events", done => { + it("triggers relay refetch with size list and tracks events, and re-shows sign up to see price", done => { const filter = wrapper.find("SizeFilter") const checkboxes = filter.find("Checkbox") @@ -283,13 +292,17 @@ describe("AuctionResults", () => { }, }) + wrapper.update() + const html = wrapper.html() + expect(html).toContain("Sign up to see price") + done() }) }) }) describe("year created filter", () => { const value = v => ({ target: { value: `${v}` } }) - it("triggers relay refetch with created years and tracks events", () => { + it("triggers relay refetch with created years and tracks events, and re-shows sign up to see price", () => { const filter = wrapper.find("YearCreated") const selects = filter.find("select") @@ -309,12 +322,16 @@ describe("AuctionResults", () => { latestCreatedYear: 1973, }) ) + + wrapper.update() + const html = wrapper.html() + expect(html).toContain("Sign up to see price") }) }) }) describe("sort", () => { - it("triggers relay refetch with correct params", done => { + it("triggers relay refetch with correct params, and re-shows sign up to see price", done => { const sort = wrapper.find("SortSelect SelectSmall") sort @@ -330,6 +347,11 @@ describe("AuctionResults", () => { sort: "ESTIMATE_AND_DATE_DESC", }) ) + + wrapper.update() + const html = wrapper.html() + expect(html).toContain("Sign up to see price") + done() }) }) From dc19fa104467b8b69a90a21b0dd8c3004f5064b1 Mon Sep 17 00:00:00 2001 From: Jian Date: Thu, 21 May 2020 11:32:20 -0400 Subject: [PATCH 08/10] Change paginationCount to a boolean. Rename it to 'paginated'. Because we just need to know whether pagination occurred, not how many times it occurred. --- .../ArtistAuctionResultItem.tsx | 20 +++++++++---------- .../AuctionResults/ArtistAuctionResults.tsx | 6 +++--- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResultItem.tsx b/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResultItem.tsx index 04a8c3c2b0..b9b8356dad 100644 --- a/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResultItem.tsx +++ b/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResultItem.tsx @@ -37,7 +37,7 @@ export interface Props extends SystemContextProps { mediator?: Mediator lastChild: boolean filtersHaveUpdated: boolean - paginationCount: number + paginated: boolean } const FullWidthBorderBox = styled(BorderBox)` @@ -209,7 +209,7 @@ const LargeAuctionItem: SFC = props => { props.mediator, "lg", props.filtersHaveUpdated, - props.paginationCount + props.paginated )} @@ -254,7 +254,7 @@ const ExtraSmallAuctionItem: SFC = props => { props.mediator, "xs", props.filtersHaveUpdated, - props.paginationCount + props.paginated )} {title} @@ -339,15 +339,15 @@ const renderPricing = ( mediator, size, filtersHaveUpdated, - paginationCount + paginated ) => { const textSize = size === "xs" ? "2" : "3t" // If user is logged in we show prices. Otherwise we show prices only for the default view - on page 1 and filters not changed. // Ideally we get current page number from filter context 'page' property but somehow it is always '1'. - // So we resort to pagination count. If user has paginated at all, prices will be hidden. even if user comes back to page 1. + // So we resort to pagination detection. If user has paginated at all, prices will be hidden. even if user comes back to page 1. // TODO: Fix filter context so its 'page' property has the current page number, then change this code. - if (user || (!filtersHaveUpdated && paginationCount == 0)) { + if (user || (!filtersHaveUpdated && !paginated)) { const textAlign = size === "xs" ? "left" : "right" const dateOfSale = DateTime.fromISO(saleDate) const now = DateTime.local() @@ -449,11 +449,11 @@ const renderRealizedPrice = ( mediator, size, filtersHaveUpdated, - paginationCount + paginated ) => { const justifyContent = size === "xs" ? "flex-start" : "flex-end" // Show prices if user is logged in. Otherwise, show prices only on default view - filters at default and no pagination has happened. - if (user || (!filtersHaveUpdated && paginationCount == 0)) { + if (user || (!filtersHaveUpdated && !paginated)) { return ( {estimatedPrice && ( @@ -564,7 +564,7 @@ const renderLargeCollapse = (props, user, mediator, filtersHaveUpdated) => { mediator, "lg", filtersHaveUpdated, - props.paginationCount + props.paginated )} @@ -651,7 +651,7 @@ const renderSmallCollapse = (props, user, mediator, filtersHaveUpdated) => { mediator, "xs", filtersHaveUpdated, - props.paginationCount + props.paginated )} diff --git a/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResults.tsx b/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResults.tsx index 1d27683bad..a10f4a339d 100644 --- a/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResults.tsx +++ b/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResults.tsx @@ -51,7 +51,7 @@ const AuctionResultsContainer: React.FC = ({ } = filterContext.filters // Count number of times user paginated. - const [paginationCount, incrementPaginationCount] = useState(0) + const [paginated, togglePaginated] = useState(false) const loadNext = () => { const { hasNextPage, endCursor } = pageInfo @@ -63,7 +63,7 @@ const AuctionResultsContainer: React.FC = ({ const loadAfter = cursor => { setIsLoading(true) - incrementPaginationCount(paginationCount + 1) + togglePaginated(true) relay.refetch( { @@ -159,7 +159,7 @@ const AuctionResultsContainer: React.FC = ({ auctionResult={node} lastChild={index === auctionResultsLength - 1} filtersHaveUpdated={false} - paginationCount={paginationCount} + paginated={paginated} /> ) From 81ff85c5f645d4e4e9f95235aa9fc73f0d75e9a2 Mon Sep 17 00:00:00 2001 From: Jian Date: Thu, 21 May 2020 13:53:33 -0400 Subject: [PATCH 09/10] Regarding 'filtersHaveUpdated' const in 'ArtistAuctionResultItem', renaming it to 'filtersAtDefault' because that's really what it's about. Also moving it up a level in the component tree so it doesn't get evaluated 10 times at each render. --- .../ArtistAuctionResultItem.tsx | 38 +++++++------------ .../AuctionResults/ArtistAuctionResults.tsx | 9 ++++- 2 files changed, 21 insertions(+), 26 deletions(-) diff --git a/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResultItem.tsx b/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResultItem.tsx index b9b8356dad..727b558297 100644 --- a/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResultItem.tsx +++ b/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResultItem.tsx @@ -26,9 +26,6 @@ import { ImageWithFallback, renderFallbackImage, } from "./Components/ImageWithFallback" -import { useAuctionResultsFilterContext } from "./AuctionResultsFilterContext" -import { isEqual } from "lodash" -import { auctionResultsFilterResetState } from "./AuctionResultsFilterContext" export interface Props extends SystemContextProps { expanded?: boolean @@ -36,7 +33,7 @@ export interface Props extends SystemContextProps { index: number mediator?: Mediator lastChild: boolean - filtersHaveUpdated: boolean + filtersAtDefault: boolean paginated: boolean } @@ -75,13 +72,6 @@ export const ArtistAuctionResultItem: SFC = props => { }) } - // Is current filter state different from the default (reset) state? - const filterContext = useAuctionResultsFilterContext() - const filtersHaveUpdated = !isEqual( - filterContext.filters, - auctionResultsFilterResetState - ) - return ( <> @@ -92,7 +82,6 @@ export const ArtistAuctionResultItem: SFC = props => { expanded={expanded} mediator={mediator} user={user} - filtersHaveUpdated={filtersHaveUpdated} /> @@ -100,7 +89,7 @@ export const ArtistAuctionResultItem: SFC = props => { { ...props, expanded }, user, mediator, - filtersHaveUpdated + props.filtersAtDefault )} @@ -115,7 +104,6 @@ export const ArtistAuctionResultItem: SFC = props => { expanded={expanded} mediator={mediator} user={user} - filtersHaveUpdated={filtersHaveUpdated} /> @@ -124,7 +112,7 @@ export const ArtistAuctionResultItem: SFC = props => { { ...props, expanded }, user, mediator, - filtersHaveUpdated + props.filtersAtDefault )} @@ -208,7 +196,7 @@ const LargeAuctionItem: SFC = props => { props.user, props.mediator, "lg", - props.filtersHaveUpdated, + props.filtersAtDefault, props.paginated )} @@ -253,7 +241,7 @@ const ExtraSmallAuctionItem: SFC = props => { props.user, props.mediator, "xs", - props.filtersHaveUpdated, + props.filtersAtDefault, props.paginated )} @@ -338,7 +326,7 @@ const renderPricing = ( user, mediator, size, - filtersHaveUpdated, + filtersAtDefault, paginated ) => { const textSize = size === "xs" ? "2" : "3t" @@ -347,7 +335,7 @@ const renderPricing = ( // Ideally we get current page number from filter context 'page' property but somehow it is always '1'. // So we resort to pagination detection. If user has paginated at all, prices will be hidden. even if user comes back to page 1. // TODO: Fix filter context so its 'page' property has the current page number, then change this code. - if (user || (!filtersHaveUpdated && !paginated)) { + if (user || (filtersAtDefault && !paginated)) { const textAlign = size === "xs" ? "left" : "right" const dateOfSale = DateTime.fromISO(saleDate) const now = DateTime.local() @@ -448,12 +436,12 @@ const renderRealizedPrice = ( user, mediator, size, - filtersHaveUpdated, + filtersAtDefault, paginated ) => { const justifyContent = size === "xs" ? "flex-start" : "flex-end" // Show prices if user is logged in. Otherwise, show prices only on default view - filters at default and no pagination has happened. - if (user || (!filtersHaveUpdated && !paginated)) { + if (user || (filtersAtDefault && !paginated)) { return ( {estimatedPrice && ( @@ -487,7 +475,7 @@ const renderRealizedPrice = ( } } -const renderLargeCollapse = (props, user, mediator, filtersHaveUpdated) => { +const renderLargeCollapse = (props, user, mediator, filtersAtDefault) => { const { expanded, auctionResult: { @@ -563,7 +551,7 @@ const renderLargeCollapse = (props, user, mediator, filtersHaveUpdated) => { user, mediator, "lg", - filtersHaveUpdated, + filtersAtDefault, props.paginated )} @@ -588,7 +576,7 @@ const renderLargeCollapse = (props, user, mediator, filtersHaveUpdated) => { ) } -const renderSmallCollapse = (props, user, mediator, filtersHaveUpdated) => { +const renderSmallCollapse = (props, user, mediator, filtersAtDefault) => { const { expanded, auctionResult: { @@ -650,7 +638,7 @@ const renderSmallCollapse = (props, user, mediator, filtersHaveUpdated) => { user, mediator, "xs", - filtersHaveUpdated, + filtersAtDefault, props.paginated )} diff --git a/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResults.tsx b/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResults.tsx index a10f4a339d..c4d0cf1278 100644 --- a/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResults.tsx +++ b/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResults.tsx @@ -24,6 +24,7 @@ import { AuctionFilterMobileActionSheet } from "./Components/AuctionFilterMobile import { AuctionFilters } from "./Components/AuctionFilters" import { AuctionResultHeaderFragmentContainer as AuctionResultHeader } from "./Components/AuctionResultHeader" import { AuctionResultsControls } from "./Components/AuctionResultsControls" +import { auctionResultsFilterResetState } from "./AuctionResultsFilterContext" const logger = createLogger("ArtistAuctionResults.tsx") @@ -95,6 +96,12 @@ const AuctionResultsContainer: React.FC = ({ const [showMobileActionSheet, toggleMobileActionSheet] = useState(false) const tracking = useTracking() + // Is current filter state different from the default (reset) state? + const filtersAtDefault = isEqual( + filterContext.filters, + auctionResultsFilterResetState + ) + const previousFilters = usePrevious(filterContext.filters) // TODO: move this and artwork copy to util? @@ -158,7 +165,7 @@ const AuctionResultsContainer: React.FC = ({ index={index} auctionResult={node} lastChild={index === auctionResultsLength - 1} - filtersHaveUpdated={false} + filtersAtDefault={filtersAtDefault} paginated={paginated} /> From 8367aef44dd67210f51b860e92e144dbdc499ab3 Mon Sep 17 00:00:00 2001 From: Jian Date: Thu, 21 May 2020 13:56:25 -0400 Subject: [PATCH 10/10] Correct comment about pagination state. --- src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResults.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResults.tsx b/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResults.tsx index c4d0cf1278..8c96a83957 100644 --- a/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResults.tsx +++ b/src/Apps/Artist/Routes/AuctionResults/ArtistAuctionResults.tsx @@ -51,7 +51,7 @@ const AuctionResultsContainer: React.FC = ({ allowEmptyCreatedDates, } = filterContext.filters - // Count number of times user paginated. + // Detect whether user has paginated at all. const [paginated, togglePaginated] = useState(false) const loadNext = () => {