Skip to content

Commit 214bf60

Browse files
arielWixvaleriihorsharik-wix
authored andcommitted
Fixing quick view image (#114)
1 parent 07a5b1a commit 214bf60

File tree

5 files changed

+79
-53
lines changed

5 files changed

+79
-53
lines changed

examples/astro-stores-demo/src/components/store/CategoryPage.tsx

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@ interface StoreCollectionPageProps {
3030
}
3131

3232
export const ProductGridContent = ({
33-
productPageRoute,
3433
categoriesListConfig,
3534
}: {
36-
productPageRoute: string;
3735
categoriesListConfig: CategoriesListServiceConfig;
3836
}) => {
3937
const [quickViewProduct, setQuickViewProduct] =
@@ -167,10 +165,7 @@ export const ProductGridContent = ({
167165
</div>
168166
)}
169167

170-
<a
171-
data-testid="title-navigation"
172-
href={`${productPageRoute}/${product.slug}`}
173-
>
168+
<a data-testid="title-navigation" href={`/${product.slug}`}>
174169
<h3 className="text-content-primary font-semibold mb-2 line-clamp-2">
175170
{product.name}
176171
</h3>
@@ -407,7 +402,7 @@ export const ProductGridContent = ({
407402
{/* View Product Button */}
408403
<a
409404
data-testid="view-product-button"
410-
href={`${productPageRoute}/${product.slug}`}
405+
href={`/${product.slug}`}
411406
className="w-full text-content-primary font-semibold py-2 px-4 rounded-lg transition-all duration-200 flex items-center justify-center gap-2 btn-secondary"
412407
>
413408
View Product
@@ -569,12 +564,24 @@ export const ProductGridContent = ({
569564

570565
{/* Quick View Modal */}
571566
{quickViewProduct && (
572-
<QuickViewModal
573-
product={quickViewProduct}
574-
isOpen={isQuickViewOpen}
575-
onClose={closeQuickView}
576-
productPageRoute={productPageRoute}
577-
/>
567+
<Product.Root
568+
productServiceConfig={{ productSlug: quickViewProduct.slug! }}
569+
>
570+
<Product.Loading>
571+
{({ isLoading }) => (
572+
<Product.Content>
573+
{({ product }) => (
574+
<QuickViewModal
575+
product={product}
576+
isLoading={isLoading}
577+
isOpen={isQuickViewOpen}
578+
onClose={closeQuickView}
579+
/>
580+
)}
581+
</Product.Content>
582+
)}
583+
</Product.Loading>
584+
</Product.Root>
578585
)}
579586
</div>
580587
);
@@ -644,17 +651,13 @@ export function CategoryPage({
644651
productsListConfig,
645652
productsListSearchConfig,
646653
categoriesListConfig,
647-
productPageRoute,
648654
}: StoreCollectionPageProps) {
649655
return (
650656
<ProductList.Root
651657
productsListConfig={productsListConfig}
652658
productsListSearchConfig={productsListSearchConfig}
653659
>
654-
<ProductGridContent
655-
productPageRoute={productPageRoute}
656-
categoriesListConfig={categoriesListConfig}
657-
/>
660+
<ProductGridContent categoriesListConfig={categoriesListConfig} />
658661
<LoadMoreSection />
659662
</ProductList.Root>
660663
);

examples/astro-stores-demo/src/components/store/QuickViewModal.tsx

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,21 @@ import ProductDetails from './ProductDetails';
44

55
import { CurrentCart } from '@wix/headless-ecom/react';
66
import type { LineItem } from '@wix/headless-ecom/services';
7+
import { Product } from '@wix/headless-stores/react';
78

89
interface QuickViewModalProps {
910
product: productsV3.V3Product;
1011
isOpen: boolean;
12+
isLoading: boolean;
1113
onClose: () => void;
12-
productPageRoute: string;
1314
}
1415

1516
export default function QuickViewModal({
1617
product,
18+
isLoading,
1719
isOpen,
1820
onClose,
19-
productPageRoute,
2021
}: QuickViewModalProps) {
21-
const [isLoading, setIsLoading] = useState(false);
22-
const [fullProduct, setFullProduct] = useState<productsV3.V3Product | null>(
23-
null
24-
);
2522
const [showSuccessMessage, setShowSuccessMessage] = useState(false);
2623

2724
// Handle escape key to close modal
@@ -41,29 +38,6 @@ export default function QuickViewModal({
4138
};
4239
}, [isOpen, onClose]);
4340

44-
// Load full product data when modal opens
45-
useEffect(() => {
46-
if (isOpen && product.slug) {
47-
setIsLoading(true);
48-
// Use Wix API to load full product data
49-
const loadFullProduct = async () => {
50-
try {
51-
// For now, use the existing product data since it should contain all necessary information
52-
// If more detailed product data is needed, this would require a Wix client instance
53-
setFullProduct(product);
54-
} catch (error) {
55-
console.error('Failed to load full product data:', error);
56-
// Fallback to original product data
57-
setFullProduct(product);
58-
} finally {
59-
setIsLoading(false);
60-
}
61-
};
62-
63-
loadFullProduct();
64-
}
65-
}, [isOpen, product.slug]);
66-
6741
if (!isOpen) return null;
6842

6943
return (
@@ -157,12 +131,12 @@ export default function QuickViewModal({
157131
</div>
158132
) : (
159133
<>
160-
<ProductDetails isQuickView={true} product={product} />
134+
<ProductDetails isQuickView={true} product={product!} />
161135

162136
{/* View Full Product Page Link */}
163137
<div className="mt-6 pt-6 border-t border-brand-subtle">
164138
<a
165-
href={`${productPageRoute}/${product.slug}`}
139+
href={`/${product.slug}`}
166140
className="w-full text-content-primary font-semibold py-3 px-4 rounded-lg transition-all duration-200 flex items-center justify-center gap-2 btn-primary"
167141
>
168142
View Full Product Page

examples/astro-stores-demo/src/react-pages/category/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ export default function StoreCollectionPage({
4141
productsListConfig={productsListConfig}
4242
productsListSearchConfig={productsListSearchConfig}
4343
categoriesListConfig={categoriesListConfig}
44-
productPageRoute=""
4544
/>
4645
</div>
4746
</StoreLayout>

packages/headless-components/stores/src/react/Product.tsx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,43 @@ export function Media(props: ProductMediaProps) {
201201
media,
202202
});
203203
}
204+
205+
export interface ProductProps {
206+
children: (props: ProductRenderProps) => React.ReactNode;
207+
}
208+
209+
export interface ProductRenderProps {
210+
product: V3Product;
211+
}
212+
213+
export function Content(props: ProductProps) {
214+
const service = useService(ProductServiceDefinition) as ServiceAPI<
215+
typeof ProductServiceDefinition
216+
>;
217+
218+
const product = service.product.get();
219+
220+
return props.children({
221+
product,
222+
});
223+
}
224+
225+
export interface LoadingProps {
226+
children: (props: LoadingRenderProps) => React.ReactNode;
227+
}
228+
229+
export interface LoadingRenderProps {
230+
isLoading: boolean;
231+
}
232+
233+
export function Loading(props: LoadingProps) {
234+
const service = useService(ProductServiceDefinition) as ServiceAPI<
235+
typeof ProductServiceDefinition
236+
>;
237+
238+
const isLoading = service.isLoading.get();
239+
240+
return props.children({
241+
isLoading,
242+
});
243+
}

packages/headless-components/stores/src/services/product-service.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ export const ProductServiceDefinition =
3939
*/
4040
export interface ProductServiceConfig {
4141
/** The initial product data to configure the service with */
42-
product: productsV3.V3Product;
42+
product?: productsV3.V3Product;
43+
44+
productSlug?: string;
4345
}
4446

4547
/**
@@ -84,21 +86,29 @@ export const ProductService =
8486
const product: Signal<productsV3.V3Product> = signalsService.signal(
8587
config.product as any,
8688
);
87-
const isLoading: Signal<boolean> = signalsService.signal(false as any);
89+
const isLoading: Signal<boolean> = signalsService.signal(
90+
!!config.productSlug as any,
91+
);
8892
const error: Signal<string | null> = signalsService.signal(null as any);
8993

9094
const loadProduct = async (slug: string) => {
9195
isLoading.set(true);
92-
const productResponse = await loadProductBySlug(slug);
96+
const productResponse = await loadProductBySlug(slug!);
97+
9398
if (!productResponse.product) {
9499
error.set("Product not found");
95100
} else {
96101
product.set(productResponse.product!);
97102
error.set(null);
98103
}
104+
99105
isLoading.set(false);
100106
};
101107

108+
if (config.productSlug) {
109+
loadProduct(config.productSlug);
110+
}
111+
102112
return {
103113
product,
104114
isLoading,

0 commit comments

Comments
 (0)