Refactoring

This commit is contained in:
2024-06-23 19:43:12 +04:00
parent 7f4d1bf87d
commit ea723b88b0
18 changed files with 224 additions and 223 deletions

View File

@@ -1,3 +0,0 @@
import { ItemCard } from "./itemCard";
export { ItemCard };

View File

@@ -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>
);
};

View File

@@ -0,0 +1,2 @@
import { SectionService, type SectionType } from "./sections";
export { SectionService, type SectionType };

View 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);
};
}

View File

@@ -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: "Выйти",