-
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
19 changed files
with
438 additions
and
46 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 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
35 changes: 35 additions & 0 deletions
35
...es)/comments/[content_type]/[slug]/[[...comment_reference]]/components/content-header.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,35 @@ | ||
'use client'; | ||
|
||
import { FC } from 'react'; | ||
|
||
|
||
|
||
import useContent from '@/app/(pages)/comments/[content_type]/[slug]/[[...comment_reference]]/components/useContent'; | ||
import P from '@/components/typography/p'; | ||
import Header from '@/components/ui/header'; | ||
import { CONTENT_TYPE_LINKS, CONTENT_TYPES } from '@/utils/constants'; | ||
|
||
|
||
interface Props { | ||
slug: string; | ||
content_type: API.ContentType; | ||
} | ||
|
||
const ContentHeader: FC<Props> = ({ slug, content_type }) => { | ||
const { data } = useContent({ | ||
content_type, | ||
slug | ||
}) | ||
|
||
const link = `${CONTENT_TYPE_LINKS[content_type]}/${slug}`; | ||
|
||
|
||
return ( | ||
<div> | ||
<Header href={link} title={data?.title} variant="h2" /> | ||
<P className="text-sm text-muted-foreground">{CONTENT_TYPES[content_type].title_ua}</P> | ||
</div> | ||
) | ||
} | ||
|
||
export default ContentHeader; |
41 changes: 41 additions & 0 deletions
41
app/(pages)/comments/[content_type]/[slug]/[[...comment_reference]]/components/content.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,41 @@ | ||
'use client'; | ||
|
||
import * as React from 'react'; | ||
import { FC } from 'react'; | ||
|
||
import Link from 'next/link'; | ||
|
||
import ContentCard from '@/components/content-card/content-card'; | ||
import Block from '@/components/ui/block'; | ||
import Header from '@/components/ui/header'; | ||
import { CONTENT_TYPE_LINKS } from '@/utils/constants'; | ||
|
||
import useContent from './useContent'; | ||
|
||
|
||
interface Props { | ||
slug: string; | ||
content_type: API.ContentType; | ||
} | ||
|
||
const Content: FC<Props> = ({ slug, content_type }) => { | ||
const { data } = useContent({ content_type, slug }); | ||
|
||
const link = `${CONTENT_TYPE_LINKS[content_type]}/${slug}`; | ||
|
||
return ( | ||
<Block> | ||
<div className="hidden w-full items-center gap-4 px-16 md:px-48 lg:flex lg:px-0"> | ||
<ContentCard href={link} poster={data?.image} /> | ||
</div> | ||
<div className="flex w-full gap-4 lg:hidden"> | ||
<div className="w-12"> | ||
<ContentCard href={link} poster={data?.image} /> | ||
</div> | ||
<Link href={link}>{data?.title}</Link> | ||
</div> | ||
</Block> | ||
); | ||
}; | ||
|
||
export default Content; |
104 changes: 104 additions & 0 deletions
104
app/(pages)/comments/[content_type]/[slug]/[[...comment_reference]]/components/useContent.ts
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,104 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
import getAnimeInfo from '@/services/api/anime/getAnimeInfo'; | ||
import getCharacterInfo from '@/services/api/characters/getCharacterInfo'; | ||
import getCollection from '@/services/api/collections/getCollection'; | ||
import getEdit from '@/services/api/edit/getEdit'; | ||
import getPersonInfo from '@/services/api/people/getPersonInfo'; | ||
import { useSettingsContext } from '@/services/providers/settings-provider'; | ||
|
||
interface Props { | ||
content_type: API.ContentType; | ||
slug: string; | ||
} | ||
|
||
interface Response { | ||
title: string; | ||
image: string; | ||
content_type: API.ContentType; | ||
} | ||
|
||
export const getContent = ({ content_type, slug }: Props) => { | ||
switch (content_type) { | ||
case 'anime': | ||
return getAnimeInfo({ params: { slug } }); | ||
case 'character': | ||
return getCharacterInfo({ params: { slug } }); | ||
case 'person': | ||
return getPersonInfo({ params: { slug } }); | ||
case 'collection': | ||
return getCollection({ params: { reference: slug } }); | ||
case 'edit': | ||
return getEdit({ params: { edit_id: Number(slug) } }); | ||
default: | ||
return getAnimeInfo({ params: { slug } }); | ||
} | ||
}; | ||
|
||
const useContent = ({ slug, content_type }: Props) => { | ||
const { titleLanguage } = useSettingsContext(); | ||
|
||
const query = useQuery({ | ||
queryKey: ['content', content_type, slug], | ||
queryFn: async () => getContent({ content_type, slug }), | ||
select: (data) => { | ||
let content: Response | undefined; | ||
|
||
if ('data_type' in data) { | ||
if (data.data_type === 'anime') { | ||
content = { | ||
title: | ||
data[titleLanguage!] || | ||
data.title_ua || | ||
data.title_en || | ||
data.title_ja, | ||
image: data.poster, | ||
content_type, | ||
}; | ||
} | ||
|
||
if (data.data_type === 'character') { | ||
content = { | ||
title: data.name_ua || data.name_en || data.name_ja, | ||
image: data.image, | ||
content_type, | ||
}; | ||
} | ||
|
||
if (data.data_type === 'person') { | ||
content = { | ||
title: data.name_ua || data.name_en || data.name_native, | ||
image: data.image, | ||
content_type, | ||
}; | ||
} | ||
|
||
if (data.data_type === 'collection') { | ||
content = { | ||
title: data.title, | ||
image: | ||
data.collection[0].content.data_type === 'anime' | ||
? data.collection[0].content.poster | ||
: data.collection[0].content.image, | ||
content_type, | ||
}; | ||
} | ||
} else { | ||
content = { | ||
title: `Правка #${data.edit_id}`, | ||
image: | ||
data.content.data_type === 'anime' | ||
? data.content.poster | ||
: data.content.image, | ||
content_type, | ||
}; | ||
} | ||
|
||
return content; | ||
}, | ||
}); | ||
|
||
return query; | ||
}; | ||
|
||
export default useContent; |
Oops, something went wrong.