-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
266 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...me/[slug]/_components/actions/actions.tsx → ...ime/[slug]/components/actions/actions.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
54 changes: 54 additions & 0 deletions
54
app/(pages)/anime/[slug]/components/watch-stats/components/score.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
'use client'; | ||
|
||
import { useParams } from 'next/navigation'; | ||
|
||
import Small from '@/components/typography/small'; | ||
import useAnimeInfo from '@/services/hooks/anime/useAnimeInfo'; | ||
|
||
import Stats from './ui/stats'; | ||
|
||
|
||
const Score = () => { | ||
const params = useParams(); | ||
const { data } = useAnimeInfo({ slug: String(params.slug) }); | ||
|
||
if (!data) { | ||
return null; | ||
} | ||
|
||
const sumStats = | ||
data.stats.score_1 + | ||
data.stats.score_2 + | ||
data.stats.score_3 + | ||
data.stats.score_4 + | ||
data.stats.score_5 + | ||
data.stats.score_6 + | ||
data.stats.score_7 + | ||
data.stats.score_8 + | ||
data.stats.score_9 + | ||
data.stats.score_10; | ||
|
||
const stats = Object.keys(data.stats) | ||
.reverse() | ||
.reduce((acc: Hikka.WatchStat[], stat) => { | ||
if ( | ||
stat.includes('score') && | ||
data.stats[stat as API.StatType] > 0 | ||
) { | ||
const percentage = | ||
(100 * data.stats[stat as API.StatType]) / sumStats; | ||
|
||
acc.push({ | ||
icon: <Small>{stat.split('score_')[1]}</Small>, | ||
percentage, | ||
value: data.stats[stat as API.StatType], | ||
}); | ||
} | ||
|
||
return acc; | ||
}, []); | ||
|
||
return <Stats stats={stats} />; | ||
}; | ||
|
||
export default Score; |
71 changes: 71 additions & 0 deletions
71
app/(pages)/anime/[slug]/components/watch-stats/components/ui/stats.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
'use client'; | ||
|
||
import { NumericFormat } from 'react-number-format'; | ||
|
||
import Small from '@/components/typography/small'; | ||
import { | ||
Tooltip, | ||
TooltipContent, | ||
TooltipTrigger, | ||
} from '@/components/ui/tooltip'; | ||
|
||
interface Props { | ||
stats: Hikka.WatchStat[]; | ||
} | ||
|
||
const Stats = ({ stats }: Props) => { | ||
return ( | ||
<div className="relative overflow-hidden rounded-lg border border-secondary/60 bg-secondary/30 p-4"> | ||
<div className="flex flex-col justify-center gap-2"> | ||
{stats.map((stat) => { | ||
return ( | ||
<Tooltip | ||
key={`${stat.value}-${stat.percentage}`} | ||
delayDuration={0} | ||
> | ||
<TooltipTrigger> | ||
<div className="flex items-center justify-between gap-2"> | ||
<div className="flex w-full flex-1 items-center gap-2"> | ||
{stat.icon && ( | ||
<div className="flex size-6 items-center justify-center rounded-md bg-secondary"> | ||
{stat.icon} | ||
</div> | ||
)} | ||
<div className="relative h-2 w-full flex-1 overflow-hidden rounded-md"> | ||
<div | ||
className="absolute bottom-0 left-0 size-full bg-primary opacity-10" | ||
style={{ | ||
backgroundColor: stat.color, | ||
}} | ||
/> | ||
<div | ||
className="absolute bottom-0 left-0 flex h-2 w-full items-end justify-center bg-primary" | ||
style={{ | ||
backgroundColor: stat.color, | ||
width: `${stat.percentage}%`, | ||
}} | ||
></div> | ||
</div> | ||
</div> | ||
<Small className="w-14 text-right text-muted-foreground"> | ||
<NumericFormat | ||
thousandSeparator | ||
displayType="text" | ||
value={stat.value} | ||
decimalScale={1} | ||
/> | ||
</Small> | ||
</div> | ||
</TooltipTrigger> | ||
<TooltipContent align="center" side="left"> | ||
{stat.percentage.toFixed(2)}% | ||
</TooltipContent> | ||
</Tooltip> | ||
); | ||
})} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Stats; |
51 changes: 51 additions & 0 deletions
51
app/(pages)/anime/[slug]/components/watch-stats/components/watchlist.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
'use client'; | ||
|
||
import { createElement } from 'react'; | ||
|
||
import { useParams } from 'next/navigation'; | ||
|
||
import useAnimeInfo from '@/services/hooks/anime/useAnimeInfo'; | ||
import { WATCH_STATUS } from '@/utils/constants'; | ||
|
||
import Stats from './ui/stats'; | ||
|
||
|
||
const Watchlist = () => { | ||
const params = useParams(); | ||
const { data } = useAnimeInfo({ slug: String(params.slug) }); | ||
|
||
if (!data) { | ||
return null; | ||
} | ||
|
||
const sumStats = | ||
data.stats.completed + | ||
data.stats.on_hold + | ||
data.stats.dropped + | ||
data.stats.planned + | ||
data.stats.watching; | ||
|
||
const stats = Object.keys(data.stats).reduce( | ||
(acc: Hikka.WatchStat[], stat) => { | ||
if (!stat.includes('score')) { | ||
const status = WATCH_STATUS[stat as API.WatchStatus]; | ||
const percentage = | ||
(100 * data.stats[stat as API.StatType]) / sumStats; | ||
|
||
acc.push({ | ||
percentage, | ||
value: data.stats[stat as API.StatType], | ||
icon: status.icon && createElement(status.icon), | ||
color: status.color!, | ||
}); | ||
} | ||
|
||
return acc; | ||
}, | ||
[], | ||
); | ||
|
||
return <Stats stats={stats} />; | ||
}; | ||
|
||
export default Watchlist; |
39 changes: 39 additions & 0 deletions
39
app/(pages)/anime/[slug]/components/watch-stats/watch-stats.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import SubHeader from '@/components/sub-header'; | ||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'; | ||
import { ToggleGroup, ToggleGroupItem } from '@/components/ui/toggle-group'; | ||
|
||
import Score from './components/score'; | ||
import Watchlist from './components/watchlist'; | ||
|
||
const WatchStats = () => { | ||
return ( | ||
<div className="flex flex-col gap-8"> | ||
<SubHeader title="Статистика"> | ||
<ToggleGroup | ||
type="single" | ||
value="MAL" | ||
variant="outline" | ||
size="badge" | ||
> | ||
<ToggleGroupItem value="MAL" aria-label="MAL"> | ||
MAL | ||
</ToggleGroupItem> | ||
</ToggleGroup> | ||
</SubHeader> | ||
<Tabs defaultValue="watchlist"> | ||
<TabsList className="grid w-full grid-cols-2"> | ||
<TabsTrigger value="watchlist">У списках</TabsTrigger> | ||
<TabsTrigger value="score">Оцінки</TabsTrigger> | ||
</TabsList> | ||
<TabsContent value="watchlist"> | ||
<Watchlist /> | ||
</TabsContent> | ||
<TabsContent value="score"> | ||
<Score /> | ||
</TabsContent> | ||
</Tabs> | ||
</div> | ||
); | ||
}; | ||
|
||
export default WatchStats; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.