Commit dfa17dc9 authored by Lê Bảo Hồng Đức's avatar Lê Bảo Hồng Đức

[tag]0.1-vcci

parents 0a83b978 15b1aaea
Pipeline #52518 passed with stages
in 3 minutes and 41 seconds
...@@ -8,7 +8,7 @@ import { resolveUploadUrl } from "@/links"; ...@@ -8,7 +8,7 @@ import { resolveUploadUrl } from "@/links";
import type { Advertisement } from "@/api/models/advertisement"; import type { Advertisement } from "@/api/models/advertisement";
const FALLBACK_SRC = "/quang-cao/qc-3.jpg"; const FALLBACK_SRC = "/quang-cao/qc-3.jpg";
const FALLBACK_HREF = "https://vcci-hcm.org.vn"; const FALLBACK_HREF = "https://vccihcm.vn";
function AdItem({ item }: { item: Advertisement }) { function AdItem({ item }: { item: Advertisement }) {
const initialSrc = item.file?.path ? resolveUploadUrl(item.file.path) : FALLBACK_SRC; const initialSrc = item.file?.path ? resolveUploadUrl(item.file.path) : FALLBACK_SRC;
...@@ -17,7 +17,7 @@ function AdItem({ item }: { item: Advertisement }) { ...@@ -17,7 +17,7 @@ function AdItem({ item }: { item: Advertisement }) {
return ( return (
<Link <Link
href={item.link} href={item.link || FALLBACK_HREF}
target="_blank" target="_blank"
rel="noopener noreferrer" rel="noopener noreferrer"
className="block overflow-hidden rounded-[28px] shadow-[0_12px_28px_rgba(31,59,124,0.14)]" className="block overflow-hidden rounded-[28px] shadow-[0_12px_28px_rgba(31,59,124,0.14)]"
...@@ -66,11 +66,12 @@ function Advertisements({ count = 2, startIndex = 0 }: { count?: number; startIn ...@@ -66,11 +66,12 @@ function Advertisements({ count = 2, startIndex = 0 }: { count?: number; startIn
const ads = useAdvertisements("square"); const ads = useAdvertisements("square");
const visibleAds = ads.slice(startIndex, startIndex + count); const visibleAds = ads.slice(startIndex, startIndex + count);
// Fallback: nếu API không có data, hiển thị fallback item // Luôn render đủ `count` khung hình: vị trí nào API không có data thì dùng fallback qc-3.jpg.
const items = const items = Array.from({ length: count }, (_, i) => {
visibleAds.length > 0 const ad = visibleAds[i];
? visibleAds.map((item) => <AdItem key={item.id} item={item} />) if (ad) return <AdItem key={ad.id} item={ad} />;
: Array.from({ length: count }).map((_, i) => <FallbackAdItem key={`fallback-${i}`} />); return <FallbackAdItem key={`fallback-${startIndex + i}`} />;
});
const mdCols = count >= 3 ? "md:grid-cols-3" : "md:grid-cols-2"; const mdCols = count >= 3 ? "md:grid-cols-3" : "md:grid-cols-2";
return ( return (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment