Skip to content

Commit

Permalink
feat: add followings feature component for manga and novel
Browse files Browse the repository at this point in the history
  • Loading branch information
olexh committed Aug 19, 2024
1 parent 3325e2a commit 2083b24
Show file tree
Hide file tree
Showing 12 changed files with 232 additions and 112 deletions.
14 changes: 7 additions & 7 deletions src/app/(pages)/(content)/anime/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { FC } from 'react';
import Characters from '@/features/anime/anime-view/characters/characters.component';
import Description from '@/features/anime/anime-view/description.component';
import Details from '@/features/anime/anime-view/details/details.component';
import Followings from '@/features/anime/anime-view/followings/followings.component';
import Links from '@/features/anime/anime-view/links/links.component';
import Media from '@/features/anime/anime-view/media/media.component';
import Staff from '@/features/anime/anime-view/staff.component';
import WatchStats from '@/features/anime/anime-view/watch-stats/watch-stats.component';
import Followings from '@/features/followings/followings.component';
import Franchise from '@/features/franchise/franchise.component';

import getAnimeInfo, {
Expand Down Expand Up @@ -43,17 +43,17 @@ const AnimePage: FC<Props> = async ({ params }) => {
<Media />
<Staff />
<div className="flex flex-col gap-12 lg:hidden">
<WatchStats />
<Followings />
<Links />
<WatchStats key="watch-stats" />
<Followings content_type="anime" key="followings" />
<Links key="links" />
</div>
</div>
<div className="order-1 flex flex-col gap-12 lg:order-2">
<Details />
<div className="hidden lg:flex lg:flex-col lg:gap-12">
<WatchStats />
<Followings />
<Links />
<WatchStats key="watch-stats" />
<Followings content_type="anime" key="followings" />
<Links key="links" />
</div>
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions src/app/(pages)/(content)/manga/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { FC } from 'react';

import Followings from '@/features/followings/followings.component';
import Franchise from '@/features/franchise/franchise.component';
import Characters from '@/features/manga/manga-view/characters/characters.component';
import Description from '@/features/manga/manga-view/description.component';
Expand All @@ -24,13 +25,15 @@ const MangaPage: FC<Props> = async ({ params }) => {
<Staff />
<div className="flex flex-col gap-12 lg:hidden">
<ReadStats />
<Followings content_type="manga" key="followings" />
<Links />
</div>
</div>
<div className="order-1 flex flex-col gap-12 lg:order-2">
<Details />
<div className="hidden lg:flex lg:flex-col lg:gap-12">
<ReadStats />
<Followings content_type="manga" key="followings" />
<Links />
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions src/app/(pages)/(content)/novel/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { FC } from 'react';

import Followings from '@/features/followings/followings.component';
import Franchise from '@/features/franchise/franchise.component';
import Characters from '@/features/novel/novel-view/characters/characters.component';
import Description from '@/features/novel/novel-view/description.component';
Expand All @@ -24,13 +25,15 @@ const NovelPage: FC<Props> = async ({ params }) => {
<Staff />
<div className="flex flex-col gap-12 lg:hidden">
<ReadStats />
<Followings content_type="novel" key="followings" />
<Links />
</div>
</div>
<div className="order-1 flex flex-col gap-12 lg:order-2">
<Details />
<div className="hidden lg:flex lg:flex-col lg:gap-12">
<ReadStats />
<Followings content_type="novel" key="followings" />
<Links />
</div>
</div>
Expand Down
40 changes: 0 additions & 40 deletions src/features/anime/anime-view/followings/followings-modal.tsx

This file was deleted.

56 changes: 0 additions & 56 deletions src/features/anime/anime-view/followings/followings.component.tsx

This file was deleted.

52 changes: 52 additions & 0 deletions src/features/followings/following-read-item.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import Link from 'next/link';
import { FC } from 'react';
import MaterialSymbolsStarRounded from '~icons/material-symbols/star-rounded';

import P from '@/components/typography/p';
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
import { Label } from '@/components/ui/label';

import { READ_STATUS } from '@/utils/constants';
import { cn } from '@/utils/utils';

interface Props {
data: {
read: API.Read[];
} & API.User;
className?: string;
}

const FollowingReadItem: FC<Props> = ({ data, className }) => {
return (
<div className={cn('flex items-center gap-4', className)}>
<Avatar className="size-10 rounded-md" asChild>
<Link href={`/u/${data.username}`}>
<AvatarImage
className="size-10 rounded-md"
src={data.avatar}
/>
<AvatarFallback className="size-10 rounded-md" />
</Link>
</Avatar>
<div className="flex flex-1 flex-col gap-1">
<Label asChild>
<Link href={`/u/${data.username}`}>{data.username}</Link>
</Label>

<P className="text-xs text-muted-foreground">
{READ_STATUS[data.read[0].status].title_ua}
</P>
</div>
{data.read[0].score > 0 && (
<div className="inline-flex gap-1">
<Label className="leading-normal">
{data.read[0].score}
</Label>
<MaterialSymbolsStarRounded />
</div>
)}
</div>
);
};

export default FollowingReadItem;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Link from 'next/link';
import React, { FC } from 'react';
import { FC } from 'react';
import MaterialSymbolsStarRounded from '~icons/material-symbols/star-rounded';

import P from '@/components/typography/p';
Expand All @@ -16,7 +16,7 @@ interface Props {
className?: string;
}

const FollowingItem: FC<Props> = ({ data, className }) => {
const FollowingWatchItem: FC<Props> = ({ data, className }) => {
return (
<div className={cn('flex items-center gap-4', className)}>
<Avatar className="size-10 rounded-md" asChild>
Expand Down Expand Up @@ -49,4 +49,4 @@ const FollowingItem: FC<Props> = ({ data, className }) => {
);
};

export default FollowingItem;
export default FollowingWatchItem;
70 changes: 70 additions & 0 deletions src/features/followings/followings-modal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
'use client';

import { useParams } from 'next/navigation';
import { FC } from 'react';

import LoadMoreButton from '@/components/load-more-button';

import useFollowingReadList from '@/services/hooks/read/use-following-read-list';
import useFollowingWatchList from '@/services/hooks/watch/use-following-watch-list';

import FollowingReadItem from './following-read-item';
import FollowingWatchItem from './following-watch-item';

interface Props {
content_type: API.ContentType;
}

const FollowingsModal: FC<Props> = ({ content_type }) => {
const params = useParams();

const watchListQuery = useFollowingWatchList(
{
slug: String(params.slug),
},
{ enabled: content_type === 'anime' },
);

const readListQuery = useFollowingReadList(
{
slug: String(params.slug),
content_type: content_type as 'manga' | 'novel',
},
{ enabled: content_type !== 'anime' },
);

const { list, hasNextPage, isFetchingNextPage, fetchNextPage, ref } =
content_type === 'anime' ? watchListQuery : readListQuery;

return (
<div className="h-full w-auto flex-1 overflow-y-scroll">
{list &&
list.map((item) =>
'watch' in item ? (
<FollowingWatchItem
className="px-6 py-4"
data={item}
key={item.reference}
/>
) : (
<FollowingReadItem
className="px-6 py-4"
data={item}
key={item.reference}
/>
),
)}
{hasNextPage && (
<div className="px-6">
<LoadMoreButton
isFetchingNextPage={isFetchingNextPage}
fetchNextPage={fetchNextPage}
ref={ref}
/>
</div>
)}
</div>
);
};

export default FollowingsModal;
Loading

0 comments on commit 2083b24

Please sign in to comment.