2024-03-26 03:25:06 +01:00
|
|
|
import { ReviewSegment } from "@/types/review";
|
2024-02-27 17:05:28 +01:00
|
|
|
import { Button } from "../ui/button";
|
|
|
|
import { LuRefreshCcw } from "react-icons/lu";
|
2024-03-26 03:25:06 +01:00
|
|
|
import { MutableRefObject, useMemo } from "react";
|
2024-06-02 19:00:59 +02:00
|
|
|
import { cn } from "@/lib/utils";
|
2024-02-27 17:05:28 +01:00
|
|
|
|
|
|
|
type NewReviewDataProps = {
|
|
|
|
className: string;
|
|
|
|
contentRef: MutableRefObject<HTMLDivElement | null>;
|
2024-03-26 03:25:06 +01:00
|
|
|
reviewItems?: ReviewSegment[] | null;
|
|
|
|
itemsToReview?: number;
|
2024-02-27 17:05:28 +01:00
|
|
|
pullLatestData: () => void;
|
|
|
|
};
|
|
|
|
export default function NewReviewData({
|
|
|
|
className,
|
|
|
|
contentRef,
|
2024-03-26 03:25:06 +01:00
|
|
|
reviewItems,
|
|
|
|
itemsToReview,
|
2024-02-27 17:05:28 +01:00
|
|
|
pullLatestData,
|
|
|
|
}: NewReviewDataProps) {
|
2024-03-26 03:25:06 +01:00
|
|
|
const hasUpdate = useMemo(() => {
|
|
|
|
if (!reviewItems || !itemsToReview) {
|
|
|
|
return false;
|
2024-02-27 17:05:28 +01:00
|
|
|
}
|
|
|
|
|
2024-03-26 22:03:58 +01:00
|
|
|
return reviewItems.length < itemsToReview;
|
2024-03-26 03:25:06 +01:00
|
|
|
}, [reviewItems, itemsToReview]);
|
2024-02-27 17:05:28 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={className}>
|
2024-05-14 17:06:44 +02:00
|
|
|
<div className="pointer-events-auto mr-[65px] flex items-center justify-center md:mr-[115px]">
|
2024-02-27 17:05:28 +01:00
|
|
|
<Button
|
2024-06-02 19:00:59 +02:00
|
|
|
className={cn(
|
2024-02-27 17:05:28 +01:00
|
|
|
hasUpdate
|
2024-05-14 17:06:44 +02:00
|
|
|
? "duration-500 animate-in slide-in-from-top"
|
2024-06-02 19:00:59 +02:00
|
|
|
: "invisible",
|
|
|
|
"mx-auto mt-5 bg-gray-400 text-center text-white",
|
|
|
|
)}
|
2024-02-27 17:05:28 +01:00
|
|
|
onClick={() => {
|
|
|
|
pullLatestData();
|
|
|
|
if (contentRef.current) {
|
|
|
|
contentRef.current.scrollTo({
|
|
|
|
top: 0,
|
|
|
|
behavior: "smooth",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
2024-05-14 17:06:44 +02:00
|
|
|
<LuRefreshCcw className="mr-2 h-4 w-4" />
|
2024-02-27 17:05:28 +01:00
|
|
|
New Items To Review
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|