feat(tip): support dynamic gift products

This commit is contained in:
2026-07-21 13:19:45 +08:00
parent 55cb98ed14
commit 37ff69020b
62 changed files with 2325 additions and 1085 deletions
+38
View File
@@ -0,0 +1,38 @@
"use client";
import { useState } from "react";
interface TipProductImageProps {
alt: string;
className: string;
priority?: boolean;
sources: readonly string[];
}
export function TipProductImage({
alt,
className,
priority = false,
sources,
}: TipProductImageProps) {
const [sourceIndex, setSourceIndex] = useState(0);
const source = sources[sourceIndex] ?? sources[sources.length - 1];
if (!source) return null;
return (
// Gift hosts are managed by the backend and cannot be safely enumerated in Next remotePatterns.
// eslint-disable-next-line @next/next/no-img-element
<img
src={source}
alt={alt}
className={className}
loading={priority ? "eager" : "lazy"}
fetchPriority={priority ? "high" : "auto"}
onError={() => {
if (sourceIndex < sources.length - 1) {
setSourceIndex((index) => index + 1);
}
}}
/>
);
}