import { Button, Card, Modal, ModalBody, ModalFooter, ModalHeader, Rating, RatingAdvanced, RatingStar, RatingAdvancedTheme, } from "flowbite-react"; import { numberDeclension } from "#/api/utils"; import { useState } from "react"; import { ENDPOINTS } from "#/api/config"; const CustomRatingTheme: RatingAdvancedTheme = { base: "flex items-center", label: "text-sm font-medium text-cyan-600 dark:text-cyan-500", progress: { base: "mx-4 h-5 w-3/4 rounded bg-gray-200 dark:bg-gray-700", fill: "h-5 rounded bg-yellow-400", label: "text-sm font-medium text-cyan-600 dark:text-cyan-500", }, }; export const ReleaseInfoRating = (props: { release_id: number; grade: number; token: string | null; votes: { 1: number; 2: number; 3: number; 4: number; 5: number; total: number; user: number | null; }; }) => { const [isRatingModalOpen, setIsRatingModalOpen] = useState(false); const [vote, setVote] = useState(props.votes.user); return ( <>

{props.grade.toFixed(2)} из 5

{props.token && ( <>
{vote ? <>

ваша оценка: {vote}

: }
)}

{props.votes.total}{" "} {numberDeclension(props.votes.total, "голос", "голоса", "голосов")}

5 4 3 2 1
); }; const ReleaseInfoRatingModal = (props: { isOpen: boolean; setIsOpen: any; setUserVote: any; token: string | null; vote: number; release_id: number; }) => { const [curElement, setCurElement] = useState(props.vote); const [vote, setVote] = useState(props.vote); const [isSending, setIsSending] = useState(false); async function _sendVote( action: "delete" | "add" = "add", vote: number | null = null ) { let url = `${ENDPOINTS.release.info}/vote/${action}/${props.release_id}`; if (action === "add") { url += `/${vote}`; } url += `?token=${props.token}`; fetch(url); } function _setVote( action: "delete" | "add" = "add", vote: number | null = null ) { if (props.token) { _sendVote(action, vote); setVote(vote); props.setUserVote(vote); props.setIsOpen(false); setIsSending(false); } } return ( props.setIsOpen(false)} > Оценка
{[1, 2, 3, 4, 5].map((element, index) => ( ))}
{[1, 2, 3, 4, 5].map((element, index) => ( ))}
); };