"use client"; import useSWR from "swr"; import { Spinner } from "#/components/Spinner/Spinner"; const fetcher = (...args: any) => fetch([...args] as any).then((res) => res.json()); import { useUserStore } from "#/store/auth"; import { Card, Dropdown, Button } from "flowbite-react"; import { useEffect, useState } from "react"; import { unixToDate, getSeasonFromUnix, minutesToTime } from "#/api/utils"; import { ReleaseLink } from "#/components/ReleaseLink/ReleaseLink"; import { ReleasePlayer } from "#/components/ReleasePlayer/ReleasePlayer"; import { ENDPOINTS } from "#/api/config"; import { Table } from "flowbite-react"; import { ReleaseInfoSearchLink } from "#/components/ReleaseInfo/ReleaseInfo.SearchLink"; import Link from "next/link"; const lists = [ { list: 0, name: "Не смотрю" }, { list: 1, name: "Смотрю" }, { list: 2, name: "В планах" }, { list: 3, name: "Просмотрено" }, { list: 4, name: "Отложено" }, { list: 5, name: "Брошено" }, ]; const weekDay = [ "_", "каждый понедельник", "каждый вторник", "каждую среду", "каждый четверг", "каждую пятницу", "каждую субботу", "каждое воскресенье", ]; const YearSeason = ["_", "Зима", "Весна", "Лето", "Осень"]; const DropdownTheme = { floating: { target: "flex-1 bg-blue-600 enabled:hover:bg-blue-700 focus:ring-4 focus:outline-none focus:ring-blue-300 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800", }, }; export const ReleasePage = (props: any) => { const token = useUserStore((state) => state.token); const [userList, setUserList] = useState(0); const [userFavorite, setUserFavorite] = useState(false); function useFetch(id: number) { let url: string; url = `/api/release/${id}`; if (token) { url += `?token=${token}`; } const { data, isLoading, error } = useSWR(url, fetcher); return [data, isLoading, error]; } const [data, isLoading, error] = useFetch(props.id); useEffect(() => { if (data) { const el = document.getElementById("note"); if (el) { el.innerHTML = data.release.note; } setUserList(data.release.profile_list_status || 0); setUserFavorite(data.release.is_favorite); } }, [data]); function _addToFavorite() { if (data && token) { setUserFavorite(!userFavorite); if (userFavorite) { fetch( `${ENDPOINTS.user.favorite}/delete/${data.release.id}?token=${token}` ); } else { fetch( `${ENDPOINTS.user.favorite}/add/${data.release.id}?token=${token}` ); } } } function _addToList(list: number) { if (data && token) { setUserList(list); fetch( `${ENDPOINTS.user.bookmark}/add/${list}/${data.release.id}?token=${token}` ); } } return data ? (
{data.release.title_ru && (

{data.release.title_ru}

)} {data.release.title_original && (

{data.release.title_original}

)}
{data.release.note && (
)} {data.release.description &&

{data.release.description}

}
{data.release.status.name.toLowerCase() != "анонс" && ( )}
{data.release.country ? ( data.release.country.toLowerCase() == "япония" ? ( ) : ( ) ) : ( )} {data.release.country && data.release.country} {(data.release.aired_on_date != 0 || data.release.year) && ", "} {data.release.aired_on_date != 0 && `${getSeasonFromUnix(data.release.aired_on_date)} `} {data.release.year && `${data.release.year} г.`} {data.release.episodes_released ? data.release.episodes_released : "?"} {"/"} {data.release.episodes_total ? data.release.episodes_total + " эп. " : "? эп. "} {data.release.duration != 0 && `по ${minutesToTime(data.release.duration)}`} {data.release.category.name} {", "} {data.release.broadcast == 0 ? data.release.status.name.toLowerCase() : `выходит ${weekDay[data.release.broadcast]}`} {data.release.studio && ( <> {"Студия: "} {data.release.studio .split(", ") .map((studio: string, index: number) => { return ( <> {index > 0 && ", "} ); })} {(data.release.author || data.release.director) && ", "} )} {data.release.author && ( <> {"Автор: "} {data.release.director && ", "} )} {data.release.director && ( <> {"Режиссёр: "} )} {data.release.genres && data.release.genres .split(", ") .map((genre: string, index: number) => { return ( <> {index > 0 && ", "} ); })} {data.release.status.name.toLowerCase() == "анонс" && ( {data.release.aired_on_date != 0 ? ( unixToDate(data.release.aired_on_date) ) : data.release.year ? ( <> {data.release.season && data.release.season != 0 ? `${YearSeason[data.release.season]} ` : ""} {data.release.year && `${data.release.year} г.`} ) : ( "Скоро" )} )}
{token && (
{lists.map((list) => ( _addToList(list.list)} > {list.name} ))}
)} {data.release.related_releases.length > 0 && (

Связанные релизы

{data.release.related && (

Показать все

)}
{data.release.related_releases.map((release) => { if (release.id == data.release.id) return null; return ; })}
)}
) : (
); }; { /* */ }