Skip to content

Commit

Permalink
add content info in edit page
Browse files Browse the repository at this point in the history
  • Loading branch information
olexh committed Mar 5, 2024
1 parent 951dcd8 commit ed2f7cd
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 102 deletions.
48 changes: 0 additions & 48 deletions app/(pages)/edit/[editId]/_components/content.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion app/(pages)/edit/[editId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import getEdit from '@/services/api/edit/getEdit';
import getQueryClient from '@/utils/getQueryClient';

import EditView from '../_components/edit-view';
import Content from '../_components/ui/content';
import Content from '../_components/ui/content/content';
import EditStatus from '../_components/ui/edit-status';
import Actions from './_components/actions';
import Author from './_components/author';
Expand Down
52 changes: 0 additions & 52 deletions app/(pages)/edit/_components/ui/content.tsx

This file was deleted.

36 changes: 36 additions & 0 deletions app/(pages)/edit/_components/ui/content/_components/details.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import * as React from 'react';

import { Label } from '@/components/ui/label';

interface Props {
content: API.AnimeInfo | API.Character;
}

const Component = ({ content }: Props) => {
const title_ua = 'title_ua' in content ? content.title_ua : content.name_ua;
const title_en = 'title_en' in content ? content.title_en : content.name_en;
const title_ja = 'title_ja' in content ? content.title_ja : content.name_ja;

return (
<div className="bg-secondary/30 border border-secondary/60 p-4 rounded-md flex flex-col gap-4">
<div className="flex-col gap-2">
<Label className="text-muted-foreground">
Назва українською
</Label>
<p className="text-sm">{title_ua || '-'}</p>
</div>
<div className="flex-col gap-2">
<Label className="text-muted-foreground">
Назва англійською
</Label>
<p className="text-sm">{title_en || '-'}</p>
</div>
<div className="flex-col gap-2">
<Label className="text-muted-foreground">Назва оригіналу</Label>
<p className="text-sm">{title_ja || '-'}</p>
</div>
</div>
);
};

export default Component;
29 changes: 29 additions & 0 deletions app/(pages)/edit/_components/ui/content/_components/general.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as React from 'react';

import Link from 'next/link';

import BaseCard from '@/components/ui/base-card';

interface Props {
href: string;
poster: string;
title: string;
}

const Component = ({ href, title, poster }: Props) => {
return (
<>
<div className="hidden w-full items-center gap-4 px-16 md:px-48 lg:flex lg:px-0">
<BaseCard href={href} poster={poster} />
</div>
<div className="flex w-full gap-4 lg:hidden">
<div className="w-12">
<BaseCard href={href} poster={poster} />
</div>
<Link href={href}>{title}</Link>
</div>
</>
);
};

export default Component;
64 changes: 64 additions & 0 deletions app/(pages)/edit/_components/ui/content/content.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
'use client';

import * as React from 'react';

import General from '@/app/(pages)/edit/_components/ui/content/_components/general';
import SubHeader from '@/components/sub-header';
import { Button } from '@/components/ui/button';
import { useSettingsContext } from '@/services/providers/settings-provider';
import { CONTENT_TYPE_LINKS } from '@/utils/constants';

import Details from './_components/details';

interface Props {
slug: string;
content_type: API.ContentType;
content?: API.AnimeInfo | API.Character;
}

const Component = ({ slug, content_type, content }: Props) => {
const [type, setType] = React.useState<'general' | 'details'>('general');
const { titleLanguage } = useSettingsContext();

if (!content) {
return null;
}

const link = `${CONTENT_TYPE_LINKS[content_type]}/${slug}`;

const poster = 'poster' in content ? content.poster : content.image;
const title =
'title_en' in content
? content[titleLanguage!] ||
content.title_ua ||
content.title_en ||
content.title_ja
: content.name_ua || content.name_en;

return (
<div className="flex flex-col gap-8">
<SubHeader title="Контент" variant="h4">
<Button
variant={type === 'general' ? 'secondary' : 'outline'}
size="badge"
onClick={() => setType('general')}
>
Загальне
</Button>
<Button
variant={type === 'details' ? 'secondary' : 'outline'}
size="badge"
onClick={() => setType('details')}
>
Деталі
</Button>
</SubHeader>
{type === 'general' && (
<General href={link} poster={poster} title={title} />
)}
{type === 'details' && <Details content={content} />}
</div>
);
};

export default Component;
3 changes: 3 additions & 0 deletions app/(pages)/edit/_components/ui/content/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Content from './content';

export default Content;
2 changes: 1 addition & 1 deletion app/(pages)/edit/new/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import getAnimeInfo from '@/services/api/anime/getAnimeInfo';
import getCharacterInfo from '@/services/api/characters/getCharacterInfo';
import getQueryClient from '@/utils/getQueryClient';

import Content from '../_components/ui/content';
import Content from '../_components/ui/content/content';
import EditForm from '../_components/edit-form';
import RulesAlert from './_components/rules-alert';

Expand Down

0 comments on commit ed2f7cd

Please sign in to comment.