diff --git a/TODO.md b/TODO.md index b8dc2ae..d379a06 100644 --- a/TODO.md +++ b/TODO.md @@ -66,9 +66,9 @@ - [X] Добавление \ Удаление аниме в\из списков закладок и избранных - [X] Связанные релизы - [X] Просмотр страницы всех связанных релизов -- [ ] Оценка тайтла +- [X] Оценка тайтла - [X] Просмотр оценки - - [ ] Оценивание и изменение своей оценки (как Modal) + - [X] Оценивание и изменение своей оценки (как Modal) ## Стиль diff --git a/app/components/ReleaseInfo/ReleaseInfo.Rating.tsx b/app/components/ReleaseInfo/ReleaseInfo.Rating.tsx index dbe1be0..6f78499 100644 --- a/app/components/ReleaseInfo/ReleaseInfo.Rating.tsx +++ b/app/components/ReleaseInfo/ReleaseInfo.Rating.tsx @@ -4,8 +4,11 @@ import { Flowbite, Button, CustomFlowbiteTheme, + Modal, } from "flowbite-react"; import { numberDeclension } from "#/api/utils"; +import { useState } from "react"; +import { ENDPOINTS } from "#/api/config"; const RatingTheme: CustomFlowbiteTheme = { ratingAdvanced: { @@ -15,6 +18,7 @@ const RatingTheme: CustomFlowbiteTheme = { }, }; export const ReleaseInfoRating = (props: { + release_id: number; grade: number; token: string | null; votes: { @@ -27,88 +31,217 @@ export const ReleaseInfoRating = (props: { user: number | null; }; }) => { + const [isRatingModalOpen, setIsRatingModalOpen] = useState(false); + const [vote, setVote] = useState(props.votes.user); + return ( - -
- - -

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

-
- {props.token && ( - <> - - {props.votes.user ? ( + <> + +
+ + +

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

+
+ {props.token && ( + <> +
-

- ваша оценка: {props.votes.user} -

- + {vote ? ( + <> +

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

+ + + ) : ( + + )}
- ) : ( - + + )} +
+

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

+ + - )} -
-

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

- - - 5 - - - 4 - - - 3 - - - 2 - - - 1 - - -
+ className="mb-2" + > + 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) => ( + + ))} + +
+
+
+ +
+ + +
+
+
); }; diff --git a/app/pages/Release.tsx b/app/pages/Release.tsx index 41e9fd1..6399463 100644 --- a/app/pages/Release.tsx +++ b/app/pages/Release.tsx @@ -96,6 +96,7 @@ export const ReleasePage = (props: any) => { {data.release.status.name.toLowerCase() != "анонс" && (