Files
hoanghapc_nextJs/src/components/product/detail/comments/index.tsx

53 lines
2.0 KiB
TypeScript
Raw Normal View History

2026-02-03 17:20:38 +07:00
'use client';
import { useState, useMemo } from "react";
2026-02-02 16:42:40 +07:00
import { CommentData } from "@/data/comments";
import Form from "./Form";
import CommentList from "./CommentList";
export default function Comment() {
2026-02-03 17:20:38 +07:00
const [star, setStar] = useState<number | null>(null);
const filteredComments = useMemo(() => {
if (star === null) return CommentData.list;
return CommentData.list.filter(item => Number(item.rate) === star);
}, [star]);
2026-02-02 16:42:40 +07:00
return (
<div>
<div className="flex items-center justify-between leading-8 gap-2 mb-4">
<p className="m-0 text-18 font-500"> {CommentData.list.length} Bình luận </p>
<div className="flex flex-wrap gap-2 text-14 font-500 pd-comment-btn">
2026-02-03 17:20:38 +07:00
<button type="button"
className={`h-8 border rounded-[40px] px-8
${star === null ? 'border-[#0678DB] text-[#0678DB]' : 'border-[#D1D5DB]'}`}
onClick={() => setStar(null)}
>
Tất cả
</button>
2026-02-02 16:42:40 +07:00
2026-02-03 17:20:38 +07:00
{[5,4,3,2,1].map(s => (
<button type="button"
key={s}
className={`h-8 border rounded-[40px] px-4 flex items-center gap-[3px]
${star === s ? 'border-[#0678DB] text-[#0678DB]' : 'border-[#D1D5DB]'}`}
onClick={() => setStar(s)}
>
{s} <i className="bxr bx-star" />
</button>
))}
2026-02-02 16:42:40 +07:00
</div>
2026-02-03 17:20:38 +07:00
2026-02-02 16:42:40 +07:00
</div>
<div className="border border-[#DDDDDD] rounded-[12px] overflow-hidden js-comment-form">
<Form />
</div>
2026-02-03 17:20:38 +07:00
{filteredComments.length > 0 && (
<CommentList item={filteredComments} />
)}
2026-02-02 16:42:40 +07:00
</div>
)
}