Skip to content

Commit dd53513

Browse files
authored
Merge pull request #83 from thomasKn/thomas/fv-187-theme-content-int-strings
Add theme content strings
2 parents b51a264 + c5d22d8 commit dd53513

File tree

11 files changed

+210
-75
lines changed

11 files changed

+210
-75
lines changed

Diff for: app/components/cart/CartDetails.tsx

+8-9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {Money} from '@shopify/hydrogen';
55
import {AnimatePresence} from 'framer-motion';
66
import {useMemo} from 'react';
77

8+
import {useSanityThemeContent} from '~/hooks/useSanityThemeContent';
89
import {cn} from '~/lib/utils';
910

1011
import type {CartLayouts} from './Cart';
@@ -95,14 +96,14 @@ function CartDetailsLayout(props: {
9596
}
9697

9798
function CartCheckoutActions({checkoutUrl}: {checkoutUrl: string}) {
99+
const {themeContent} = useSanityThemeContent();
98100
if (!checkoutUrl) return null;
99101

100102
return (
101103
<div className="mt-2 flex flex-col">
102104
<Button asChild>
103105
<a href={checkoutUrl} target="_self">
104-
{/* Todo => add theme content string */}
105-
Continue to Checkout
106+
{themeContent?.cart.proceedToCheckout}
106107
</a>
107108
</Button>
108109
{/* @todo: <CartShopPayButton cart={cart} /> */}
@@ -119,6 +120,8 @@ function CartSummary({
119120
cost: CartApiQueryFragment['cost'];
120121
layout: CartLayouts;
121122
}) {
123+
const {themeContent} = useSanityThemeContent();
124+
122125
const Content = useMemo(
123126
() => (
124127
<div
@@ -128,14 +131,10 @@ function CartSummary({
128131
layout === 'page' && 'grid gap-6',
129132
])}
130133
>
131-
<h2 className="sr-only">
132-
{/* Todo => add theme content string */}
133-
Order summary
134-
</h2>
134+
<h2 className="sr-only">{themeContent?.cart.orderSummary}</h2>
135135
<dl className="grid">
136136
<div className="flex items-center justify-between font-medium">
137-
{/* Todo => add theme content string */}
138-
<span>Subtotal</span>
137+
<span>{themeContent?.cart.subtotal}</span>
139138
<span>
140139
{cost?.subtotalAmount?.amount ? (
141140
<Money className="tabular-nums" data={cost?.subtotalAmount} />
@@ -148,7 +147,7 @@ function CartSummary({
148147
{children}
149148
</div>
150149
),
151-
[children, cost?.subtotalAmount, layout],
150+
[children, cost?.subtotalAmount, layout, themeContent],
152151
);
153152

154153
if (layout === 'drawer') {

Diff for: app/components/cart/CartDiscounts.tsx

+9-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type {Cart as CartType} from '@shopify/hydrogen/storefront-api-types';
33
import {CartForm} from '@shopify/hydrogen';
44

55
import {useLocalePath} from '~/hooks/useLocalePath';
6+
import {useSanityThemeContent} from '~/hooks/useSanityThemeContent';
67
import {cn} from '~/lib/utils';
78

89
import {IconRemove} from '../icons/IconRemove';
@@ -21,6 +22,7 @@ export function CartDiscounts({
2122
discountCodes: CartType['discountCodes'];
2223
layout: 'drawer' | 'page';
2324
}) {
25+
const {themeContent} = useSanityThemeContent();
2426
const codes: string[] =
2527
discountCodes
2628
?.filter((discount) => discount.applicable)
@@ -31,8 +33,7 @@ export function CartDiscounts({
3133
{/* Have existing discount, display it with a remove option */}
3234
<dl className={codes && codes.length !== 0 ? 'grid' : 'hidden'}>
3335
<div className="flex items-center justify-between font-medium">
34-
{/* Todo => add theme content string */}
35-
<span>Discount(s)</span>
36+
<span>{themeContent?.cart.discounts}</span>
3637
<div className="flex items-center justify-between">
3738
<UpdateDiscountForm>
3839
<button className="[&>*]:pointer-events-none">
@@ -56,14 +57,16 @@ export function CartDiscounts({
5657
'items-center justify-between gap-4',
5758
)}
5859
>
59-
{/* Todo => add theme content string */}
60-
<Input name="discountCode" placeholder="Discount code" type="text" />
60+
<Input
61+
name="discountCode"
62+
placeholder={themeContent?.cart.discountCode || ''}
63+
type="text"
64+
/>
6165
<Button
6266
className={cn(layout === 'page' && 'w-full lg:w-auto')}
6367
variant="outline"
6468
>
65-
{/* Todo => add theme content string */}
66-
Apply Discount
69+
{themeContent?.cart.applyDiscount}
6770
</Button>
6871
</div>
6972
</UpdateDiscountForm>

Diff for: app/components/cart/CartEmpty.tsx

+7-10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {cx} from 'class-variance-authority';
33
import {AnimatePresence, m} from 'framer-motion';
44

55
import {useLocalePath} from '~/hooks/useLocalePath';
6+
import {useSanityThemeContent} from '~/hooks/useSanityThemeContent';
67
import {cn} from '~/lib/utils';
78

89
import type {CartLayouts} from './Cart';
@@ -19,6 +20,7 @@ export function CartEmpty({
1920
onClose?: () => void;
2021
show: boolean;
2122
}) {
23+
const {themeContent} = useSanityThemeContent();
2224
const container = {
2325
drawer: cx([
2426
'p-5 content-start gap-4 h-full pb-8 flex justify-center items-center md:gap-12 md:pb-12',
@@ -30,9 +32,6 @@ export function CartEmpty({
3032

3133
const collectionsPath = useLocalePath({path: '/collections'});
3234

33-
// Todo => add theme content string
34-
const label = 'Continue shopping';
35-
3635
return (
3736
<AnimatePresence>
3837
{show && (
@@ -54,20 +53,18 @@ export function CartEmpty({
5453
layout === 'drawer' && 'justify-center text-center',
5554
])}
5655
>
57-
<span>
58-
{/* Todo => add theme content string */}
59-
Looks like you haven&rsquo;t added anything yet, let&rsquo;s get
60-
you started!
61-
</span>
56+
<span>{themeContent?.cart.emptyMessage}</span>
6257
<div>
6358
{layout === 'page' ? (
6459
<Button asChild>
6560
<Link prefetch="intent" to={collectionsPath}>
66-
{label}
61+
{themeContent?.cart.continueShopping}
6762
</Link>
6863
</Button>
6964
) : (
70-
<Button onClick={onClose}>{label}</Button>
65+
<Button onClick={onClose}>
66+
{themeContent?.cart.continueShopping}
67+
</Button>
7168
)}
7269
</div>
7370
{/* Todo => add FeaturedProducts */}

Diff for: app/components/cart/CartLineItem.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
} from '@shopify/hydrogen';
1313

1414
import {useLocalePath} from '~/hooks/useLocalePath';
15+
import {useSanityThemeContent} from '~/hooks/useSanityThemeContent';
1516
import {cn} from '~/lib/utils';
1617

1718
import type {CartLayouts} from './Cart';
@@ -147,6 +148,7 @@ export function CartLineItem({
147148

148149
function ItemRemoveButton({lineId}: {lineId: CartLineFragment['id']}) {
149150
const cartPath = useLocalePath({path: '/cart'});
151+
const {themeContent} = useSanityThemeContent();
150152

151153
return (
152154
<CartForm
@@ -165,8 +167,7 @@ function ItemRemoveButton({lineId}: {lineId: CartLineFragment['id']}) {
165167
)}
166168
type="submit"
167169
>
168-
{/* Todo => add theme content string */}
169-
<span className="sr-only">Remove</span>
170+
<span className="sr-only">{themeContent?.cart.remove}</span>
170171
<IconRemove aria-hidden="true" />
171172
</IconButton>
172173

@@ -230,6 +231,7 @@ function UpdateCartForm({
230231
function CartLineQuantityAdjust({line}: {line: CartLineFragment}) {
231232
const optimisticId = line?.id;
232233
const optimisticData = useOptimisticData<OptimisticData>(optimisticId);
234+
const {themeContent} = useSanityThemeContent();
233235

234236
if (!line || typeof line?.quantity === 'undefined') return null;
235237

@@ -242,8 +244,7 @@ function CartLineQuantityAdjust({line}: {line: CartLineFragment}) {
242244
return (
243245
<>
244246
<label className="sr-only" htmlFor={`quantity-${lineId}`}>
245-
{/* Todo => add theme content string */}
246-
Quantity, {optimisticQuantity}
247+
{themeContent?.cart.quantity}, {optimisticQuantity}
247248
</label>
248249
<QuantitySelector>
249250
<UpdateCartForm lines={[{id: lineId, quantity: prevQuantity}]}>

Diff for: app/components/collection/Sort.tsx

+15-15
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
useColorsCssVars,
1414
} from '~/hooks/useColorsCssVars';
1515
import {useOptimisticNavigationData} from '~/hooks/useOptimisticNavigationData';
16+
import {useSanityThemeContent} from '~/hooks/useSanityThemeContent';
1617
import {cn} from '~/lib/utils';
1718

1819
import type {SortParam} from './SortFilterLayout';
@@ -39,29 +40,32 @@ function useSortItems() {
3940
const {optimisticData: clearFilters} =
4041
useOptimisticNavigationData<boolean>('clear-all-filters');
4142
const {optimisticData} = useOptimisticNavigationData<SortParam>('sort-radio');
43+
const {themeContent} = useSanityThemeContent();
4244

43-
// Todo => add strings to themeContent
4445
const items: SortItem[] = useMemo(
4546
() => [
46-
{key: 'featured', label: 'Featured'},
47+
{
48+
key: 'featured',
49+
label: themeContent?.collection?.sortFeatured || 'Featured',
50+
},
4751
{
4852
key: 'price-low-high',
49-
label: 'Price: Low - High',
53+
label: themeContent?.collection?.sortLowHigh || 'Price: Low - High',
5054
},
5155
{
5256
key: 'price-high-low',
53-
label: 'Price: High - Low',
57+
label: themeContent?.collection?.sortHighLow || 'Price: High - Low',
5458
},
5559
{
5660
key: 'best-selling',
57-
label: 'Best Selling',
61+
label: themeContent?.collection?.sortBestSelling || 'Best Selling',
5862
},
5963
{
6064
key: 'newest',
61-
label: 'Newest',
65+
label: themeContent?.collection?.sortNewest || 'Newest',
6266
},
6367
],
64-
[],
68+
[themeContent],
6569
);
6670

6771
if (optimisticData) {
@@ -88,17 +92,15 @@ function useSortItems() {
8892
export function DesktopSort(props: {sectionSettings?: CmsSectionSettings}) {
8993
const colorsCssVars = useColorsCssVars({settings: props.sectionSettings});
9094
const {activeItem, items} = useSortItems();
95+
const {themeContent} = useSanityThemeContent();
9196

9297
return (
9398
<DropdownMenu>
9499
<DropdownMenuTrigger className={cn(iconButtonClass, 'w-auto gap-1 px-2')}>
95100
<IconSort strokeWidth={1} />
96101
<span>
97102
<span className="px-2 font-medium">
98-
{/*
99-
// Todo => add strings to themeContent
100-
*/}
101-
Sort by:
103+
{themeContent?.collection?.sortBy}
102104
</span>
103105
<span>{(activeItem || items[0]).label}</span>
104106
</span>
@@ -117,17 +119,15 @@ export function DesktopSort(props: {sectionSettings?: CmsSectionSettings}) {
117119

118120
export function MobileSort() {
119121
const {items} = useSortItems();
122+
const {themeContent} = useSanityThemeContent();
120123

121124
return (
122125
<div>
123126
<div className="flex items-center gap-3">
124127
<IconSort strokeWidth={1} />
125128
<span>
126129
<span className="px-2 text-xl font-medium">
127-
{/*
128-
// Todo => add strings to themeContent
129-
*/}
130-
Sort by:
130+
{themeContent?.collection?.sortBy}
131131
</span>
132132
</span>
133133
</div>

Diff for: app/components/collection/SortFilterLayout.tsx

+7-8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {useState} from 'react';
99
import type {CmsSectionSettings} from '~/hooks/useColorsCssVars';
1010

1111
import {useOptimisticNavigationData} from '~/hooks/useOptimisticNavigationData';
12+
import {useSanityThemeContent} from '~/hooks/useSanityThemeContent';
1213
import {cn} from '~/lib/utils';
1314

1415
import {IconFilters} from '../icons/IconFilters';
@@ -64,6 +65,7 @@ export function SortFilter({
6465
const [isOpen, setIsOpen] = useState(false);
6566
const {optimisticData, pending} =
6667
useOptimisticNavigationData<boolean>('clear-all-filters');
68+
const {themeContent} = useSanityThemeContent();
6769

6870
// Here we can optimistically clear all filters and close DrawerFooter
6971
if (optimisticData) {
@@ -93,8 +95,7 @@ export function SortFilter({
9395
onClick={onClearAllFilters}
9496
variant="ghost"
9597
>
96-
{/* // Todo => add strings to themeContent */}
97-
<span>Clear all filters</span>
98+
<span>{themeContent?.collection?.clearFilters}</span>
9899
<span className="tabular-nums">
99100
({appliedFilters.length})
100101
</span>
@@ -146,8 +147,8 @@ function MobileDrawer({
146147
productsCount: number;
147148
}) {
148149
const [open, setOpen] = useState(false);
149-
// Todo => add strings to themeContent
150-
const heading = 'Filter and Sort';
150+
const {themeContent} = useSanityThemeContent();
151+
const heading = themeContent?.collection?.filterAndSort;
151152
const {pending} = useOptimisticNavigationData<boolean>('clear-all-filters');
152153

153154
return (
@@ -218,15 +219,13 @@ function MobileDrawer({
218219
onClick={onClearAllFilters}
219220
variant="ghost"
220221
>
221-
{/* // Todo => add strings to themeContent */}
222-
<span>Clear</span>
222+
<span>{themeContent?.collection?.clear}</span>
223223
<span className="tabular-nums">
224224
({appliedFilters.length})
225225
</span>
226226
</Button>
227227
<Button onClick={() => setOpen(false)}>
228-
{/* // Todo => add strings to themeContent */}
229-
Apply
228+
{themeContent?.collection?.apply}
230229
</Button>
231230
</DrawerFooter>
232231
</m.div>

Diff for: app/components/sanity/SanityImage.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ export function SanityImage({
9595
.join(', ')
9696
.concat(`, ${urlDefault} ${data.width}w`);
9797

98-
// Todo => Global image border-radius setting should apply to the wrapper <span/>
9998
// No padding should be applied to the wrapper <span/> or the <img/> tag to avoid blurry LQIP becoming visible
10099
return (
101100
<span

Diff for: app/components/sections/CollectionListSection.tsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,7 @@ function AwaitCollectionList(props: {
8686

8787
return (
8888
<Suspense fallback={props.fallback}>
89-
<Await
90-
// Todo => Add an error component
91-
errorElement={props.error}
92-
resolve={collectionListPromise}
93-
>
89+
<Await errorElement={props.error} resolve={collectionListPromise}>
9490
{(data) => {
9591
// Resolve the collection list data from Shopify with the gids from Sanity
9692
let collections:

0 commit comments

Comments
 (0)