-
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
7 changed files
with
182 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
'use client'; | ||
|
||
import * as React from 'react'; | ||
import { FC } from 'react'; | ||
|
||
import ContentCard from '@/components/content-card/content-card'; | ||
import LoadMoreButton from '@/components/load-more-button'; | ||
import { Badge } from '@/components/ui/badge'; | ||
import Block from '@/components/ui/block'; | ||
import Card from '@/components/ui/card'; | ||
import Header from '@/components/ui/header'; | ||
import HorizontalCard from '@/components/ui/horizontal-card'; | ||
import NotFound from '@/components/ui/not-found'; | ||
import Stack from '@/components/ui/stack'; | ||
import useGlobalComments from '@/services/hooks/comments/useGlobalComments'; | ||
import { CONTENT_TYPE_LINKS } from '@/utils/constants'; | ||
import { cn } from '@/utils/utils'; | ||
|
||
interface Props { | ||
className?: string; | ||
} | ||
|
||
const Comments: FC<Props> = ({ className }) => { | ||
const { list, hasNextPage, ref, isFetchingNextPage, fetchNextPage } = | ||
useGlobalComments(); | ||
|
||
return ( | ||
<Block className={cn(className)}> | ||
<Header title="Останні коментарі" /> | ||
<Stack | ||
size={3} | ||
extended | ||
extendedSize={3} | ||
className="grid-cols-1 md:grid-cols-1" | ||
> | ||
{list?.map((item, index) => ( | ||
<Card key={item.reference}> | ||
<Badge | ||
variant="secondary" | ||
className="absolute -top-3 left-4 z-[1]" | ||
> | ||
#{index + 1} | ||
</Badge> | ||
<HorizontalCard | ||
image={item.author.avatar} | ||
imageRatio={1} | ||
description={item.text} | ||
key={item.created} | ||
title={item.author.username} | ||
href={`/u/${item.author.username}`} | ||
createdAt={item.created} | ||
> | ||
<ContentCard | ||
className="w-10" | ||
poster={item.image} | ||
href={`${CONTENT_TYPE_LINKS[item.content_type]}/${item.slug}`} | ||
/> | ||
</HorizontalCard> | ||
</Card> | ||
))} | ||
{list?.length === 0 && ( | ||
<NotFound | ||
title="Історія відсутня" | ||
description="Історія оновиться після змін у Вашому списку, або у списку користувачів, яких Ви відстежуєте" | ||
/> | ||
)} | ||
</Stack> | ||
{list && hasNextPage && ( | ||
<LoadMoreButton | ||
ref={ref} | ||
fetchNextPage={fetchNextPage} | ||
isFetchingNextPage={isFetchingNextPage} | ||
/> | ||
)} | ||
</Block> | ||
); | ||
}; | ||
|
||
export default Comments; |
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,55 @@ | ||
import { Metadata } from 'next'; | ||
import * as React from 'react'; | ||
import { FC } from 'react'; | ||
|
||
|
||
|
||
import { dehydrate } from '@tanstack/query-core'; | ||
import { HydrationBoundary } from '@tanstack/react-query'; | ||
|
||
|
||
|
||
import getGlobalComments from '@/services/api/comments/getGlobalComments'; | ||
import getFollowingHistory from '@/services/api/history/getFollowingHistory'; | ||
import { getCookie } from '@/utils/cookies'; | ||
import _generateMetadata from '@/utils/generateMetadata'; | ||
import getQueryClient from '@/utils/getQueryClient'; | ||
|
||
|
||
|
||
import Comments from './components/comments'; | ||
|
||
|
||
export const metadata: Metadata = _generateMetadata({ | ||
title: 'Активність', | ||
}); | ||
|
||
interface Props { | ||
searchParams: Record<string, any>; | ||
} | ||
|
||
const FollowingHistoryPage: FC<Props> = async ({ searchParams }) => { | ||
const queryClient = await getQueryClient(); | ||
|
||
await queryClient.prefetchInfiniteQuery({ | ||
initialPageParam: 1, | ||
queryKey: ['globalComments'], | ||
queryFn: ({ pageParam, meta }) => | ||
getGlobalComments({ | ||
page: pageParam, | ||
auth: meta?.auth, | ||
}), | ||
}) | ||
|
||
const dehydratedState = dehydrate(queryClient); | ||
|
||
return ( | ||
<HydrationBoundary state={dehydratedState}> | ||
<div className="flex flex-col gap-12"> | ||
<Comments /> | ||
</div> | ||
</HydrationBoundary> | ||
); | ||
}; | ||
|
||
export default FollowingHistoryPage; |
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,18 @@ | ||
import { | ||
BaseFetchRequestProps, | ||
fetchRequest, | ||
} from '@/services/api/fetchRequest'; | ||
|
||
export default async function req({ | ||
page = 1, | ||
size = 15, | ||
...props | ||
}: BaseFetchRequestProps): Promise<API.WithPagination<API.GlobalComment>> { | ||
return fetchRequest<API.WithPagination<API.GlobalComment>>({ | ||
...props, | ||
path: `/comments/list`, | ||
method: 'get', | ||
page, | ||
size, | ||
}); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import getGlobalComments from '@/services/api/comments/getGlobalComments'; | ||
import useInfiniteList from '@/services/hooks/useInfiniteList'; | ||
|
||
const useGlobalComments = () => { | ||
return useInfiniteList({ | ||
queryKey: ['globalComments'], | ||
queryFn: ({ pageParam }) => | ||
getGlobalComments({ | ||
page: pageParam, | ||
}), | ||
}); | ||
}; | ||
|
||
export default useGlobalComments; |
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