|
|
@ -1,4 +1,4 @@ |
|
|
import React, { useState } from 'react'; |
|
|
|
|
|
|
|
|
import React, { useEffect, useMemo, useRef, useState } from 'react'; |
|
|
import { useLocation, useNavigate, useParams } from 'react-router-dom'; |
|
|
import { useLocation, useNavigate, useParams } from 'react-router-dom'; |
|
|
import { MobileShell } from '../../components/layout/MobileShell'; |
|
|
import { MobileShell } from '../../components/layout/MobileShell'; |
|
|
import { CompactProductCard } from '../../components/common/CompactProductCard'; |
|
|
import { CompactProductCard } from '../../components/common/CompactProductCard'; |
|
|
@ -20,7 +20,13 @@ import { |
|
|
useCreateReviewMutation, |
|
|
useCreateReviewMutation, |
|
|
useProductDetailQuery, |
|
|
useProductDetailQuery, |
|
|
} from '../../lib/shopQueries'; |
|
|
} from '../../lib/shopQueries'; |
|
|
import { copyToClipboard } from '../../lib/webview-actions'; |
|
|
|
|
|
|
|
|
import { |
|
|
|
|
|
copyToClipboard, |
|
|
|
|
|
isInFlutterWebView, |
|
|
|
|
|
pickFileViaFlutterBridge, |
|
|
|
|
|
} from '../../lib/webview-actions'; |
|
|
|
|
|
|
|
|
|
|
|
const MAX_REVIEW_IMAGE_BYTES = 10 * 1024 * 1024; |
|
|
|
|
|
|
|
|
const STATIC_PRODUCT_REVIEWS = [ |
|
|
const STATIC_PRODUCT_REVIEWS = [ |
|
|
{ |
|
|
{ |
|
|
@ -74,8 +80,39 @@ export const ShopSinglePage: React.FC = () => { |
|
|
const [activeTab, setActiveTab] = useState<'info' | 'review'>('info'); |
|
|
const [activeTab, setActiveTab] = useState<'info' | 'review'>('info'); |
|
|
const [reviewRating, setReviewRating] = useState(5); |
|
|
const [reviewRating, setReviewRating] = useState(5); |
|
|
const [reviewComment, setReviewComment] = useState(''); |
|
|
const [reviewComment, setReviewComment] = useState(''); |
|
|
|
|
|
const [reviewImage, setReviewImage] = useState<{ |
|
|
|
|
|
file: File; |
|
|
|
|
|
previewUrl: string; |
|
|
|
|
|
isObjectUrl: boolean; |
|
|
|
|
|
} | null>(null); |
|
|
|
|
|
const [pickingReviewImage, setPickingReviewImage] = useState(false); |
|
|
|
|
|
const reviewFileInputRef = useRef<HTMLInputElement | null>(null); |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
|
return () => { |
|
|
|
|
|
if (reviewImage?.isObjectUrl) { |
|
|
|
|
|
URL.revokeObjectURL(reviewImage.previewUrl); |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
}, [reviewImage]); |
|
|
|
|
|
|
|
|
const resolvedRef = productId || 'islam-in-the-bible-book'; |
|
|
const resolvedRef = productId || 'islam-in-the-bible-book'; |
|
|
|
|
|
const [slideState, setSlideState] = useState<{ ref: string; index: number }>({ |
|
|
|
|
|
ref: resolvedRef, |
|
|
|
|
|
index: 0, |
|
|
|
|
|
}); |
|
|
|
|
|
const [dragOffset, setDragOffset] = useState(0); |
|
|
|
|
|
const [isDragging, setIsDragging] = useState(false); |
|
|
|
|
|
const [heroEl, setHeroEl] = useState<HTMLDivElement | null>(null); |
|
|
|
|
|
const dragStartRef = useRef<{ |
|
|
|
|
|
id: number; |
|
|
|
|
|
x: number; |
|
|
|
|
|
y: number; |
|
|
|
|
|
lastX: number; |
|
|
|
|
|
time: number; |
|
|
|
|
|
locked: 'x' | null; |
|
|
|
|
|
} | null>(null); |
|
|
|
|
|
const wheelCooldownRef = useRef(0); |
|
|
const productQuery = useProductDetailQuery(resolvedRef, !isBare); |
|
|
const productQuery = useProductDetailQuery(resolvedRef, !isBare); |
|
|
const createReviewMutation = useCreateReviewMutation(); |
|
|
const createReviewMutation = useCreateReviewMutation(); |
|
|
|
|
|
|
|
|
@ -133,6 +170,62 @@ export const ShopSinglePage: React.FC = () => { |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const stageReviewFile = ( |
|
|
|
|
|
file: File, |
|
|
|
|
|
previewUrl?: string, |
|
|
|
|
|
isObjectUrl = false |
|
|
|
|
|
) => { |
|
|
|
|
|
if (file.type && !file.type.startsWith('image/')) { |
|
|
|
|
|
if (isObjectUrl && previewUrl) URL.revokeObjectURL(previewUrl); |
|
|
|
|
|
showToast(tr('Failed to upload image. Please try another file.')); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
if (file.size > MAX_REVIEW_IMAGE_BYTES) { |
|
|
|
|
|
if (isObjectUrl && previewUrl) URL.revokeObjectURL(previewUrl); |
|
|
|
|
|
showToast('Image exceeds the 10 MB size limit'); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
setReviewImage({ |
|
|
|
|
|
file, |
|
|
|
|
|
previewUrl: previewUrl || URL.createObjectURL(file), |
|
|
|
|
|
isObjectUrl: previewUrl ? isObjectUrl : true, |
|
|
|
|
|
}); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const handlePickReviewImage = async () => { |
|
|
|
|
|
if (isBare || submittingReview || pickingReviewImage) return; |
|
|
|
|
|
if (isInFlutterWebView()) { |
|
|
|
|
|
setPickingReviewImage(true); |
|
|
|
|
|
try { |
|
|
|
|
|
const picked = await pickFileViaFlutterBridge('image'); |
|
|
|
|
|
if (!picked) return; |
|
|
|
|
|
if (picked.file) { |
|
|
|
|
|
stageReviewFile(picked.file, picked.url, Boolean(picked.isObjectUrl)); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
const resp = await fetch(resolveMediaUrl(picked.url)); |
|
|
|
|
|
const blob = await resp.blob(); |
|
|
|
|
|
stageReviewFile( |
|
|
|
|
|
new File([blob], picked.name || `review-${Date.now()}.jpg`, { |
|
|
|
|
|
type: blob.type || 'image/jpeg', |
|
|
|
|
|
}) |
|
|
|
|
|
); |
|
|
|
|
|
} catch { |
|
|
|
|
|
showToast(tr('Failed to upload image. Please try another file.')); |
|
|
|
|
|
} finally { |
|
|
|
|
|
setPickingReviewImage(false); |
|
|
|
|
|
} |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
reviewFileInputRef.current?.click(); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const handleReviewFileChange = (e: React.ChangeEvent<HTMLInputElement>) => { |
|
|
|
|
|
const file = e.target.files?.[0]; |
|
|
|
|
|
e.target.value = ''; |
|
|
|
|
|
if (file) stageReviewFile(file); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
const handleSubmitReview = async (e: React.FormEvent) => { |
|
|
const handleSubmitReview = async (e: React.FormEvent) => { |
|
|
e.preventDefault(); |
|
|
e.preventDefault(); |
|
|
if (!reviewComment.trim() || submittingReview) return; |
|
|
if (!reviewComment.trim() || submittingReview) return; |
|
|
@ -149,19 +242,198 @@ export const ShopSinglePage: React.FC = () => { |
|
|
payload: { |
|
|
payload: { |
|
|
rating: reviewRating, |
|
|
rating: reviewRating, |
|
|
comment: reviewComment.trim(), |
|
|
comment: reviewComment.trim(), |
|
|
|
|
|
image: reviewImage?.file, |
|
|
}, |
|
|
}, |
|
|
}); |
|
|
}); |
|
|
setReviewComment(''); |
|
|
setReviewComment(''); |
|
|
|
|
|
setReviewImage(null); |
|
|
showToast('Review submitted'); |
|
|
showToast('Review submitted'); |
|
|
} catch (err) { |
|
|
} catch (err) { |
|
|
showToast(err instanceof Error ? err.message : 'Could not post review'); |
|
|
showToast(err instanceof Error ? err.message : 'Could not post review'); |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
const heroImageSrc = liveProduct |
|
|
|
|
|
? resolveMediaUrl(liveProduct.hero_image_url || liveProduct.primary_image_url) || |
|
|
|
|
|
'/assets/images/product-duffel-bag-hero.png' |
|
|
|
|
|
: '/assets/images/product-duffel-bag-hero.png'; |
|
|
|
|
|
|
|
|
const productTitle = liveProduct?.title || 'Islam in the Bible Book'; |
|
|
|
|
|
|
|
|
|
|
|
const gallerySlides = useMemo(() => { |
|
|
|
|
|
if (liveProduct) { |
|
|
|
|
|
const mediaSlides = (Array.isArray(liveProduct.media) ? liveProduct.media : []) |
|
|
|
|
|
.slice() |
|
|
|
|
|
.sort((a, b) => a.sort_order - b.sort_order || a.id - b.id) |
|
|
|
|
|
.map((m, idx) => ({ |
|
|
|
|
|
id: `media-${m.id}-${idx}`, |
|
|
|
|
|
src: resolveMediaUrl(m.image_url), |
|
|
|
|
|
alt: m.alt_text || productTitle, |
|
|
|
|
|
})) |
|
|
|
|
|
.filter((s) => Boolean(s.src)); |
|
|
|
|
|
|
|
|
|
|
|
if (mediaSlides.length > 0) { |
|
|
|
|
|
return mediaSlides; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return [ |
|
|
|
|
|
{ |
|
|
|
|
|
id: 'hero-fallback', |
|
|
|
|
|
src: |
|
|
|
|
|
resolveMediaUrl( |
|
|
|
|
|
liveProduct.hero_image_url || liveProduct.primary_image_url |
|
|
|
|
|
) || '/assets/images/product-duffel-bag-hero.png', |
|
|
|
|
|
alt: productTitle, |
|
|
|
|
|
}, |
|
|
|
|
|
]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!useMockFallback) { |
|
|
|
|
|
return []; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return [ |
|
|
|
|
|
{ |
|
|
|
|
|
id: 'mock-1', |
|
|
|
|
|
src: '/assets/images/product-duffel-bag-hero.png', |
|
|
|
|
|
alt: productTitle, |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
id: 'mock-2', |
|
|
|
|
|
src: '/assets/images/product-brown-leather-bag.png', |
|
|
|
|
|
alt: productTitle, |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
id: 'mock-3', |
|
|
|
|
|
src: '/assets/images/product-boby-backpack.png', |
|
|
|
|
|
alt: productTitle, |
|
|
|
|
|
}, |
|
|
|
|
|
]; |
|
|
|
|
|
}, [liveProduct, productTitle, useMockFallback]); |
|
|
|
|
|
|
|
|
|
|
|
const maxSlideIndex = Math.max(0, gallerySlides.length - 1); |
|
|
|
|
|
const activeSlide = |
|
|
|
|
|
slideState.ref === resolvedRef |
|
|
|
|
|
? Math.min(slideState.index, maxSlideIndex) |
|
|
|
|
|
: 0; |
|
|
|
|
|
|
|
|
|
|
|
const setActiveSlide = (next: number | ((prev: number) => number)) => { |
|
|
|
|
|
setSlideState((prev) => { |
|
|
|
|
|
const current = |
|
|
|
|
|
prev.ref === resolvedRef ? Math.min(prev.index, maxSlideIndex) : 0; |
|
|
|
|
|
const raw = typeof next === 'function' ? next(current) : next; |
|
|
|
|
|
return { |
|
|
|
|
|
ref: resolvedRef, |
|
|
|
|
|
index: Math.max(0, Math.min(maxSlideIndex, raw)), |
|
|
|
|
|
}; |
|
|
|
|
|
}); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
|
if (!heroEl) return; |
|
|
|
|
|
// Consume horizontal touchmove so Android WebView / Flutter does not cancel the swipe
|
|
|
|
|
|
const onTouchMove = (e: TouchEvent) => { |
|
|
|
|
|
if (dragStartRef.current?.locked === 'x' && e.cancelable) { |
|
|
|
|
|
e.preventDefault(); |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
heroEl.addEventListener('touchmove', onTouchMove, { passive: false }); |
|
|
|
|
|
return () => { |
|
|
|
|
|
heroEl.removeEventListener('touchmove', onTouchMove); |
|
|
|
|
|
}; |
|
|
|
|
|
}, [heroEl]); |
|
|
|
|
|
|
|
|
|
|
|
const handleGalleryPointerDown = (e: React.PointerEvent<HTMLDivElement>) => { |
|
|
|
|
|
if (!e.isPrimary || gallerySlides.length <= 1) return; |
|
|
|
|
|
if (e.pointerType === 'mouse' && e.button !== 0) return; |
|
|
|
|
|
dragStartRef.current = { |
|
|
|
|
|
id: e.pointerId, |
|
|
|
|
|
x: e.clientX, |
|
|
|
|
|
y: e.clientY, |
|
|
|
|
|
lastX: e.clientX, |
|
|
|
|
|
time: Date.now(), |
|
|
|
|
|
locked: null, |
|
|
|
|
|
}; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const handleGalleryPointerMove = (e: React.PointerEvent<HTMLDivElement>) => { |
|
|
|
|
|
const start = dragStartRef.current; |
|
|
|
|
|
if (!start || start.id !== e.pointerId) return; |
|
|
|
|
|
|
|
|
|
|
|
start.lastX = e.clientX; |
|
|
|
|
|
const dx = e.clientX - start.x; |
|
|
|
|
|
const dy = e.clientY - start.y; |
|
|
|
|
|
|
|
|
|
|
|
if (!start.locked) { |
|
|
|
|
|
const absX = Math.abs(dx); |
|
|
|
|
|
const absY = Math.abs(dy); |
|
|
|
|
|
if (absX < 6 && absY < 8) return; |
|
|
|
|
|
if (absY > absX) { |
|
|
|
|
|
dragStartRef.current = null; |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
start.locked = 'x'; |
|
|
|
|
|
if (e.pointerType === 'mouse') { |
|
|
|
|
|
e.currentTarget.setPointerCapture(e.pointerId); |
|
|
|
|
|
} |
|
|
|
|
|
setIsDragging(true); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const atEdge = |
|
|
|
|
|
(activeSlide === 0 && dx > 0) || |
|
|
|
|
|
(activeSlide === gallerySlides.length - 1 && dx < 0); |
|
|
|
|
|
setDragOffset(atEdge ? dx * 0.3 : dx); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const finishGalleryDrag = ( |
|
|
|
|
|
e: React.PointerEvent<HTMLDivElement>, |
|
|
|
|
|
cancelled = false |
|
|
|
|
|
) => { |
|
|
|
|
|
const start = dragStartRef.current; |
|
|
|
|
|
if (!start || start.id !== e.pointerId) return; |
|
|
|
|
|
dragStartRef.current = null; |
|
|
|
|
|
|
|
|
|
|
|
if (e.currentTarget.hasPointerCapture(e.pointerId)) { |
|
|
|
|
|
e.currentTarget.releasePointerCapture(e.pointerId); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (start.locked === 'x' && !cancelled) { |
|
|
|
|
|
const endX = Number.isFinite(e.clientX) ? e.clientX : start.lastX; |
|
|
|
|
|
const dx = endX - start.x; |
|
|
|
|
|
const elapsed = Date.now() - start.time; |
|
|
|
|
|
const threshold = Math.min(50, (e.currentTarget.clientWidth || 375) * 0.16); |
|
|
|
|
|
const isQuickFlick = elapsed < 250 && Math.abs(dx) > 20; |
|
|
|
|
|
|
|
|
|
|
|
if (dx <= -threshold || (isQuickFlick && dx < 0)) { |
|
|
|
|
|
setActiveSlide((prev) => prev + 1); |
|
|
|
|
|
} else if (dx >= threshold || (isQuickFlick && dx > 0)) { |
|
|
|
|
|
setActiveSlide((prev) => prev - 1); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
setIsDragging(false); |
|
|
|
|
|
setDragOffset(0); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const handleGalleryWheel = (e: React.WheelEvent<HTMLDivElement>) => { |
|
|
|
|
|
if ( |
|
|
|
|
|
gallerySlides.length <= 1 || |
|
|
|
|
|
Math.abs(e.deltaX) <= Math.abs(e.deltaY) || |
|
|
|
|
|
Math.abs(e.deltaX) < 20 |
|
|
|
|
|
) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
const now = Date.now(); |
|
|
|
|
|
if (now - wheelCooldownRef.current < 450) return; |
|
|
|
|
|
wheelCooldownRef.current = now; |
|
|
|
|
|
setActiveSlide((prev) => (e.deltaX > 0 ? prev + 1 : prev - 1)); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const handleGalleryKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => { |
|
|
|
|
|
if (gallerySlides.length <= 1) return; |
|
|
|
|
|
if (e.key === 'ArrowRight') { |
|
|
|
|
|
e.preventDefault(); |
|
|
|
|
|
setActiveSlide((prev) => prev + 1); |
|
|
|
|
|
} else if (e.key === 'ArrowLeft') { |
|
|
|
|
|
e.preventDefault(); |
|
|
|
|
|
setActiveSlide((prev) => prev - 1); |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
const displayReviews = |
|
|
const displayReviews = |
|
|
!isBare && reviews |
|
|
!isBare && reviews |
|
|
@ -171,10 +443,14 @@ export const ShopSinglePage: React.FC = () => { |
|
|
date: r.formatted_date, |
|
|
date: r.formatted_date, |
|
|
rating: r.rating, |
|
|
rating: r.rating, |
|
|
comment: r.comment, |
|
|
comment: r.comment, |
|
|
|
|
|
imageUrl: resolveMediaUrl(r.image_url), |
|
|
})) |
|
|
})) |
|
|
: useMockFallback |
|
|
: useMockFallback |
|
|
? STATIC_PRODUCT_REVIEWS |
|
|
|
|
|
|
|
|
? STATIC_PRODUCT_REVIEWS.map((r) => ({ ...r, imageUrl: '' })) |
|
|
: []; |
|
|
: []; |
|
|
|
|
|
const reviewsCount = liveProduct |
|
|
|
|
|
? Math.max(liveProduct.reviews_count ?? 0, displayReviews.length) |
|
|
|
|
|
: displayReviews.length; |
|
|
|
|
|
|
|
|
const storeDetail = liveProduct?.store_detail; |
|
|
const storeDetail = liveProduct?.store_detail; |
|
|
const storeSlug = storeDetail?.slug || liveProduct?.store_slug || 'al-hujjah-books'; |
|
|
const storeSlug = storeDetail?.slug || liveProduct?.store_slug || 'al-hujjah-books'; |
|
|
@ -183,18 +459,70 @@ export const ShopSinglePage: React.FC = () => { |
|
|
|
|
|
|
|
|
return ( |
|
|
return ( |
|
|
<MobileShell width={375} height={1233} backgroundColor="#f3f1ef"> |
|
|
<MobileShell width={375} height={1233} backgroundColor="#f3f1ef"> |
|
|
{/* Hero Product Image & Floating Top Controls */} |
|
|
|
|
|
<div className="habib-single-hero-wrap"> |
|
|
|
|
|
|
|
|
{/* Hero Product Image Gallery & Floating Top Controls */} |
|
|
|
|
|
<div |
|
|
|
|
|
ref={setHeroEl} |
|
|
|
|
|
className="habib-single-hero-wrap" |
|
|
|
|
|
role="region" |
|
|
|
|
|
aria-roledescription="carousel" |
|
|
|
|
|
aria-label={tr('Product images')} |
|
|
|
|
|
onWheel={handleGalleryWheel} |
|
|
|
|
|
onKeyDown={handleGalleryKeyDown} |
|
|
|
|
|
style={{ touchAction: gallerySlides.length > 1 ? 'pan-y' : undefined }} |
|
|
|
|
|
> |
|
|
{isProductShimmer ? ( |
|
|
{isProductShimmer ? ( |
|
|
<ShimmerBox width="100%" height="100%" borderRadius={0} /> |
|
|
<ShimmerBox width="100%" height="100%" borderRadius={0} /> |
|
|
) : !liveProduct && !useMockFallback ? ( |
|
|
|
|
|
|
|
|
) : gallerySlides.length === 0 ? ( |
|
|
<div style={{ width: '100%', height: '100%', backgroundColor: '#e8e4df' }} /> |
|
|
<div style={{ width: '100%', height: '100%', backgroundColor: '#e8e4df' }} /> |
|
|
) : ( |
|
|
) : ( |
|
|
<img |
|
|
|
|
|
className="habib-single-hero-img" |
|
|
|
|
|
src={heroImageSrc} |
|
|
|
|
|
alt={liveProduct?.title || 'Islam in the Bible Book'} |
|
|
|
|
|
/> |
|
|
|
|
|
|
|
|
<div |
|
|
|
|
|
onPointerDown={handleGalleryPointerDown} |
|
|
|
|
|
onPointerMove={handleGalleryPointerMove} |
|
|
|
|
|
onPointerUp={(e) => finishGalleryDrag(e)} |
|
|
|
|
|
onPointerCancel={(e) => finishGalleryDrag(e, true)} |
|
|
|
|
|
onLostPointerCapture={(e) => { |
|
|
|
|
|
if (e.target === e.currentTarget) finishGalleryDrag(e, true); |
|
|
|
|
|
}} |
|
|
|
|
|
style={{ |
|
|
|
|
|
direction: 'ltr', |
|
|
|
|
|
display: 'flex', |
|
|
|
|
|
width: '100%', |
|
|
|
|
|
height: '100%', |
|
|
|
|
|
transform: `translateX(calc(-${activeSlide * 100}% + ${dragOffset}px))`, |
|
|
|
|
|
transition: isDragging |
|
|
|
|
|
? 'none' |
|
|
|
|
|
: 'transform 380ms cubic-bezier(0.22, 1, 0.36, 1)', |
|
|
|
|
|
willChange: gallerySlides.length > 1 ? 'transform' : undefined, |
|
|
|
|
|
touchAction: gallerySlides.length > 1 ? 'pan-y' : undefined, |
|
|
|
|
|
userSelect: 'none', |
|
|
|
|
|
cursor: |
|
|
|
|
|
gallerySlides.length > 1 |
|
|
|
|
|
? isDragging |
|
|
|
|
|
? 'grabbing' |
|
|
|
|
|
: 'grab' |
|
|
|
|
|
: undefined, |
|
|
|
|
|
}} |
|
|
|
|
|
> |
|
|
|
|
|
{gallerySlides.map((slide) => ( |
|
|
|
|
|
<div |
|
|
|
|
|
key={slide.id} |
|
|
|
|
|
style={{ |
|
|
|
|
|
flex: '0 0 100%', |
|
|
|
|
|
width: '100%', |
|
|
|
|
|
height: '100%', |
|
|
|
|
|
overflow: 'hidden', |
|
|
|
|
|
}} |
|
|
|
|
|
> |
|
|
|
|
|
<img |
|
|
|
|
|
className="habib-single-hero-img" |
|
|
|
|
|
src={slide.src} |
|
|
|
|
|
alt={slide.alt} |
|
|
|
|
|
draggable={false} |
|
|
|
|
|
style={{ pointerEvents: 'none' }} |
|
|
|
|
|
/> |
|
|
|
|
|
</div> |
|
|
|
|
|
))} |
|
|
|
|
|
</div> |
|
|
)} |
|
|
)} |
|
|
|
|
|
|
|
|
{/* Floating Top Action Row */} |
|
|
{/* Floating Top Action Row */} |
|
|
@ -207,6 +535,8 @@ export const ShopSinglePage: React.FC = () => { |
|
|
display: 'flex', |
|
|
display: 'flex', |
|
|
alignItems: 'center', |
|
|
alignItems: 'center', |
|
|
justifyContent: 'space-between', |
|
|
justifyContent: 'space-between', |
|
|
|
|
|
zIndex: 2, |
|
|
|
|
|
pointerEvents: 'none', |
|
|
}} |
|
|
}} |
|
|
> |
|
|
> |
|
|
<button |
|
|
<button |
|
|
@ -225,6 +555,7 @@ export const ShopSinglePage: React.FC = () => { |
|
|
display: 'flex', |
|
|
display: 'flex', |
|
|
alignItems: 'center', |
|
|
alignItems: 'center', |
|
|
justifyContent: 'center', |
|
|
justifyContent: 'center', |
|
|
|
|
|
pointerEvents: 'auto', |
|
|
}} |
|
|
}} |
|
|
> |
|
|
> |
|
|
<img |
|
|
<img |
|
|
@ -244,6 +575,7 @@ export const ShopSinglePage: React.FC = () => { |
|
|
position: 'relative', |
|
|
position: 'relative', |
|
|
width: 88, |
|
|
width: 88, |
|
|
height: 40, |
|
|
height: 40, |
|
|
|
|
|
pointerEvents: 'auto', |
|
|
}} |
|
|
}} |
|
|
> |
|
|
> |
|
|
<img |
|
|
<img |
|
|
@ -289,19 +621,51 @@ export const ShopSinglePage: React.FC = () => { |
|
|
</div> |
|
|
</div> |
|
|
|
|
|
|
|
|
{/* Image Carousel Dots */} |
|
|
{/* Image Carousel Dots */} |
|
|
{!isProductShimmer && ( |
|
|
|
|
|
<img |
|
|
|
|
|
src="/assets/images/indicator-carousel-dots.svg" |
|
|
|
|
|
alt="" |
|
|
|
|
|
|
|
|
{!isProductShimmer && gallerySlides.length > 1 && ( |
|
|
|
|
|
<div |
|
|
style={{ |
|
|
style={{ |
|
|
|
|
|
direction: 'ltr', |
|
|
position: 'absolute', |
|
|
position: 'absolute', |
|
|
left: '50%', |
|
|
left: '50%', |
|
|
bottom: 56, |
|
|
|
|
|
|
|
|
bottom: 50, |
|
|
transform: 'translateX(-50%)', |
|
|
transform: 'translateX(-50%)', |
|
|
width: 38, |
|
|
|
|
|
height: 7, |
|
|
|
|
|
|
|
|
display: 'flex', |
|
|
|
|
|
alignItems: 'center', |
|
|
|
|
|
gap: 4, |
|
|
|
|
|
zIndex: 1, |
|
|
}} |
|
|
}} |
|
|
/> |
|
|
|
|
|
|
|
|
> |
|
|
|
|
|
{gallerySlides.map((slide, idx) => { |
|
|
|
|
|
const isActive = activeSlide === idx; |
|
|
|
|
|
return ( |
|
|
|
|
|
<button |
|
|
|
|
|
key={slide.id} |
|
|
|
|
|
type="button" |
|
|
|
|
|
aria-label={`Show product image ${idx + 1} of ${gallerySlides.length}`} |
|
|
|
|
|
aria-current={isActive ? 'true' : undefined} |
|
|
|
|
|
onClick={() => setActiveSlide(idx)} |
|
|
|
|
|
style={{ |
|
|
|
|
|
padding: '6px 0', |
|
|
|
|
|
border: 'none', |
|
|
|
|
|
background: 'transparent', |
|
|
|
|
|
cursor: 'pointer', |
|
|
|
|
|
display: 'flex', |
|
|
|
|
|
alignItems: 'center', |
|
|
|
|
|
}} |
|
|
|
|
|
> |
|
|
|
|
|
<span |
|
|
|
|
|
style={{ |
|
|
|
|
|
width: isActive ? 16 : 7, |
|
|
|
|
|
height: 7, |
|
|
|
|
|
borderRadius: 3.5, |
|
|
|
|
|
backgroundColor: isActive ? '#747474' : '#d7dbe2', |
|
|
|
|
|
transition: 'width 280ms ease, background-color 280ms ease', |
|
|
|
|
|
}} |
|
|
|
|
|
/> |
|
|
|
|
|
</button> |
|
|
|
|
|
); |
|
|
|
|
|
})} |
|
|
|
|
|
</div> |
|
|
)} |
|
|
)} |
|
|
</div> |
|
|
</div> |
|
|
|
|
|
|
|
|
@ -545,8 +909,8 @@ export const ShopSinglePage: React.FC = () => { |
|
|
{tr( |
|
|
{tr( |
|
|
isBare |
|
|
isBare |
|
|
? '0 Reviews' |
|
|
? '0 Reviews' |
|
|
: `${displayReviews.length} ${ |
|
|
|
|
|
displayReviews.length === 1 ? 'Review' : 'Reviews' |
|
|
|
|
|
|
|
|
: `${reviewsCount} ${ |
|
|
|
|
|
reviewsCount === 1 ? 'Review' : 'Reviews' |
|
|
}`
|
|
|
}`
|
|
|
)} |
|
|
)} |
|
|
</span> |
|
|
</span> |
|
|
@ -915,7 +1279,7 @@ export const ShopSinglePage: React.FC = () => { |
|
|
transition: 'color 200ms cubic-bezier(0.22, 1, 0.36, 1)', |
|
|
transition: 'color 200ms cubic-bezier(0.22, 1, 0.36, 1)', |
|
|
}} |
|
|
}} |
|
|
> |
|
|
> |
|
|
{isProductShimmer ? tr('Review') : tr(`Review(${displayReviews.length})`)} |
|
|
|
|
|
|
|
|
{isProductShimmer ? tr('Review') : tr(`Review(${reviewsCount})`)} |
|
|
</button> |
|
|
</button> |
|
|
|
|
|
|
|
|
{/* Active Tab Indicator Bar */} |
|
|
{/* Active Tab Indicator Bar */} |
|
|
@ -1053,7 +1417,7 @@ export const ShopSinglePage: React.FC = () => { |
|
|
> |
|
|
> |
|
|
{isProductShimmer |
|
|
{isProductShimmer |
|
|
? tr('Customer Reviews') |
|
|
? tr('Customer Reviews') |
|
|
: tr(`Customer Reviews (${displayReviews.length})`)} |
|
|
|
|
|
|
|
|
: tr(`Customer Reviews (${reviewsCount})`)} |
|
|
</span> |
|
|
</span> |
|
|
<div style={{ display: 'inline-flex', alignItems: 'center', gap: 4 }}> |
|
|
<div style={{ display: 'inline-flex', alignItems: 'center', gap: 4 }}> |
|
|
<img |
|
|
<img |
|
|
@ -1150,6 +1514,13 @@ export const ShopSinglePage: React.FC = () => { |
|
|
))} |
|
|
))} |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
|
|
|
<input |
|
|
|
|
|
ref={reviewFileInputRef} |
|
|
|
|
|
type="file" |
|
|
|
|
|
accept="image/*" |
|
|
|
|
|
onChange={handleReviewFileChange} |
|
|
|
|
|
style={{ display: 'none' }} |
|
|
|
|
|
/> |
|
|
<textarea |
|
|
<textarea |
|
|
rows={2} |
|
|
rows={2} |
|
|
value={reviewComment} |
|
|
value={reviewComment} |
|
|
@ -1165,24 +1536,132 @@ export const ShopSinglePage: React.FC = () => { |
|
|
resize: 'none', |
|
|
resize: 'none', |
|
|
}} |
|
|
}} |
|
|
/> |
|
|
/> |
|
|
<button |
|
|
|
|
|
type="submit" |
|
|
|
|
|
disabled={submittingReview || !reviewComment.trim()} |
|
|
|
|
|
|
|
|
{reviewImage && ( |
|
|
|
|
|
<div |
|
|
|
|
|
style={{ |
|
|
|
|
|
display: 'flex', |
|
|
|
|
|
alignItems: 'center', |
|
|
|
|
|
justifyContent: 'space-between', |
|
|
|
|
|
gap: 8, |
|
|
|
|
|
padding: '6px 8px', |
|
|
|
|
|
borderRadius: 10, |
|
|
|
|
|
backgroundColor: '#f8f8f8', |
|
|
|
|
|
border: '1px solid #e8e4df', |
|
|
|
|
|
}} |
|
|
|
|
|
> |
|
|
|
|
|
<div |
|
|
|
|
|
style={{ |
|
|
|
|
|
display: 'flex', |
|
|
|
|
|
alignItems: 'center', |
|
|
|
|
|
gap: 8, |
|
|
|
|
|
minWidth: 0, |
|
|
|
|
|
}} |
|
|
|
|
|
> |
|
|
|
|
|
<img |
|
|
|
|
|
src={reviewImage.previewUrl} |
|
|
|
|
|
alt={tr('Attached image')} |
|
|
|
|
|
style={{ |
|
|
|
|
|
width: 40, |
|
|
|
|
|
height: 40, |
|
|
|
|
|
borderRadius: 8, |
|
|
|
|
|
objectFit: 'cover', |
|
|
|
|
|
flexShrink: 0, |
|
|
|
|
|
}} |
|
|
|
|
|
/> |
|
|
|
|
|
<span |
|
|
|
|
|
style={{ |
|
|
|
|
|
fontFamily: 'var(--font-sans)', |
|
|
|
|
|
fontSize: 11, |
|
|
|
|
|
color: '#3d3d3d', |
|
|
|
|
|
whiteSpace: 'nowrap', |
|
|
|
|
|
overflow: 'hidden', |
|
|
|
|
|
textOverflow: 'ellipsis', |
|
|
|
|
|
}} |
|
|
|
|
|
> |
|
|
|
|
|
{reviewImage.file.name} |
|
|
|
|
|
</span> |
|
|
|
|
|
</div> |
|
|
|
|
|
<button |
|
|
|
|
|
type="button" |
|
|
|
|
|
onClick={() => setReviewImage(null)} |
|
|
|
|
|
style={{ |
|
|
|
|
|
border: 'none', |
|
|
|
|
|
background: 'transparent', |
|
|
|
|
|
color: '#d44747', |
|
|
|
|
|
fontFamily: 'var(--font-sans)', |
|
|
|
|
|
fontWeight: 600, |
|
|
|
|
|
fontSize: 11, |
|
|
|
|
|
cursor: 'pointer', |
|
|
|
|
|
flexShrink: 0, |
|
|
|
|
|
padding: '2px 4px', |
|
|
|
|
|
}} |
|
|
|
|
|
> |
|
|
|
|
|
{tr('Remove')} |
|
|
|
|
|
</button> |
|
|
|
|
|
</div> |
|
|
|
|
|
)} |
|
|
|
|
|
<div |
|
|
style={{ |
|
|
style={{ |
|
|
alignSelf: 'flex-end', |
|
|
|
|
|
padding: '6px 14px', |
|
|
|
|
|
borderRadius: 9, |
|
|
|
|
|
backgroundColor: '#292a2e', |
|
|
|
|
|
color: '#ffffff', |
|
|
|
|
|
fontFamily: 'var(--font-sans)', |
|
|
|
|
|
fontWeight: 600, |
|
|
|
|
|
fontSize: 12, |
|
|
|
|
|
cursor: 'pointer', |
|
|
|
|
|
opacity: submittingReview || !reviewComment.trim() ? 0.6 : 1, |
|
|
|
|
|
|
|
|
display: 'flex', |
|
|
|
|
|
alignItems: 'center', |
|
|
|
|
|
justifyContent: 'space-between', |
|
|
|
|
|
gap: 8, |
|
|
}} |
|
|
}} |
|
|
> |
|
|
> |
|
|
{submittingReview ? tr('Posting...') : tr('Post Review')} |
|
|
|
|
|
</button> |
|
|
|
|
|
|
|
|
<button |
|
|
|
|
|
type="button" |
|
|
|
|
|
disabled={submittingReview || pickingReviewImage} |
|
|
|
|
|
onClick={() => { |
|
|
|
|
|
void handlePickReviewImage(); |
|
|
|
|
|
}} |
|
|
|
|
|
style={{ |
|
|
|
|
|
display: 'inline-flex', |
|
|
|
|
|
alignItems: 'center', |
|
|
|
|
|
gap: 5, |
|
|
|
|
|
padding: '5px 10px', |
|
|
|
|
|
borderRadius: 9, |
|
|
|
|
|
border: '1px dashed #bcbcbc', |
|
|
|
|
|
backgroundColor: '#f8f8f8', |
|
|
|
|
|
color: '#3d3d3d', |
|
|
|
|
|
fontFamily: 'var(--font-sans)', |
|
|
|
|
|
fontWeight: 600, |
|
|
|
|
|
fontSize: 11, |
|
|
|
|
|
cursor: |
|
|
|
|
|
submittingReview || pickingReviewImage |
|
|
|
|
|
? 'not-allowed' |
|
|
|
|
|
: 'pointer', |
|
|
|
|
|
opacity: submittingReview || pickingReviewImage ? 0.6 : 1, |
|
|
|
|
|
}} |
|
|
|
|
|
> |
|
|
|
|
|
<img |
|
|
|
|
|
src="/assets/images/icon-upload-image-placeholder.svg" |
|
|
|
|
|
alt="" |
|
|
|
|
|
style={{ width: 14, height: 14, flexShrink: 0 }} |
|
|
|
|
|
/> |
|
|
|
|
|
<span> |
|
|
|
|
|
{pickingReviewImage |
|
|
|
|
|
? tr('Uploading...') |
|
|
|
|
|
: tr('+ Upload Image')} |
|
|
|
|
|
</span> |
|
|
|
|
|
</button> |
|
|
|
|
|
<button |
|
|
|
|
|
type="submit" |
|
|
|
|
|
disabled={submittingReview || !reviewComment.trim()} |
|
|
|
|
|
style={{ |
|
|
|
|
|
padding: '6px 14px', |
|
|
|
|
|
borderRadius: 9, |
|
|
|
|
|
backgroundColor: '#292a2e', |
|
|
|
|
|
color: '#ffffff', |
|
|
|
|
|
fontFamily: 'var(--font-sans)', |
|
|
|
|
|
fontWeight: 600, |
|
|
|
|
|
fontSize: 12, |
|
|
|
|
|
cursor: 'pointer', |
|
|
|
|
|
opacity: submittingReview || !reviewComment.trim() ? 0.6 : 1, |
|
|
|
|
|
}} |
|
|
|
|
|
> |
|
|
|
|
|
{submittingReview ? tr('Posting...') : tr('Post Review')} |
|
|
|
|
|
</button> |
|
|
|
|
|
</div> |
|
|
</form> |
|
|
</form> |
|
|
)} |
|
|
)} |
|
|
|
|
|
|
|
|
@ -1297,6 +1776,22 @@ export const ShopSinglePage: React.FC = () => { |
|
|
> |
|
|
> |
|
|
{review.comment} |
|
|
{review.comment} |
|
|
</div> |
|
|
</div> |
|
|
|
|
|
|
|
|
|
|
|
{review.imageUrl && ( |
|
|
|
|
|
<img |
|
|
|
|
|
src={review.imageUrl} |
|
|
|
|
|
alt={tr('Attached image')} |
|
|
|
|
|
loading="lazy" |
|
|
|
|
|
style={{ |
|
|
|
|
|
width: '100%', |
|
|
|
|
|
maxWidth: 180, |
|
|
|
|
|
maxHeight: 180, |
|
|
|
|
|
borderRadius: 10, |
|
|
|
|
|
objectFit: 'cover', |
|
|
|
|
|
border: '1px solid #ece9e5', |
|
|
|
|
|
}} |
|
|
|
|
|
/> |
|
|
|
|
|
)} |
|
|
</div> |
|
|
</div> |
|
|
)) |
|
|
)) |
|
|
)} |
|
|
)} |
|
|
|