Skip to content

Commit

Permalink
refactor: cart to use Streamable
Browse files Browse the repository at this point in the history
  • Loading branch information
apledger committed Jan 2, 2025
1 parent 273c470 commit f942c85
Show file tree
Hide file tree
Showing 12 changed files with 652 additions and 645 deletions.
48 changes: 22 additions & 26 deletions apps/web/vibes/soul/examples/pages/cart/electric.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { checkoutAction, lineItemAction } from '@/vibes/soul/examples/sections/c
import { copyright, footerLinks } from '@/vibes/soul/examples/sections/footer/electric';
import { Banner } from '@/vibes/soul/primitives/banner';
import { Navigation } from '@/vibes/soul/primitives/navigation';
import { Cart } from '@/vibes/soul/sections/cart';
import { Cart, CartLineItem } from '@/vibes/soul/sections/cart';
import { CartSummaryLineItem } from '@/vibes/soul/sections/cart/summary';
import { Footer } from '@/vibes/soul/sections/footer';
import {
Amex,
Expand Down Expand Up @@ -50,9 +51,24 @@ const paymentIconsArray: React.ReactNode[] = [
<Bitcoin key="Bitcoin" />,
];

export default async function Preview() {
const lineItems = await getLineItems('Electric');
const subtotal = await getSubtotal('Electric');
export default function Preview() {
const lineItems = new Promise<CartLineItem[]>((res) =>
setTimeout(() => res(getLineItems('Electric')), 1000),
);
const summaryLineItems = getSubtotal('Electric').then((subtotal) => {
return new Promise<CartSummaryLineItem[]>((res) =>
setTimeout(
() =>
res([
{ label: 'Subtotal', value: subtotal },
{ label: 'Shipping', value: 'TBD' },
{ label: 'Tax', value: 'TBD' },
]),
1000,
),
);
});
const summaryTotal = new Promise<string>((res) => setTimeout(() => res('127.60'), 1000));

return (
<>
Expand All @@ -74,30 +90,10 @@ export default async function Preview() {

<Cart
checkoutAction={checkoutAction}
emptyState={{
title: 'Your cart is empty',
subtitle: 'Add some products to get started.',
cta: {
label: 'Continue shopping',
href: '#',
},
}}
lineItemAction={lineItemAction}
lineItems={lineItems}
summary={{
title: 'Summary',
subtotal: subtotal,
caption: 'Shipping & taxes calculated at checkout',
subtotalLabel: 'Subtotal',
shippingLabel: 'Shipping',
shipping: 'TBD',
taxLabel: 'Tax',
tax: 'TBD',
// grandTotalLabel: 'Total',
// grandTotal: '$127.60',
ctaLabel: 'Checkout',
}}
title="Cart"
summaryLineItems={summaryLineItems}
summaryTotal={summaryTotal}
/>

<Subscribe
Expand Down
48 changes: 22 additions & 26 deletions apps/web/vibes/soul/examples/pages/cart/luxury.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { checkoutAction, lineItemAction } from '@/vibes/soul/examples/sections/c
import { copyright, footerLinks } from '@/vibes/soul/examples/sections/footer/electric';
import { Banner } from '@/vibes/soul/primitives/banner';
import { Navigation } from '@/vibes/soul/primitives/navigation';
import { Cart } from '@/vibes/soul/sections/cart';
import { Cart, CartLineItem } from '@/vibes/soul/sections/cart';
import { CartSummaryLineItem } from '@/vibes/soul/sections/cart/summary';
import { Footer } from '@/vibes/soul/sections/footer';
import {
Amex,
Expand Down Expand Up @@ -50,9 +51,24 @@ const paymentIconsArray: React.ReactNode[] = [
<Bitcoin key="Bitcoin" />,
];

export default async function Preview() {
const lineItems = await getLineItems('Luxury');
const subtotal = await getSubtotal('Luxury');
export default function Preview() {
const lineItems = new Promise<CartLineItem[]>((res) =>
setTimeout(() => res(getLineItems('Luxury')), 1000),
);
const summaryLineItems = getSubtotal('Luxury').then((subtotal) => {
return new Promise<CartSummaryLineItem[]>((res) =>
setTimeout(
() =>
res([
{ label: 'Subtotal', value: subtotal },
{ label: 'Shipping', value: 'TBD' },
{ label: 'Tax', value: 'TBD' },
]),
1000,
),
);
});
const summaryTotal = new Promise<string>((res) => setTimeout(() => res('127.60'), 1000));

return (
<>
Expand All @@ -74,30 +90,10 @@ export default async function Preview() {

<Cart
checkoutAction={checkoutAction}
emptyState={{
title: 'Your cart is empty',
subtitle: 'Add some products to get started.',
cta: {
label: 'Continue shopping',
href: '#',
},
}}
lineItemAction={lineItemAction}
lineItems={lineItems}
summary={{
title: 'Summary',
subtotal: subtotal,
caption: 'Shipping & taxes calculated at checkout',
subtotalLabel: 'Subtotal',
shippingLabel: 'Shipping',
shipping: 'TBD',
taxLabel: 'Tax',
tax: 'TBD',
// grandTotalLabel: 'Total',
// grandTotal: '$127.60',
ctaLabel: 'Checkout',
}}
title="Cart"
summaryLineItems={summaryLineItems}
summaryTotal={summaryTotal}
/>

<Subscribe
Expand Down
48 changes: 22 additions & 26 deletions apps/web/vibes/soul/examples/pages/cart/warm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { checkoutAction, lineItemAction } from '@/vibes/soul/examples/sections/c
import { copyright, footerLinks } from '@/vibes/soul/examples/sections/footer/electric';
import { Banner } from '@/vibes/soul/primitives/banner';
import { Navigation } from '@/vibes/soul/primitives/navigation';
import { Cart } from '@/vibes/soul/sections/cart';
import { Cart, CartLineItem } from '@/vibes/soul/sections/cart';
import { CartSummaryLineItem } from '@/vibes/soul/sections/cart/summary';
import { Footer } from '@/vibes/soul/sections/footer';
import {
Amex,
Expand Down Expand Up @@ -50,9 +51,24 @@ const paymentIconsArray: React.ReactNode[] = [
<Bitcoin key="Bitcoin" />,
];

export default async function Preview() {
const lineItems = await getLineItems('Warm');
const subtotal = await getSubtotal('Warm');
export default function Preview() {
const lineItems = new Promise<CartLineItem[]>((res) =>
setTimeout(() => res(getLineItems('Warm')), 1000),
);
const summaryLineItems = getSubtotal('Warm').then((subtotal) => {
return new Promise<CartSummaryLineItem[]>((res) =>
setTimeout(
() =>
res([
{ label: 'Subtotal', value: subtotal },
{ label: 'Shipping', value: 'TBD' },
{ label: 'Tax', value: 'TBD' },
]),
1000,
),
);
});
const summaryTotal = new Promise<string>((res) => setTimeout(() => res('127.60'), 1000));

return (
<>
Expand All @@ -74,30 +90,10 @@ export default async function Preview() {

<Cart
checkoutAction={checkoutAction}
emptyState={{
title: 'Your cart is empty',
subtitle: 'Add some products to get started.',
cta: {
label: 'Continue shopping',
href: '#',
},
}}
lineItemAction={lineItemAction}
lineItems={lineItems}
summary={{
title: 'Summary',
subtotal: subtotal,
caption: 'Shipping & taxes calculated at checkout',
subtotalLabel: 'Subtotal',
shippingLabel: 'Shipping',
shipping: 'TBD',
taxLabel: 'Tax',
tax: 'TBD',
// grandTotalLabel: 'Total',
// grandTotal: '$127.60',
ctaLabel: 'Checkout',
}}
title="Cart"
summaryLineItems={summaryLineItems}
summaryTotal={summaryTotal}
/>

<Subscribe
Expand Down
45 changes: 19 additions & 26 deletions apps/web/vibes/soul/examples/sections/cart/electric.tsx
Original file line number Diff line number Diff line change
@@ -1,42 +1,35 @@
import { getLineItems, getSubtotal } from '@/vibes/soul/data/line-items';
import { Cart, CartLineItem } from '@/vibes/soul/sections/cart';
import { CartSummaryLineItem } from '@/vibes/soul/sections/cart/summary';

import { checkoutAction, lineItemAction } from './actions';

export default async function Preview() {
// const products = await getLineItems('Electric')
export default function Preview() {
const lineItems = new Promise<CartLineItem[]>((res) =>
setTimeout(() => res(getLineItems('Electric')), 5000),
setTimeout(() => res(getLineItems('Electric')), 1000),
);
const subtotal = await getSubtotal('Electric');
const summaryLineItems = getSubtotal('Electric').then((subtotal) => {
return new Promise<CartSummaryLineItem[]>((res) =>
setTimeout(
() =>
res([
{ label: 'Subtotal', value: subtotal },
{ label: 'Shipping', value: 'TBD' },
{ label: 'Tax', value: 'TBD' },
]),
1000,
),
);
});
const summaryTotal = new Promise<string>((res) => setTimeout(() => res('127.60'), 1000));

return (
<Cart
checkoutAction={checkoutAction}
emptyState={{
title: 'Your cart is empty',
subtitle: 'Add some products to get started.',
cta: {
label: 'Continue shopping',
href: '#',
},
}}
lineItemAction={lineItemAction}
lineItems={lineItems}
summary={{
title: 'Summary',
subtotal: subtotal,
caption: 'Shipping & taxes calculated at checkout',
subtotalLabel: 'Subtotal',
shippingLabel: 'Shipping',
shipping: 'TBD',
taxLabel: 'Tax',
tax: 'TBD',
// grandTotalLabel: 'Total',
// grandTotal: '$127.60',
ctaLabel: 'Checkout',
}}
title="Cart"
summaryLineItems={summaryLineItems}
summaryTotal={summaryTotal}
/>
);
}
44 changes: 18 additions & 26 deletions apps/web/vibes/soul/examples/sections/cart/loading-electric.tsx
Original file line number Diff line number Diff line change
@@ -1,43 +1,35 @@
import { getLineItems, getSubtotal } from '@/vibes/soul/data/line-items';
import { Cart, CartLineItem } from '@/vibes/soul/sections/cart';
import { CartSummaryLineItem } from '@/vibes/soul/sections/cart/summary';

import { checkoutAction, lineItemAction } from './actions';

export default function Preview() {
const lineItems = new Promise<CartLineItem[]>((res) =>
setTimeout(() => res(getLineItems('Electric')), 5000),
);
const subtotal = new Promise<string>((res) =>
setTimeout(() => res(getSubtotal('Electric')), 10000),
setTimeout(() => res(getLineItems('Electric')), 1000),
);
const summaryLineItems = getSubtotal('Electric').then((subtotal) => {
return new Promise<CartSummaryLineItem[]>((res) =>
setTimeout(
() =>
res([
{ label: 'Subtotal', value: subtotal },
{ label: 'Shipping', value: 'TBD' },
{ label: 'Tax', value: 'TBD' },
]),
1000,
),
);
});
const summaryTotal = new Promise<string>((res) => setTimeout(() => res('127.60'), 1000));

return (
<Cart
checkoutAction={checkoutAction}
emptyState={{
title: 'Your cart is empty',
subtitle: 'Add some products to get started.',
cta: {
label: 'Continue shopping',
href: '#',
},
}}
lineItemAction={lineItemAction}
lineItems={lineItems}
summary={{
title: 'Summary',
subtotal: subtotal,
caption: 'Shipping & taxes calculated at checkout',
subtotalLabel: 'Subtotal',
shippingLabel: 'Shipping',
shipping: 'TBD',
taxLabel: 'Tax',
tax: 'TBD',
// grandTotalLabel: 'Total',
// grandTotal: '$127.60',
ctaLabel: 'Checkout',
}}
title="Cart"
summaryLineItems={summaryLineItems}
summaryTotal={summaryTotal}
/>
);
}
44 changes: 18 additions & 26 deletions apps/web/vibes/soul/examples/sections/cart/loading-luxury.tsx
Original file line number Diff line number Diff line change
@@ -1,43 +1,35 @@
import { getLineItems, getSubtotal } from '@/vibes/soul/data/line-items';
import { Cart, CartLineItem } from '@/vibes/soul/sections/cart';
import { CartSummaryLineItem } from '@/vibes/soul/sections/cart/summary';

import { checkoutAction, lineItemAction } from './actions';

export default function Preview() {
const lineItems = new Promise<CartLineItem[]>((res) =>
setTimeout(() => res(getLineItems('Luxury')), 5000),
);
const subtotal = new Promise<string>((res) =>
setTimeout(() => res(getSubtotal('Luxury')), 10000),
setTimeout(() => res(getLineItems('Luxury')), 1000),
);
const summaryLineItems = getSubtotal('Luxury').then((subtotal) => {
return new Promise<CartSummaryLineItem[]>((res) =>
setTimeout(
() =>
res([
{ label: 'Subtotal', value: subtotal },
{ label: 'Shipping', value: 'TBD' },
{ label: 'Tax', value: 'TBD' },
]),
1000,
),
);
});
const summaryTotal = new Promise<string>((res) => setTimeout(() => res('127.60'), 1000));

return (
<Cart
checkoutAction={checkoutAction}
emptyState={{
title: 'Your cart is empty',
subtitle: 'Add some products to get started.',
cta: {
label: 'Continue shopping',
href: '#',
},
}}
lineItemAction={lineItemAction}
lineItems={lineItems}
summary={{
title: 'Summary',
subtotal: subtotal,
caption: 'Shipping & taxes calculated at checkout',
subtotalLabel: 'Subtotal',
shippingLabel: 'Shipping',
shipping: 'TBD',
taxLabel: 'Tax',
tax: 'TBD',
// grandTotalLabel: 'Total',
// grandTotal: '$127.60',
ctaLabel: 'Checkout',
}}
title="Cart"
summaryLineItems={summaryLineItems}
summaryTotal={summaryTotal}
/>
);
}
Loading

0 comments on commit f942c85

Please sign in to comment.