Files
goodgo-platform/apps/web/components/search/search-results.tsx
Ho Ngoc Hai 2f07b374d9
Some checks failed
CI / Lint → Typecheck → Test → Build (22) (push) Failing after 5s
CI / E2E Tests (push) Has been skipped
CodeQL Analysis / CodeQL (javascript-typescript) (push) Failing after 1m0s
Deploy / Build API Image (push) Failing after 11s
Deploy / Build Web Image (push) Failing after 9s
Deploy / Build AI Services Image (push) Failing after 9s
E2E Tests / Playwright E2E (push) Failing after 7s
Security Scanning / Dependency Audit (pnpm) (push) Failing after 2s
Security Scanning / Trivy Scan — Web Image (push) Failing after 25s
Security Scanning / Trivy Scan — AI Services Image (push) Failing after 24s
Security Scanning / Trivy Filesystem Scan (push) Failing after 35s
Deploy / Deploy to Staging (push) Has been skipped
Security Scanning / Security Gate (push) Failing after 0s
Deploy / Rollback Staging (push) Has been skipped
Security Scanning / Trivy Scan — API Image (push) Failing after 26s
Deploy / Smoke Test Staging (push) Has been skipped
Deploy / Deploy to Production (push) Has been skipped
Deploy / Smoke Test Production (push) Has been skipped
Deploy / Rollback Production (push) Has been skipped
feat(web): dashboard gets Dự án + KCN nav; listings pages use list layout
Three asks after a walk-through of the dashboard:

1. Dashboard navigation was missing direct entry points to the two
   catalog surfaces (Dự án, Khu Công Nghiệp) even though both exist at
   /du-an and /khu-cong-nghiep. Users landing in the dashboard had to
   go back out to the public header to reach them.

2. The "Tin đăng" (dashboard listings) page defaulted to a 3-column
   grid which shows only a handful of properties per viewport. Scanning
   many listings at once is easier as a vertical list of horizontal
   rows.

3. The public /search results used the same 3-column grid via
   PropertyCard. Asked to flip to list there too.

Changes
- (dashboard)/layout.tsx: new `catalogs` nav group with Building2 +
  Factory icons pointing at /du-an and /khu-cong-nghiep. Primary
  desktop nav also exposes both so they're reachable without opening
  the hamburger. Uses existing `nav.projects` / `nav.industrialParks`
  i18n keys plus a new `dashboard.catalogs` label in vi/en.
- (dashboard)/listings/page.tsx: default viewMode flipped from 'grid'
  to 'list'. The list mode renders a horizontal row per listing
  (thumbnail + title/location + price + badges + engagement counters)
  inside an <ul>. Toggle button relabelled "Danh sách".
- components/search/search-results.tsx + property-card.tsx: add a
  `layout?: 'card' | 'list'` prop to PropertyCard. When `list`, the
  card renders as a horizontal row with 224px thumbnail on sm+,
  stacked on mobile. SearchResults wraps items in a <ul><li> and asks
  for list layout. Default card layout preserved so other callers
  (compare, related, etc.) keep their vertical card view.

No API / DB changes. Typecheck clean for the touched surfaces.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-19 09:49:51 +07:00

149 lines
4.5 KiB
TypeScript

'use client';
import * as React from 'react';
import { Button } from '@/components/ui/button';
import { Select } from '@/components/ui/select';
import type { ListingDetail, PaginatedResult } from '@/lib/listings-api';
import { PropertyCard } from './property-card';
interface SearchResultsProps {
result: PaginatedResult<ListingDetail> | null;
loading: boolean;
error?: boolean;
onRetry?: () => void;
page: number;
sort: string;
onPageChange: (page: number) => void;
onSortChange: (sort: string) => void;
}
export function SearchResults({
result,
loading,
error,
onRetry,
page,
sort,
onPageChange,
onSortChange,
}: SearchResultsProps) {
if (loading) {
return (
<div className="flex min-h-[400px] items-center justify-center">
<div className="h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent" />
</div>
);
}
if (error) {
return (
<div className="flex min-h-[400px] flex-col items-center justify-center gap-3 text-muted-foreground">
<p className="text-lg font-medium">Không thể tải kết quả tìm kiếm</p>
<p className="text-sm">Đã xảy ra lỗi. Vui lòng thử lại.</p>
{onRetry && (
<Button variant="outline" size="sm" onClick={onRetry}>
Thử lại
</Button>
)}
</div>
);
}
if (!result || result.data.length === 0) {
return (
<div className="flex min-h-[400px] flex-col items-center justify-center text-muted-foreground">
<svg
className="mb-4 h-16 w-16 text-muted-foreground/50"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={1.5}
d="M21 21l-5.197-5.197m0 0A7.5 7.5 0 105.196 5.196a7.5 7.5 0 0010.607 10.607z"
/>
</svg>
<p className="text-lg font-medium">Không tìm thấy kết quả</p>
<p className="mt-1 text-sm">Hãy thử thay đi bộ lọc đ tìm kiếm rộng hơn</p>
</div>
);
}
return (
<div className="space-y-4">
<div className="flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between">
<p className="text-sm text-muted-foreground">
{result.total} kết quả
</p>
<Select
value={sort}
onChange={(e) => onSortChange(e.target.value)}
className="w-full sm:w-48"
>
<option value="">Mới nhất</option>
<option value="price_asc">Giá: Thấp đến cao</option>
<option value="price_desc">Giá: Cao đến thấp</option>
<option value="area_asc">Diện tích: Nhỏ đến lớn</option>
<option value="area_desc">Diện tích: Lớn đến nhỏ</option>
</Select>
</div>
<ul className="flex flex-col gap-3">
{result.data.map((listing) => (
<li key={listing.id}>
<PropertyCard listing={listing} layout="list" />
</li>
))}
</ul>
{result.totalPages > 1 && (
<div className="flex items-center justify-center gap-2 pt-4">
<Button
variant="outline"
size="sm"
disabled={page <= 1}
onClick={() => onPageChange(page - 1)}
>
Trước
</Button>
<div className="flex gap-1">
{Array.from({ length: Math.min(result.totalPages, 5) }, (_, i) => {
let pageNum: number;
if (result.totalPages <= 5) {
pageNum = i + 1;
} else if (page <= 3) {
pageNum = i + 1;
} else if (page >= result.totalPages - 2) {
pageNum = result.totalPages - 4 + i;
} else {
pageNum = page - 2 + i;
}
return (
<Button
key={pageNum}
variant={pageNum === page ? 'default' : 'outline'}
size="sm"
className="w-9"
onClick={() => onPageChange(pageNum)}
>
{pageNum}
</Button>
);
})}
</div>
<Button
variant="outline"
size="sm"
disabled={page >= result.totalPages}
onClick={() => onPageChange(page + 1)}
>
Tiếp
</Button>
</div>
)}
</div>
);
}