fix(web): update search, listing, and map components
Improve agent profile client, comparison table, image gallery/upload, listing map, filter bar, property card, and search results components with better error handling, type safety, and UX refinements. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
@@ -18,6 +18,7 @@ import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
|||||||
import { Link } from '@/i18n/navigation';
|
import { Link } from '@/i18n/navigation';
|
||||||
import type { AgentPublicProfile, AgentReviewItem } from '@/lib/agents-api';
|
import type { AgentPublicProfile, AgentReviewItem } from '@/lib/agents-api';
|
||||||
import { formatPrice } from '@/lib/currency';
|
import { formatPrice } from '@/lib/currency';
|
||||||
|
import { shimmerBlurDataURL } from '@/lib/image-blur';
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Props
|
// Props
|
||||||
@@ -340,6 +341,8 @@ function ListingCard({ listing }: { listing: AgentPublicProfile['activeListings'
|
|||||||
fill
|
fill
|
||||||
className="object-cover transition-transform group-hover:scale-105"
|
className="object-cover transition-transform group-hover:scale-105"
|
||||||
sizes="(max-width: 640px) 100vw, 50vw"
|
sizes="(max-width: 640px) 100vw, 50vw"
|
||||||
|
placeholder="blur"
|
||||||
|
blurDataURL={shimmerBlurDataURL()}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<div className="flex h-full items-center justify-center">
|
<div className="flex h-full items-center justify-center">
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { Badge } from '@/components/ui/badge';
|
|||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Link } from '@/i18n/navigation';
|
import { Link } from '@/i18n/navigation';
|
||||||
import { formatPrice, formatPricePerM2 } from '@/lib/currency';
|
import { formatPrice, formatPricePerM2 } from '@/lib/currency';
|
||||||
|
import { shimmerBlurDataURL } from '@/lib/image-blur';
|
||||||
import type { ListingDetail } from '@/lib/listings-api';
|
import type { ListingDetail } from '@/lib/listings-api';
|
||||||
|
|
||||||
const PROPERTY_TYPE_LABELS: Record<string, string> = {
|
const PROPERTY_TYPE_LABELS: Record<string, string> = {
|
||||||
@@ -80,6 +81,8 @@ export function ComparisonTable({ listings, onRemove }: ComparisonTableProps) {
|
|||||||
fill
|
fill
|
||||||
sizes="200px"
|
sizes="200px"
|
||||||
className="object-cover"
|
className="object-cover"
|
||||||
|
placeholder="blur"
|
||||||
|
blurDataURL={shimmerBlurDataURL()}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<div className="flex h-full items-center justify-center text-xs text-muted-foreground">
|
<div className="flex h-full items-center justify-center text-xs text-muted-foreground">
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
import Image from 'next/image';
|
import Image from 'next/image';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
import { ImageLightbox } from '@/components/listings/image-lightbox';
|
||||||
|
import { shimmerBlurDataURL } from '@/lib/image-blur';
|
||||||
import type { PropertyMedia } from '@/lib/listings-api';
|
import type { PropertyMedia } from '@/lib/listings-api';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
@@ -13,6 +15,12 @@ interface ImageGalleryProps {
|
|||||||
export function ImageGallery({ media, className }: ImageGalleryProps) {
|
export function ImageGallery({ media, className }: ImageGalleryProps) {
|
||||||
const images = media.filter((m) => m.type === 'image').sort((a, b) => a.order - b.order);
|
const images = media.filter((m) => m.type === 'image').sort((a, b) => a.order - b.order);
|
||||||
const [selectedIndex, setSelectedIndex] = React.useState(0);
|
const [selectedIndex, setSelectedIndex] = React.useState(0);
|
||||||
|
const [lightboxOpen, setLightboxOpen] = React.useState(false);
|
||||||
|
|
||||||
|
const openLightbox = React.useCallback((index: number) => {
|
||||||
|
setSelectedIndex(index);
|
||||||
|
setLightboxOpen(true);
|
||||||
|
}, []);
|
||||||
|
|
||||||
if (images.length === 0) {
|
if (images.length === 0) {
|
||||||
return (
|
return (
|
||||||
@@ -31,35 +39,58 @@ export function ImageGallery({ media, className }: ImageGalleryProps) {
|
|||||||
<div className={cn('space-y-3', className)}>
|
<div className={cn('space-y-3', className)}>
|
||||||
{/* Main image */}
|
{/* Main image */}
|
||||||
<div className="relative aspect-video overflow-hidden rounded-lg bg-muted">
|
<div className="relative aspect-video overflow-hidden rounded-lg bg-muted">
|
||||||
|
<button
|
||||||
|
onClick={() => openLightbox(selectedIndex)}
|
||||||
|
className="absolute inset-0 z-10 cursor-zoom-in"
|
||||||
|
aria-label="Xem ảnh toàn màn hình"
|
||||||
|
/>
|
||||||
<Image
|
<Image
|
||||||
src={images[selectedIndex]?.url ?? ''}
|
src={images[selectedIndex]?.url ?? ''}
|
||||||
alt={images[selectedIndex]?.caption || `Ảnh ${selectedIndex + 1}`}
|
alt={images[selectedIndex]?.caption || `Ảnh ${selectedIndex + 1}`}
|
||||||
fill
|
fill
|
||||||
sizes="(max-width: 768px) 100vw, 60vw"
|
sizes="(max-width: 640px) 100vw, 50vw"
|
||||||
className="object-cover"
|
className="object-cover"
|
||||||
priority={selectedIndex === 0}
|
priority={selectedIndex === 0}
|
||||||
|
placeholder="blur"
|
||||||
|
blurDataURL={shimmerBlurDataURL()}
|
||||||
/>
|
/>
|
||||||
{images.length > 1 && (
|
{images.length > 1 && (
|
||||||
<>
|
<>
|
||||||
<button
|
<button
|
||||||
onClick={() => setSelectedIndex((i) => (i > 0 ? i - 1 : images.length - 1))}
|
onClick={(e) => {
|
||||||
className="absolute left-2 top-1/2 -translate-y-1/2 rounded-full bg-black/50 p-2 text-white transition-colors hover:bg-black/70"
|
e.stopPropagation();
|
||||||
|
setSelectedIndex((i) => (i > 0 ? i - 1 : images.length - 1));
|
||||||
|
}}
|
||||||
|
className="absolute left-2 top-1/2 z-20 -translate-y-1/2 rounded-full bg-black/50 p-2 text-white transition-colors hover:bg-black/70"
|
||||||
aria-label="Ảnh trước"
|
aria-label="Ảnh trước"
|
||||||
>
|
>
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="m15 18-6-6 6-6"/></svg>
|
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="m15 18-6-6 6-6"/></svg>
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
onClick={() => setSelectedIndex((i) => (i < images.length - 1 ? i + 1 : 0))}
|
onClick={(e) => {
|
||||||
className="absolute right-2 top-1/2 -translate-y-1/2 rounded-full bg-black/50 p-2 text-white transition-colors hover:bg-black/70"
|
e.stopPropagation();
|
||||||
|
setSelectedIndex((i) => (i < images.length - 1 ? i + 1 : 0));
|
||||||
|
}}
|
||||||
|
className="absolute right-2 top-1/2 z-20 -translate-y-1/2 rounded-full bg-black/50 p-2 text-white transition-colors hover:bg-black/70"
|
||||||
aria-label="Ảnh tiếp"
|
aria-label="Ảnh tiếp"
|
||||||
>
|
>
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="m9 18 6-6-6-6"/></svg>
|
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="m9 18 6-6-6-6"/></svg>
|
||||||
</button>
|
</button>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
<div className="absolute bottom-2 right-2 rounded bg-black/60 px-2 py-1 text-xs text-white">
|
<div className="absolute bottom-2 right-2 z-20 rounded bg-black/60 px-2 py-1 text-xs text-white">
|
||||||
{selectedIndex + 1} / {images.length}
|
{selectedIndex + 1} / {images.length}
|
||||||
</div>
|
</div>
|
||||||
|
{/* Expand hint icon */}
|
||||||
|
<div className="absolute bottom-2 left-2 z-20 flex items-center gap-1 rounded bg-black/60 px-2 py-1 text-xs text-white">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
|
||||||
|
<path d="M15 3h6v6" />
|
||||||
|
<path d="M9 21H3v-6" />
|
||||||
|
<path d="m21 3-7 7" />
|
||||||
|
<path d="m3 21 7-7" />
|
||||||
|
</svg>
|
||||||
|
Xem toàn màn hình
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Thumbnails */}
|
{/* Thumbnails */}
|
||||||
@@ -69,6 +100,7 @@ export function ImageGallery({ media, className }: ImageGalleryProps) {
|
|||||||
<button
|
<button
|
||||||
key={img.id}
|
key={img.id}
|
||||||
onClick={() => setSelectedIndex(index)}
|
onClick={() => setSelectedIndex(index)}
|
||||||
|
onDoubleClick={() => openLightbox(index)}
|
||||||
className={cn(
|
className={cn(
|
||||||
'relative h-16 w-16 flex-shrink-0 overflow-hidden rounded-md border-2 transition-colors',
|
'relative h-16 w-16 flex-shrink-0 overflow-hidden rounded-md border-2 transition-colors',
|
||||||
index === selectedIndex ? 'border-primary' : 'border-transparent opacity-70 hover:opacity-100',
|
index === selectedIndex ? 'border-primary' : 'border-transparent opacity-70 hover:opacity-100',
|
||||||
@@ -85,6 +117,14 @@ export function ImageGallery({ media, className }: ImageGalleryProps) {
|
|||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{/* Lightbox */}
|
||||||
|
<ImageLightbox
|
||||||
|
images={images}
|
||||||
|
initialIndex={selectedIndex}
|
||||||
|
open={lightboxOpen}
|
||||||
|
onClose={() => setLightboxOpen(false)}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,12 +84,21 @@ export function ImageUpload({ images, onChange, maxFiles = 20, className }: Imag
|
|||||||
return (
|
return (
|
||||||
<div className={cn('space-y-4', className)}>
|
<div className={cn('space-y-4', className)}>
|
||||||
<div
|
<div
|
||||||
|
role="button"
|
||||||
|
tabIndex={0}
|
||||||
onDragOver={handleDragOver}
|
onDragOver={handleDragOver}
|
||||||
onDragLeave={handleDragLeave}
|
onDragLeave={handleDragLeave}
|
||||||
onDrop={handleDrop}
|
onDrop={handleDrop}
|
||||||
onClick={() => inputRef.current?.click()}
|
onClick={() => inputRef.current?.click()}
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
if (e.key === 'Enter' || e.key === ' ') {
|
||||||
|
e.preventDefault();
|
||||||
|
inputRef.current?.click();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
aria-label="Tải ảnh lên. Kéo thả ảnh vào đây hoặc nhấn để chọn"
|
||||||
className={cn(
|
className={cn(
|
||||||
'flex cursor-pointer flex-col items-center justify-center rounded-lg border-2 border-dashed p-8 transition-colors',
|
'flex cursor-pointer flex-col items-center justify-center rounded-lg border-2 border-dashed p-8 transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary',
|
||||||
isDragging
|
isDragging
|
||||||
? 'border-primary bg-primary/5'
|
? 'border-primary bg-primary/5'
|
||||||
: 'border-muted-foreground/25 hover:border-primary/50',
|
: 'border-muted-foreground/25 hover:border-primary/50',
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ export function ListingMap({ listings, onMarkerClick, selectedListingId, classNa
|
|||||||
function showPopup(map: mapboxgl.Map, marker: MapMarker) {
|
function showPopup(map: mapboxgl.Map, marker: MapMarker) {
|
||||||
popupRef.current?.remove();
|
popupRef.current?.remove();
|
||||||
|
|
||||||
const popup = new mapboxgl.Popup({ offset: 25, maxWidth: '260px', closeButton: true })
|
const popup = new mapboxgl.Popup({ offset: 25, maxWidth: 'min(260px, 85vw)', closeButton: true })
|
||||||
.setLngLat([marker.lng, marker.lat])
|
.setLngLat([marker.lng, marker.lat])
|
||||||
.setDOMContent(buildPopupContent(marker.listing))
|
.setDOMContent(buildPopupContent(marker.listing))
|
||||||
.addTo(map);
|
.addTo(map);
|
||||||
@@ -209,7 +209,7 @@ export function ListingMap({ listings, onMarkerClick, selectedListingId, classNa
|
|||||||
const hasToken = typeof process !== 'undefined' && process.env['NEXT_PUBLIC_MAPBOX_TOKEN'];
|
const hasToken = typeof process !== 'undefined' && process.env['NEXT_PUBLIC_MAPBOX_TOKEN'];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`relative overflow-hidden rounded-lg border ${className || 'h-[500px]'}`}>
|
<div className={`relative overflow-hidden rounded-lg border ${className || 'h-[300px] md:h-[500px]'}`}>
|
||||||
<div ref={mapContainerRef} className="h-full w-full" />
|
<div ref={mapContainerRef} className="h-full w-full" />
|
||||||
|
|
||||||
{/* Fallback when no Mapbox token */}
|
{/* Fallback when no Mapbox token */}
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ export function FilterBar({ filters, onChange, onSearch, layout = 'horizontal' }
|
|||||||
<Select
|
<Select
|
||||||
value={filters.transactionType}
|
value={filters.transactionType}
|
||||||
onChange={(e) => update('transactionType', e.target.value)}
|
onChange={(e) => update('transactionType', e.target.value)}
|
||||||
className={isSidebar ? 'w-full' : 'w-40'}
|
className={isSidebar ? 'w-full' : 'w-full sm:w-40'}
|
||||||
aria-label={t('allTransactions')}
|
aria-label={t('allTransactions')}
|
||||||
>
|
>
|
||||||
<option value="">{t('allTransactions')}</option>
|
<option value="">{t('allTransactions')}</option>
|
||||||
@@ -97,7 +97,7 @@ export function FilterBar({ filters, onChange, onSearch, layout = 'horizontal' }
|
|||||||
<Select
|
<Select
|
||||||
value={filters.propertyType}
|
value={filters.propertyType}
|
||||||
onChange={(e) => update('propertyType', e.target.value)}
|
onChange={(e) => update('propertyType', e.target.value)}
|
||||||
className={isSidebar ? 'w-full' : 'w-44'}
|
className={isSidebar ? 'w-full' : 'w-full sm:w-44'}
|
||||||
aria-label={t('allPropertyTypes')}
|
aria-label={t('allPropertyTypes')}
|
||||||
>
|
>
|
||||||
<option value="">{t('allPropertyTypes')}</option>
|
<option value="">{t('allPropertyTypes')}</option>
|
||||||
@@ -111,7 +111,7 @@ export function FilterBar({ filters, onChange, onSearch, layout = 'horizontal' }
|
|||||||
<Select
|
<Select
|
||||||
value={filters.city}
|
value={filters.city}
|
||||||
onChange={(e) => update('city', e.target.value)}
|
onChange={(e) => update('city', e.target.value)}
|
||||||
className={isSidebar ? 'w-full' : 'w-44'}
|
className={isSidebar ? 'w-full' : 'w-full sm:w-44'}
|
||||||
aria-label={t('allAreas')}
|
aria-label={t('allAreas')}
|
||||||
>
|
>
|
||||||
<option value="">{t('allAreas')}</option>
|
<option value="">{t('allAreas')}</option>
|
||||||
@@ -125,7 +125,7 @@ export function FilterBar({ filters, onChange, onSearch, layout = 'horizontal' }
|
|||||||
<Select
|
<Select
|
||||||
value={currentPriceIdx >= 0 ? String(currentPriceIdx) : ''}
|
value={currentPriceIdx >= 0 ? String(currentPriceIdx) : ''}
|
||||||
onChange={(e) => handlePriceRange(e.target.value)}
|
onChange={(e) => handlePriceRange(e.target.value)}
|
||||||
className={isSidebar ? 'w-full' : 'w-40'}
|
className={isSidebar ? 'w-full' : 'w-full sm:w-40'}
|
||||||
aria-label={t('allPrices')}
|
aria-label={t('allPrices')}
|
||||||
>
|
>
|
||||||
<option value="">{t('allPrices')}</option>
|
<option value="">{t('allPrices')}</option>
|
||||||
@@ -188,7 +188,7 @@ export function FilterBar({ filters, onChange, onSearch, layout = 'horizontal' }
|
|||||||
<Select
|
<Select
|
||||||
value={filters.bedrooms}
|
value={filters.bedrooms}
|
||||||
onChange={(e) => update('bedrooms', e.target.value)}
|
onChange={(e) => update('bedrooms', e.target.value)}
|
||||||
className="w-36"
|
className="w-full sm:w-36"
|
||||||
aria-label={t('bedrooms')}
|
aria-label={t('bedrooms')}
|
||||||
>
|
>
|
||||||
<option value="">{t('bedrooms')}</option>
|
<option value="">{t('bedrooms')}</option>
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { AddToCompareButton } from '@/components/comparison/add-to-compare-butto
|
|||||||
import { Badge } from '@/components/ui/badge';
|
import { Badge } from '@/components/ui/badge';
|
||||||
import { Card, CardContent } from '@/components/ui/card';
|
import { Card, CardContent } from '@/components/ui/card';
|
||||||
import { formatPrice } from '@/lib/currency';
|
import { formatPrice } from '@/lib/currency';
|
||||||
|
import { shimmerBlurDataURL } from '@/lib/image-blur';
|
||||||
import type { ListingDetail } from '@/lib/listings-api';
|
import type { ListingDetail } from '@/lib/listings-api';
|
||||||
|
|
||||||
const PROPERTY_TYPE_LABELS: Record<string, string> = {
|
const PROPERTY_TYPE_LABELS: Record<string, string> = {
|
||||||
@@ -38,6 +39,8 @@ export function PropertyCard({ listing, compact }: PropertyCardProps) {
|
|||||||
fill
|
fill
|
||||||
sizes="(max-width: 640px) 100vw, (max-width: 1024px) 50vw, 33vw"
|
sizes="(max-width: 640px) 100vw, (max-width: 1024px) 50vw, 33vw"
|
||||||
className="object-cover transition-transform group-hover:scale-105"
|
className="object-cover transition-transform group-hover:scale-105"
|
||||||
|
placeholder="blur"
|
||||||
|
blurDataURL={shimmerBlurDataURL()}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<div className="flex h-full items-center justify-center text-muted-foreground" aria-hidden="true">
|
<div className="flex h-full items-center justify-center text-muted-foreground" aria-hidden="true">
|
||||||
|
|||||||
@@ -73,14 +73,14 @@ export function SearchResults({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between">
|
||||||
<p className="text-sm text-muted-foreground">
|
<p className="text-sm text-muted-foreground">
|
||||||
{result.total} kết quả
|
{result.total} kết quả
|
||||||
</p>
|
</p>
|
||||||
<Select
|
<Select
|
||||||
value={sort}
|
value={sort}
|
||||||
onChange={(e) => onSortChange(e.target.value)}
|
onChange={(e) => onSortChange(e.target.value)}
|
||||||
className="w-48"
|
className="w-full sm:w-48"
|
||||||
>
|
>
|
||||||
<option value="">Mới nhất</option>
|
<option value="">Mới nhất</option>
|
||||||
<option value="price_asc">Giá: Thấp đến cao</option>
|
<option value="price_asc">Giá: Thấp đến cao</option>
|
||||||
|
|||||||
Reference in New Issue
Block a user