Skip to content

Commit

Permalink
fix: custom store bug seller list (#346)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertoMSousa authored Oct 20, 2022
1 parent 150205c commit 4f10da2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/lib/routing/parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ export const ExploreQueryParameters = {
currency: "currency",
orderDirection: "orderDirection",
orderBy: "orderBy",
sortBy: "sortBy"
sortBy: "sortBy",
sellerCurationList: "sellerCurationList"
} as const;

export const CollectionsQueryParameters = {
Expand Down
4 changes: 3 additions & 1 deletion src/lib/utils/hooks/offers/getOffers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const getOffers = async (props: UseOffersProps) => {
quantityAvailable_lte: props.quantityAvailable_lte,
quantityAvailable_gte: props.quantityAvailable_gte,
type: props.type,
sellerCurationList: props.sellerCurationList || [],
sellerCurationList: props?.sellerCurationList || [],
offerCurationList: props.offerCurationList || [],
first: props.first,
skip: props.skip,
Expand Down Expand Up @@ -119,6 +119,7 @@ async function fetchCurationListOffers(
const sellerCurationList = props.enableCurationLists
? props.sellerCurationList || []
: null;

const offerCurationList = props.enableCurationLists
? props.offerCurationList || []
: null;
Expand All @@ -128,6 +129,7 @@ async function fetchCurationListOffers(
sellerCurationList: !!sellerCurationList,
offerCurationList: false
});

const getOfferCurationListOffersQuery = buildGetOffersQuery({
...getOffersQueryArgs,
sellerCurationList: false,
Expand Down
12 changes: 9 additions & 3 deletions src/lib/utils/hooks/useCollections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ export function useCollections(
validUntilDate?: string;
exchangeOrderBy?: string;
validFromDate_lte?: string;
sellerCurationList?: string;
},
options: {
enabled?: boolean;
} = {}
) {
const sellerCurationList = props?.sellerCurationList?.split(",");
return useQuery(
["sellers", props],
["sellers", props, sellerCurationList],
async () => {
const result = await fetchSubgraph<{
sellers: {
Expand Down Expand Up @@ -48,8 +50,11 @@ export function useCollections(
$validFromDate: String
$validUntilDate: String
$validFromDate_lte: String
${sellerCurationList ? "$sellerCurationList: [String!]" : ""}
) {
sellers(skip: $skip, first: $first) {
sellers(skip: $skip, first: $first where: {${
sellerCurationList ? "sellerId_in: $sellerCurationList" : ""
}}) {
id
exchanges {
id
Expand Down Expand Up @@ -90,7 +95,8 @@ export function useCollections(
}
`,
{
...props
...props,
sellerCurationList: sellerCurationList
}
);
return result?.sellers ?? [];
Expand Down
12 changes: 11 additions & 1 deletion src/pages/explore/WithAllOffers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ export function WithAllOffers<P>(

const filterOptions = useMemo(() => {
const filterByName = params?.[ExploreQueryParameters.name] || false;
const sellerCurationList =
params?.[ExploreQueryParameters.sellerCurationList] || false;

const sortByParam =
params?.[ExploreQueryParameters.sortBy]?.includes("price:asc") ||
params?.[ExploreQueryParameters.sortBy]?.includes("price:desc") ||
Expand Down Expand Up @@ -150,6 +153,12 @@ export function WithAllOffers<P>(
name: filterByName
};
}
if (sellerCurationList) {
payload = {
...basePayload,
sellerCurationList: sellerCurationList
};
}
if (sortByParam !== false) {
const [orderBy, orderDirection] = (sortByParam as string).split(":");
if (orderBy === "committedDate" || orderBy === "redeemedDate") {
Expand Down Expand Up @@ -186,7 +195,8 @@ export function WithAllOffers<P>(
"isSortable",
"orderBy",
"orderDirection",
"validFromDate_lte"
"validFromDate_lte",
"sellerCurationList"
]) as FilterOptions;
}, [params]);

Expand Down

0 comments on commit 4f10da2

Please sign in to comment.