From 8803d635a03682a82fbc8c156e1bdc741529ff41 Mon Sep 17 00:00:00 2001 From: hta218 Date: Sun, 8 Dec 2024 16:51:03 +0700 Subject: [PATCH 1/4] Update collection filters toolbar --- app/sections/collection-filters/index.tsx | 2 +- app/sections/collection-filters/tools-bar.tsx | 27 +++++++++++-------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/app/sections/collection-filters/index.tsx b/app/sections/collection-filters/index.tsx index a65e58a5..97795d27 100644 --- a/app/sections/collection-filters/index.tsx +++ b/app/sections/collection-filters/index.tsx @@ -86,7 +86,7 @@ let CollectionFilters = forwardRef( {...props} />
- {filtersPosition === "sidebar" && ( + {enableFilter && filtersPosition === "sidebar" && (
Filters
diff --git a/app/sections/collection-filters/tools-bar.tsx b/app/sections/collection-filters/tools-bar.tsx index 880b6946..16e2eb66 100644 --- a/app/sections/collection-filters/tools-bar.tsx +++ b/app/sections/collection-filters/tools-bar.tsx @@ -1,14 +1,14 @@ +import { Sliders, X } from "@phosphor-icons/react"; +import * as Dialog from "@radix-ui/react-dialog"; import { useLoaderData } from "@remix-run/react"; import { type VariantProps, cva } from "class-variance-authority"; +import clsx from "clsx"; import type { CollectionDetailsQuery } from "storefrontapi.generated"; +import { Button } from "~/components/button"; import { cn } from "~/lib/cn"; import { Filters } from "./filters"; import { LayoutSwitcher, type LayoutSwitcherProps } from "./layout-switcher"; import { Sort } from "./sort"; -import * as Dialog from "@radix-ui/react-dialog"; -import { Button } from "~/components/button"; -import { Sliders, X } from "@phosphor-icons/react"; -import clsx from "clsx"; let variants = cva("", { variants: { @@ -57,14 +57,18 @@ export function ToolsBar({ onGridSizeChange={onGridSizeChange} /> {showProductsCount && ( - + {collection?.products.nodes.length} Products )} -
- {enableSort && } - {enableFilter && } -
+ {(enableSort || (enableFilter && filtersPosition === "drawer")) && ( +
+ {enableSort && } + {enableFilter && ( + + )} +
+ )}
); @@ -102,8 +106,9 @@ function FiltersDrawer({
Filters - From 7c301b602fb673264990d8b5c015a7ba6020bdc6 Mon Sep 17 00:00:00 2001 From: hta218 Date: Mon, 9 Dec 2024 10:19:51 +0700 Subject: [PATCH 2/4] Refine Scrollbar configuration in ScrollArea component for better styling and layout consistency --- app/components/scroll-area.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/components/scroll-area.tsx b/app/components/scroll-area.tsx index 73904b9c..03f947e9 100644 --- a/app/components/scroll-area.tsx +++ b/app/components/scroll-area.tsx @@ -55,7 +55,7 @@ export let ScrollArea = forwardRef( ( > Date: Mon, 9 Dec 2024 10:20:06 +0700 Subject: [PATCH 3/4] Allow filters drawer to be scrollable --- app/sections/collection-filters/filters.tsx | 5 +++-- app/sections/collection-filters/tools-bar.tsx | 9 ++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/sections/collection-filters/filters.tsx b/app/sections/collection-filters/filters.tsx index 6632b47c..b62bff55 100644 --- a/app/sections/collection-filters/filters.tsx +++ b/app/sections/collection-filters/filters.tsx @@ -21,8 +21,9 @@ import type { AppliedFilter } from "~/lib/filter"; import { getAppliedFilterLink, getFilterLink } from "~/lib/filter"; import type { CollectionFiltersData } from "."; import { Input } from "../../modules/input"; +import { cn } from "~/lib/cn"; -export function Filters() { +export function Filters({ className }: { className?: string }) { let parentInstance = useClosestWeaverseItem(".filters-list"); let parentData = parentInstance.data as unknown as CollectionFiltersData; let { expandFilters, showFiltersCount } = parentData; @@ -65,7 +66,7 @@ export function Filters() { return ( filter.id) : []} > diff --git a/app/sections/collection-filters/tools-bar.tsx b/app/sections/collection-filters/tools-bar.tsx index 16e2eb66..eb3dc7b3 100644 --- a/app/sections/collection-filters/tools-bar.tsx +++ b/app/sections/collection-filters/tools-bar.tsx @@ -5,6 +5,7 @@ import { type VariantProps, cva } from "class-variance-authority"; import clsx from "clsx"; import type { CollectionDetailsQuery } from "storefrontapi.generated"; import { Button } from "~/components/button"; +import { ScrollArea } from "~/components/scroll-area"; import { cn } from "~/lib/cn"; import { Filters } from "./filters"; import { LayoutSwitcher, type LayoutSwitcherProps } from "./layout-switcher"; @@ -98,12 +99,12 @@ function FiltersDrawer({ />
-
+
Filters
- + + +
From cd617f2a028cb2bf1f3fad386cf16694a46e7cec Mon Sep 17 00:00:00 2001 From: hta218 Date: Tue, 10 Dec 2024 07:21:06 +0700 Subject: [PATCH 4/4] Update products pagination in collection page --- app/sections/collection-filters/index.tsx | 67 ++++------ .../products-loaded-on-scroll.tsx | 57 --------- .../products-pagination.tsx | 115 ++++++++++++++++++ app/sections/collection-filters/sort.tsx | 28 ++--- 4 files changed, 150 insertions(+), 117 deletions(-) delete mode 100644 app/sections/collection-filters/products-loaded-on-scroll.tsx create mode 100644 app/sections/collection-filters/products-pagination.tsx diff --git a/app/sections/collection-filters/index.tsx b/app/sections/collection-filters/index.tsx index 97795d27..d7781e2c 100644 --- a/app/sections/collection-filters/index.tsx +++ b/app/sections/collection-filters/index.tsx @@ -1,13 +1,11 @@ import { useLoaderData } from "@remix-run/react"; -import { Pagination } from "@shopify/hydrogen"; import type { HydrogenComponentSchema } from "@weaverse/hydrogen"; import { forwardRef, useEffect, useState } from "react"; -import { useInView } from "react-intersection-observer"; import type { CollectionDetailsQuery } from "storefrontapi.generated"; import Link from "~/components/link"; import { Section, type SectionProps, layoutInputs } from "~/components/section"; import { Filters } from "./filters"; -import { ProductsLoadedOnScroll } from "./products-loaded-on-scroll"; +import { ProductsPagination } from "./products-pagination"; import { ToolsBar } from "./tools-bar"; export interface CollectionFiltersData { @@ -40,7 +38,6 @@ let CollectionFilters = forwardRef( loadMoreText, ...rest } = props; - let { ref, inView } = useInView(); let { collection, collections } = useLoaderData< CollectionDetailsQuery & { collections: Array<{ handle: string; title: string }>; @@ -92,48 +89,12 @@ let CollectionFilters = forwardRef(
)} - - {({ - nodes, - isLoading, - nextPageUrl, - previousPageUrl, - hasNextPage, - hasPreviousPage, - state, - }) => ( -
- {hasPreviousPage && ( - - {isLoading ? "Loading..." : loadPrevText} - - )} - - {hasNextPage && ( - - {isLoading ? "Loading..." : loadMoreText} - - )} -
- )} -
+
); @@ -206,6 +167,20 @@ export let schema: HydrogenComponentSchema = { defaultValue: true, condition: "enableFilter.eq.true", }, + { + type: "switch", + name: "enableColorSwatch", + label: "Enable color swatches", + defaultValue: true, + condition: "enableFilter.eq.true", + }, + { + type: "text", + name: "displayAsButtonFor", + label: "Display as button for:", + defaultValue: "Size, More filters", + condition: "enableFilter.eq.true", + }, ], }, { diff --git a/app/sections/collection-filters/products-loaded-on-scroll.tsx b/app/sections/collection-filters/products-loaded-on-scroll.tsx deleted file mode 100644 index ad7adf02..00000000 --- a/app/sections/collection-filters/products-loaded-on-scroll.tsx +++ /dev/null @@ -1,57 +0,0 @@ -import { useNavigate } from "@remix-run/react"; -import { useEffect } from "react"; -import { getImageLoadingPriority } from "~/lib/const"; -import { ProductCard } from "~/modules/product-card"; - -interface ProductsLoadedOnScrollProps { - gridSizeDesktop: number; - gridSizeMobile: number; - nodes: any; - inView: boolean; - nextPageUrl: string; - hasNextPage: boolean; - state: any; -} - -export function ProductsLoadedOnScroll(props: ProductsLoadedOnScrollProps) { - let { - gridSizeMobile, - gridSizeDesktop, - nodes, - inView, - nextPageUrl, - hasNextPage, - state, - } = props; - let navigate = useNavigate(); - - useEffect(() => { - if (inView && hasNextPage) { - navigate(nextPageUrl, { - replace: true, - preventScrollReset: true, - state, - }); - } - }, [inView, navigate, state, nextPageUrl, hasNextPage]); - - return ( -
- {nodes.map((product: any, i: number) => ( - - ))} -
- ); -} diff --git a/app/sections/collection-filters/products-pagination.tsx b/app/sections/collection-filters/products-pagination.tsx new file mode 100644 index 00000000..33897166 --- /dev/null +++ b/app/sections/collection-filters/products-pagination.tsx @@ -0,0 +1,115 @@ +import { useLoaderData, useNavigate } from "@remix-run/react"; +import { Pagination } from "@shopify/hydrogen"; +import clsx from "clsx"; +import { useEffect } from "react"; +import { useInView } from "react-intersection-observer"; +import type { CollectionDetailsQuery } from "storefrontapi.generated"; +import Link from "~/components/link"; +import { getImageLoadingPriority } from "~/lib/const"; +import { ProductCard } from "~/modules/product-card"; + +export function ProductsPagination({ + gridSizeDesktop, + gridSizeMobile, + loadPrevText, + loadMoreText, +}: { + gridSizeDesktop: number; + gridSizeMobile: number; + loadPrevText: string; + loadMoreText: string; +}) { + let { collection } = useLoaderData< + CollectionDetailsQuery & { + collections: Array<{ handle: string; title: string }>; + } + >(); + let { ref, inView } = useInView(); + + return ( + + {({ + nodes, + isLoading, + nextPageUrl, + previousPageUrl, + hasNextPage, + hasPreviousPage, + state, + }) => ( +
+ {hasPreviousPage && ( + + {isLoading ? "Loading..." : loadPrevText} + + )} + + {hasNextPage && ( + + {isLoading ? "Loading..." : loadMoreText} + + )} +
+ )} +
+ ); +} + +interface ProductsLoadedOnScrollProps { + nodes: any; + inView: boolean; + nextPageUrl: string; + hasNextPage: boolean; + state: any; +} + +function ProductsLoadedOnScroll(props: ProductsLoadedOnScrollProps) { + let { nodes, inView, nextPageUrl, hasNextPage, state } = props; + let navigate = useNavigate(); + + useEffect(() => { + if (inView && hasNextPage) { + navigate(nextPageUrl, { + replace: true, + preventScrollReset: true, + state, + }); + } + }, [inView, navigate, state, nextPageUrl, hasNextPage]); + + return ( +
+ {nodes.map((product: any, i: number) => ( + + ))} +
+ ); +} diff --git a/app/sections/collection-filters/sort.tsx b/app/sections/collection-filters/sort.tsx index 34455287..6b444966 100644 --- a/app/sections/collection-filters/sort.tsx +++ b/app/sections/collection-filters/sort.tsx @@ -24,20 +24,20 @@ const PRODUCT_SORT: { label: string; key: SortParam }[] = [ }, ]; -const SEARCH_SORT: { label: string; key: SortParam }[] = [ - { - label: "Price: Low - High", - key: "price-low-high", - }, - { - label: "Price: High - Low", - key: "price-high-low", - }, - { - label: "Relevance", - key: "relevance", - }, -]; +// const SEARCH_SORT: { label: string; key: SortParam }[] = [ +// { +// label: "Price: Low - High", +// key: "price-low-high", +// }, +// { +// label: "Price: High - Low", +// key: "price-high-low", +// }, +// { +// label: "Relevance", +// key: "relevance", +// }, +// ]; export function Sort() { let [params] = useSearchParams();