diff --git a/components/content-card/components/anime-tooltip.tsx b/components/content-card/components/anime-tooltip.tsx index dad81b9d..2f863171 100644 --- a/components/content-card/components/anime-tooltip.tsx +++ b/components/content-card/components/anime-tooltip.tsx @@ -1,6 +1,5 @@ 'use client'; -import * as React from 'react'; import { FC, PropsWithChildren, memo } from 'react'; import Link from 'next/link'; @@ -75,7 +74,7 @@ const TooltipData: FC = ({ slug }) => { ) : null} {synopsis && ( - + {synopsis} )} diff --git a/components/content-card/components/character-tooltip.tsx b/components/content-card/components/character-tooltip.tsx new file mode 100644 index 00000000..f81d9e12 --- /dev/null +++ b/components/content-card/components/character-tooltip.tsx @@ -0,0 +1,120 @@ +'use client'; + +import { FC, PropsWithChildren, memo } from 'react'; + +import ContentCard from '@/components/content-card/content-card'; +import MDViewer from '@/components/markdown/viewer/MD-viewer'; +import { + HoverCard, + HoverCardArrow, + HoverCardContent, + HoverCardPortal, + HoverCardTrigger, +} from '@/components/ui/hover-card'; +import { Label } from '@/components/ui/label'; +import useSession from '@/services/hooks/auth/useSession'; +import useCharacterAnime from '@/services/hooks/characters/useCharacterAnime'; +import useCharacterInfo from '@/services/hooks/characters/useCharacterInfo'; + +interface TooltipDataProps { + slug: string; +} + +interface Props extends PropsWithChildren { + slug?: string; + withTrigger?: boolean; +} + +const TooltipData: FC = ({ slug }) => { + const { user: loggedUser } = useSession(); + const { data } = useCharacterInfo({ slug }); + const { list } = useCharacterAnime({ slug }); + + const characterAnime = list?.sort( + (a, b) => b.anime.score - a.anime.score, + )[0]; + + if (!data) { + return ( +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ); + } + + return ( +
+ +
+
+ +
+
+
+ + {data.description_ua} + +
+
+
+ {characterAnime && ( +
+ +
+ )} +
+ ); +}; + +const CharacterTooltip: FC = ({ + slug, + children, + withTrigger, + ...props +}) => { + if (!slug) { + return null; + } + + return ( + + {children} + + + + + + + + ); +}; + +export default memo(CharacterTooltip); diff --git a/components/content-card/content-card.tsx b/components/content-card/content-card.tsx index d2ff6e5d..90b52499 100644 --- a/components/content-card/content-card.tsx +++ b/components/content-card/content-card.tsx @@ -13,6 +13,7 @@ import MaterialSymbolsImageNotSupportedOutlineRounded from '~icons/material-symb import Link from 'next/link'; import AnimeTooltip from '@/components/content-card/components/anime-tooltip'; +import CharacterTooltip from '@/components/content-card/components/character-tooltip'; import P from '@/components/typography/p'; import Image from '@/components/ui/image'; import { Label } from '@/components/ui/label'; @@ -58,6 +59,8 @@ const Tooltip: FC = ({ children, content_type, slug }) => { switch (content_type) { case 'anime': return {children}; + case 'character': + return {children}; default: return {children}; } diff --git a/components/markdown/viewer/components/link.tsx b/components/markdown/viewer/components/link.tsx index 3d41020c..eadbd020 100644 --- a/components/markdown/viewer/components/link.tsx +++ b/components/markdown/viewer/components/link.tsx @@ -4,6 +4,7 @@ import MaterialSymbolsLinkRounded from '~icons/material-symbols/link-rounded'; import NextLink from 'next/link'; import AnimeTooltip from '@/components/content-card/components/anime-tooltip'; +import CharacterTooltip from '@/components/content-card/components/character-tooltip'; import P from '@/components/typography/p'; import { AlertDialog, @@ -44,6 +45,17 @@ const Link: FC> = ({ children, href, className }) => { ); } + } + if (href.includes("/characters")) { + const link = href.split('/characters/')[1]?.split('/')[0]; + + if (link) { + return ( + + {children} + + ); + } } return {children}; diff --git a/components/ui/hover-card.tsx b/components/ui/hover-card.tsx index 7e669125..d423d3b0 100644 --- a/components/ui/hover-card.tsx +++ b/components/ui/hover-card.tsx @@ -33,8 +33,8 @@ HoverCardContent.displayName = HoverCardPrimitive.Content.displayName; export { HoverCard, - HoverCardTrigger, + HoverCardArrow, HoverCardContent, HoverCardPortal, - HoverCardArrow, + HoverCardTrigger, }; diff --git a/next.config.mjs b/next.config.mjs index c0ca0e8e..265529c4 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -1,6 +1,7 @@ -import bundleAnalyzer from '@next/bundle-analyzer'; import Icons from 'unplugin-icons/webpack'; +import bundleAnalyzer from '@next/bundle-analyzer'; + /** @type {import('next').NextConfig} */ const nextConfig = { eslint: { @@ -31,7 +32,7 @@ const nextConfig = { async rewrites() { return [ { - source: "/api/:path*", + source: '/api/:path*', destination: `${process.env.API_URL}/:path*`, }, ]; @@ -41,5 +42,4 @@ const withBundleAnalyzer = bundleAnalyzer({ enabled: process.env.ANALYZE === 'true', }); - export default withBundleAnalyzer(nextConfig); diff --git a/services/api/characters/getCharacterAnime.tsx b/services/api/characters/getCharacterAnime.tsx index 780954dc..6485206d 100644 --- a/services/api/characters/getCharacterAnime.tsx +++ b/services/api/characters/getCharacterAnime.tsx @@ -1,12 +1,11 @@ import { BaseFetchRequestProps, - FetchRequestProps, fetchRequest, } from '@/services/api/fetchRequest'; -export interface Response extends API.WithPagination {} +export interface Response extends API.WithPagination {} -export type Anime = { +export type CharacterAnime = { main: boolean; anime: API.Anime; };