mirror of
https://github.com/StepanovPlaton/torrent_frontend.git
synced 2026-04-04 04:40:50 +04:00
Refactoring
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
import { ItemCard } from "./itemCard";
|
||||
|
||||
export { ItemCard };
|
||||
@@ -1,52 +0,0 @@
|
||||
import {
|
||||
isAudiobook,
|
||||
isGame,
|
||||
isMovie,
|
||||
ItemCardType,
|
||||
ItemService,
|
||||
} from "@/entities/item";
|
||||
import { Img } from "@/shared/ui";
|
||||
import Link from "next/link";
|
||||
|
||||
export const ItemCard = ({ card }: { card: ItemCardType }) => {
|
||||
return (
|
||||
<Link
|
||||
className="group/itemcard cursor-pointer"
|
||||
href={"/" + ItemService.GetSectionUrlByItemType(card) + "/" + card.id}
|
||||
>
|
||||
{!!card.cover && (
|
||||
<Img
|
||||
src={card.cover}
|
||||
preview={true}
|
||||
className="rounded-lg object-contain"
|
||||
width={1280}
|
||||
height={720}
|
||||
/>
|
||||
)}
|
||||
<div className="flex items-center justify-between pr-2">
|
||||
<h2 className="text-3xl tb:text-xl py-1 group-hover/itemcard:underline underline-offset-1">
|
||||
{card.title}
|
||||
</h2>
|
||||
|
||||
{isGame(card) && card.version && (
|
||||
<span className="text-xs max-w-[30%] text-right line-clamp-2 text-fg4">
|
||||
{card.version}
|
||||
</span>
|
||||
)}
|
||||
{isMovie(card) && card.age && (
|
||||
<span className="text-xs max-w-[30%] text-right line-clamp-2 text-fg4">
|
||||
{card.age}
|
||||
</span>
|
||||
)}
|
||||
{isAudiobook(card) && card.author && (
|
||||
<span className="text-xs max-w-[40%] text-right line-clamp-2 text-fg4">
|
||||
{card.author}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<p className="text-lg tb:text-sm pr-2 text-justify line-clamp-5 text-fg4">
|
||||
{card.description}
|
||||
</p>
|
||||
</Link>
|
||||
);
|
||||
};
|
||||
2
src/features/sections/index.ts
Normal file
2
src/features/sections/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
import { SectionService, type SectionType } from "./sections";
|
||||
export { SectionService, type SectionType };
|
||||
64
src/features/sections/sections.ts
Normal file
64
src/features/sections/sections.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
import { TypesOfItems } from "@/entities/item";
|
||||
|
||||
export type SectionType = (typeof SectionService.sections)[number];
|
||||
|
||||
export abstract class SectionService {
|
||||
static get itemTypeToSection(): { [k in TypesOfItems]: SectionType } {
|
||||
return {
|
||||
[TypesOfItems.game]: "games",
|
||||
[TypesOfItems.movie]: "movies",
|
||||
[TypesOfItems.audiobook]: "audiobooks",
|
||||
};
|
||||
}
|
||||
|
||||
static get sectionsConfiguration(): {
|
||||
[k in SectionType]: {
|
||||
sectionName: string;
|
||||
sectionUrl: string;
|
||||
itemType: TypesOfItems;
|
||||
popularSubsectionName: string;
|
||||
sectionInviteText: string;
|
||||
addItemText: string;
|
||||
sectionDescription: string;
|
||||
};
|
||||
} {
|
||||
return {
|
||||
games: {
|
||||
sectionName: "Игры",
|
||||
sectionUrl: "games",
|
||||
itemType: TypesOfItems.game,
|
||||
popularSubsectionName: "Популярные игры",
|
||||
sectionInviteText: 'Перейти в раздел "Игры"',
|
||||
addItemText: "Добавить игру",
|
||||
sectionDescription:
|
||||
"каталог .torrent файлов для обмена актуальными версиями популярных игр",
|
||||
},
|
||||
movies: {
|
||||
sectionName: "Фильмы",
|
||||
sectionUrl: "movies",
|
||||
itemType: TypesOfItems.movie,
|
||||
popularSubsectionName: "Популярные фильмы",
|
||||
sectionInviteText: 'Перейти в раздел "Фильмы"',
|
||||
addItemText: "Добавить фильм",
|
||||
sectionDescription:
|
||||
"каталог .torrent файлов для обмена популярными фильмами в лучшем качестве",
|
||||
},
|
||||
audiobooks: {
|
||||
sectionName: "Аудиокниги",
|
||||
sectionUrl: "audiobooks",
|
||||
itemType: TypesOfItems.audiobook,
|
||||
popularSubsectionName: "Популярные аудиокниги",
|
||||
sectionInviteText: 'Перейти в раздел "Аудиокниги"',
|
||||
addItemText: "Добавить аудиокнигу",
|
||||
sectionDescription:
|
||||
"каталог .torrent файлов для обмена популярными аудиокнигами любимых авторов",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
static sections = ["games", "movies", "audiobooks"] as const;
|
||||
|
||||
static isSection = (a: string): a is SectionType => {
|
||||
return this.sections.includes(a as SectionType);
|
||||
};
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import useSWR, { mutate } from "swr";
|
||||
import clsx from "clsx";
|
||||
import Cookies from "js-cookie";
|
||||
import { useState } from "react";
|
||||
import { ItemService } from "@/entities/item";
|
||||
import { SectionService } from "../sections";
|
||||
|
||||
export const UserActivities = () => {
|
||||
const { data: me } = useSWR("user", () => UserService.IdentifyYourself());
|
||||
@@ -39,14 +39,13 @@ export const UserActivities = () => {
|
||||
{[
|
||||
{
|
||||
group: "Добавить:",
|
||||
items: Object.entries(ItemService.itemSections).map(
|
||||
([sectionId, section]) => {
|
||||
return {
|
||||
name: section.addItemText,
|
||||
link: `/${sectionId}/add`,
|
||||
};
|
||||
}
|
||||
),
|
||||
items: SectionService.sections.map((section) => {
|
||||
return {
|
||||
name: SectionService.sectionsConfiguration[section]
|
||||
.addItemText,
|
||||
link: `/${SectionService.sectionsConfiguration[section].sectionUrl}/add`,
|
||||
};
|
||||
}),
|
||||
},
|
||||
{
|
||||
name: "Выйти",
|
||||
|
||||
Reference in New Issue
Block a user