Skip to content

Commit b1d415e

Browse files
authored
Merge pull request #12 from Weaverse/feat/themivo-wishlist-integrate
Integrate Themivo Wishlist & Alerts into Aspen
2 parents 8bad38c + 001f922 commit b1d415e

73 files changed

Lines changed: 6712 additions & 220 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.env.example‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ WEAVERSE_PROJECT_ID="<weaverse-project-id>"
3131
# ALI_REVIEWS_API_KEY="<ali-reviews-api-key>"
3232
# LOYALTYLION_SITE_ID="<loyaltylion-site-id>"
3333
# LOYALTYLION_API_KEY="<loyaltylion-api-key>"
34+
# WISHLIST_API_KEY="<themivo-read-write-api-key>"
3435

3536
# Optional Shopify content configuration
3637
# METAOBJECT_COLORS_TYPE="<shopify-metaobject-type>"

‎.github/workflows/ci.yml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ jobs:
3131
run: npm run codegen
3232
- name: Check types
3333
run: npm run typecheck
34+
- name: Check Themivo wishlist regressions
35+
run: |
36+
npx --no-install vite-node tests/themivo-wishlist.unit.test.ts
37+
npx --no-install vite-node tests/themivo-products.unit.test.ts
38+
npx --no-install vite-node tests/themivo-appearance.unit.test.ts
3439
- name: Check localization
3540
run: npm run locale:check && npm run i18n:test
3641
- name: Check sanitizer regressions

‎app/components/animate-drawer.tsx‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as Dialog from "@radix-ui/react-dialog";
22
import clsx from "clsx";
33
import { AnimatePresence, motion } from "framer-motion";
4+
import type { ComponentProps, ReactNode } from "react";
45
import {
56
CART_DRAWER_RADIUS_CLASS,
67
CART_DRAWER_WIDTH_CLASS,
@@ -16,10 +17,19 @@ export function AnimatedDrawer({
1617
children,
1718
flush = false,
1819
filter = false,
20+
onCloseAutoFocus = (event) => event.preventDefault(),
21+
onExitComplete,
22+
}: {
23+
open: boolean;
24+
children: ReactNode;
25+
flush?: boolean;
26+
filter?: boolean;
27+
onCloseAutoFocus?: ComponentProps<typeof Dialog.Content>["onCloseAutoFocus"];
28+
onExitComplete?: () => void;
1929
}) {
2030
return (
2131
<Dialog.Portal forceMount>
22-
<AnimatePresence>
32+
<AnimatePresence onExitComplete={onExitComplete}>
2333
{open && (
2434
<>
2535
<Dialog.Overlay forceMount>
@@ -32,7 +42,7 @@ export function AnimatedDrawer({
3242
</Dialog.Overlay>
3343
<Dialog.Content
3444
forceMount
35-
onCloseAutoFocus={(e) => e.preventDefault()}
45+
onCloseAutoFocus={onCloseAutoFocus}
3646
className={clsx(
3747
"fixed z-10",
3848
filter || flush

‎app/components/cart/cart-best-sellers.tsx‎

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import type {
66
import { useTranslation } from "@weaverse/hydrogen";
77
import clsx from "clsx";
88
import { useEffect, useId, useMemo, useRef, useState } from "react";
9-
import { useFetcher } from "react-router";
109
import type { ProductCardFragment } from "storefront-api.generated";
1110
import { ArrowButton } from "~/components/arrow-button";
1211
import { Link } from "~/components/link";
@@ -49,7 +48,7 @@ export function CartBestSellers({
4948
);
5049

5150
const { t } = useTranslation();
52-
const { load, data } = useFetcher<{ products: Product[] }>();
51+
const [products, setProducts] = useState<Product[]>();
5352
const queryString = useMemo(
5453
() =>
5554
Object.entries({ count: count * 2, sortKey, query, reverse })
@@ -67,8 +66,23 @@ export function CartBestSellers({
6766
const [canScroll, setCanScroll] = useState({ previous: false, next: false });
6867

6968
useEffect(() => {
70-
load(productsApiPath);
71-
}, [load, productsApiPath]);
69+
const controller = new AbortController();
70+
fetch(productsApiPath, { signal: controller.signal })
71+
.then(async (response) => {
72+
if (!response.ok) {
73+
return [];
74+
}
75+
const result = (await response.json()) as { products: Product[] };
76+
return result.products;
77+
})
78+
.catch(() => [])
79+
.then((result) => {
80+
if (!controller.signal.aborted) {
81+
setProducts(result);
82+
}
83+
});
84+
return () => controller.abort();
85+
}, [productsApiPath]);
7286

7387
// Re-measure replaced cards even when the rail's own dimensions stay unchanged.
7488
// Product and skeleton changes can alter scrollWidth without resizing the rail.
@@ -111,7 +125,7 @@ export function CartBestSellers({
111125
rail.removeEventListener("keydown", syncPosition);
112126
observer.disconnect();
113127
};
114-
}, [layout, data?.products, count]);
128+
}, [layout, products, count]);
115129

116130
const scrollRail = (direction: -1 | 1) => {
117131
const rail = railRef.current;
@@ -170,7 +184,7 @@ export function CartBestSellers({
170184
<CartBestSellersContent
171185
count={count}
172186
layout={layout}
173-
products={data?.products as Product[]}
187+
products={products}
174188
/>
175189
</div>
176190
<div className="flex select-none justify-center gap-2">
@@ -211,7 +225,7 @@ export function CartBestSellers({
211225
<CartBestSellersContent
212226
count={count}
213227
layout={layout}
214-
products={data?.products as Product[]}
228+
products={products}
215229
/>
216230
</div>
217231
</>

‎app/components/cart/cart-line-item.tsx‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@ import { SubscriptionLineItem } from "~/components/subscriptions/subscription-li
99
import { calculateAspectRatio } from "~/utils/image";
1010
import { toggleCartDrawer } from "../layout/cart-drawer";
1111
import { CartLineQuantityAdjust } from "./cart-line-qty-adjust";
12+
import { SaveCartLineForLater } from "./cart-saved-for-later";
1213
import type { CartLayout, CartLine } from "./cart-types";
14+
import {
15+
DRAWER_LINE_BODY_CLASS,
16+
DRAWER_LINE_CLASS,
17+
DRAWER_LINE_IMAGE_CLASS,
18+
DRAWER_LINE_MEDIA_CLASS,
19+
DRAWER_LINE_TITLE_CLASS,
20+
} from "./drawer-frame";
1321
import { useCartStore } from "./store";
1422

1523
const cartCodeBadgeClassName =
@@ -51,7 +59,7 @@ export function CartLineItem({
5159
className={clsx(
5260
"relative transition-all duration-300",
5361
layout === "drawer"
54-
? "flex gap-4 max-md:min-w-0 max-md:w-full"
62+
? DRAWER_LINE_CLASS
5563
: "flex h-full flex-col items-center overflow-hidden rounded-(--radius-md) md:flex-row",
5664
isOptimistic && "opacity-70",
5765
id.startsWith("optimistic-") && "pointer-events-none",
@@ -61,7 +69,7 @@ export function CartLineItem({
6169
<div
6270
className={clsx(
6371
layout === "drawer"
64-
? "shrink-0 rounded-(--radius-md) bg-(--color-background-subtle)/50 max-xl:w-[clamp(100px,32.56vw,140px)] max-md:relative max-md:h-[140px] max-md:min-w-0 max-md:flex-[1_0_0] max-md:self-start max-md:overflow-hidden"
72+
? DRAWER_LINE_MEDIA_CLASS
6573
: "aspect-square w-full md:h-[360px] md:w-[360px] md:shrink-0",
6674
)}
6775
>
@@ -73,7 +81,7 @@ export function CartLineItem({
7381
className={clsx(
7482
"!object-cover",
7583
layout === "drawer"
76-
? "h-auto w-[140px] rounded-xl max-xl:aspect-square max-xl:h-full max-xl:max-h-[140px] max-xl:w-full max-md:absolute max-md:inset-0 max-md:aspect-auto max-md:max-h-none max-md:rounded-(--radius-md)"
84+
? DRAWER_LINE_IMAGE_CLASS
7785
: "h-full w-full rounded",
7886
)}
7987
alt={title}
@@ -87,7 +95,7 @@ export function CartLineItem({
8795
className={clsx(
8896
"flex flex-col",
8997
layout === "drawer"
90-
? "min-w-0 grow justify-between gap-4 max-xl:min-h-[140px] max-xl:text-sm max-md:min-w-min max-md:basis-3/5 max-md:grow-0 max-md:shrink-0 max-md:gap-2 max-md:wrap-anywhere"
98+
? DRAWER_LINE_BODY_CLASS
9199
: "h-full w-full bg-[var(--Background-Background,#FFF)] p-6 md:h-[360px]",
92100
)}
93101
>
@@ -130,6 +138,8 @@ export function CartLineItem({
130138
/>
131139
<SubscriptionLineItem line={line as any} />
132140

141+
<SaveCartLineForLater line={line} />
142+
133143
{/* Quantity and Pricing */}
134144
<div className="grid w-full grid-cols-[minmax(0,1fr)_auto] items-center gap-1">
135145
<CartLineQuantityAdjust line={line} />
@@ -158,12 +168,12 @@ export function CartLineItem({
158168
className="w-full justify-start text-left max-xl:leading-5"
159169
onClick={() => toggleCartDrawer(false)}
160170
>
161-
<span className="max-xl:line-clamp-2 xl:line-clamp-1 font-semibold uppercase max-md:line-clamp-1">
171+
<span className={DRAWER_LINE_TITLE_CLASS}>
162172
{product?.title || ""}
163173
</span>
164174
</Link>
165175
) : (
166-
<p className="max-xl:line-clamp-2 xl:line-clamp-1 font-semibold uppercase max-md:line-clamp-1">
176+
<p className={DRAWER_LINE_TITLE_CLASS}>
167177
{product?.title || ""}
168178
</p>
169179
)}

‎app/components/cart/cart-line-qty-adjust.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { useTranslation } from "@weaverse/hydrogen";
2+
import { cn } from "~/utils/cn";
23
import type { CartLine } from "./cart-types";
4+
import { CART_DRAWER_QUANTITY_SIZE_CLASS } from "./drawer-frame";
35
import { canAdjustLineQuantity, useCartStore } from "./store";
46

57
export function CartLineQuantityAdjust({ line }: { line: CartLine }) {
@@ -21,7 +23,10 @@ export function CartLineQuantityAdjust({ line }: { line: CartLine }) {
2123

2224
return (
2325
<fieldset
24-
className="inline-flex h-7.5 w-30 shrink-0 items-stretch overflow-hidden rounded-(--radius-sm) bg-(--color-background-subtle) font-dm-sans font-semibold text-[14px] text-body leading-none tracking-[0.02em]"
26+
className={cn(
27+
"inline-flex shrink-0 items-stretch overflow-hidden rounded-(--radius-sm) bg-(--color-background-subtle) font-dm-sans font-semibold text-[14px] text-body leading-none tracking-[0.02em]",
28+
CART_DRAWER_QUANTITY_SIZE_CLASS,
29+
)}
2530
aria-label={t("product.quantityValue", { quantity })}
2631
aria-busy={isPending}
2732
>

‎app/components/cart/cart-main.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { CartBestSellers } from "./cart-best-sellers";
1212
import { CartCodeForm } from "./cart-code-form";
1313
import { CartLineItem, PriceLoadingSpinner } from "./cart-line-item";
1414
import { CartPageNote } from "./cart-page-note";
15+
import { CartSavedForLater } from "./cart-saved-for-later";
1516
import {
1617
AppliedCartCodes,
1718
CartCheckoutActions,
@@ -249,6 +250,7 @@ export function CartDetails({
249250
lines={cart.lines.nodes}
250251
layout={layout}
251252
/>
253+
<CartSavedForLater layout="drawer" />
252254
</div>
253255
<CartSummary layout={layout} className="mt-auto">
254256
<AppliedCartCodes
@@ -437,6 +439,7 @@ export function CartEmpty({
437439
</Link>
438440
)}
439441
</div>
442+
{layout === "drawer" && !hidden && <CartSavedForLater layout="drawer" />}
440443
{enableCartBestSellers && layout === "drawer" && (
441444
<div className="grid gap-4">
442445
<CartBestSellers

0 commit comments

Comments
 (0)