diff --git a/src/pages/CardListPages/CardList.module.scss b/src/pages/CardListPages/CardList.module.scss deleted file mode 100644 index 778cba5..0000000 --- a/src/pages/CardListPages/CardList.module.scss +++ /dev/null @@ -1,17 +0,0 @@ -.mainContainer { - margin: 0 10%; - @include mediaMax($mobile-xs-width) { - margin: 0 5%; - } -} -.title { - font-size: 36px; - font-weight: 600; - line-height: 44px; - margin-top: 0; - margin-bottom: 8px; - @include mediaMax($tablet-max-width) { - font-size: 24px; - margin-top: 0; - } -} diff --git a/src/pages/CardListPages/CardListPages.tsx b/src/pages/CardListPages/CardListPages.tsx deleted file mode 100644 index 3c3d944..0000000 --- a/src/pages/CardListPages/CardListPages.tsx +++ /dev/null @@ -1,107 +0,0 @@ -// pages/MainPage/ui/MainPage/Lists.tsx -import { CardList } from "@/widgets/CardList/CardList"; -import { GridConfig } from "@/widgets/CardList/types"; -import { usePosts } from "@/modules/posts/hooks/usePosts"; -import styles from "./CardList.module.scss"; -import { useNews } from "@/modules"; -import { - transformNewsToCardData, - transformPostsToCardData, -} from "@/pages/CardListPages/CardListFunctions"; -import { useProjects } from "@/modules/posts/hooks/usePostProjects"; - -interface ListProps { - gridConfig?: GridConfig; - tag?: number; -} - -const NewsList = ({ - gridConfig = { desktop: 3, tablet: 2, mobile: 1 }, -}: ListProps) => { - const { data: newsData, isLoading, isError } = useNews(); - - if (isLoading) - return ( -
-

Новости

- -
- ); - - if (isError) return
Ошибка при загрузке данных
; - - return ( -
- {newsData && ( - - )} -
- ); -}; - -const LabsList = ({ - gridConfig = { desktop: 3, tablet: 2, mobile: 1 }, -}: ListProps) => { - const { data: postsData, isLoading, isError } = usePosts(); - const labs = postsData?.labs ? Object.values(postsData.labs) : []; - - if (isLoading) - return ( -
-

Лаборатории

- -
- ); - - if (isError) return
Ошибка при загрузке данных
; - - return ( -
- -
- ); -}; - -const ProjectsList = ({ - gridConfig = { desktop: 3, tablet: 2, mobile: 1 }, - tag = -1, -}: ListProps) => { - const { data: projects, isError, isLoading } = useProjects(tag); - - if (isLoading) - return ( -
-

Проекты

- -
- ); - - if (isError) return
Ошибка при загрузке данных
; - - return ( - <> - {projects?.length !== 0 && -
- -
- } - - ); -}; - -export { NewsList, LabsList, ProjectsList }; diff --git a/src/pages/MainPage/ui/MainPage/MainPage.tsx b/src/pages/MainPage/ui/MainPage/MainPage.tsx index a95f634..2b572e8 100644 --- a/src/pages/MainPage/ui/MainPage/MainPage.tsx +++ b/src/pages/MainPage/ui/MainPage/MainPage.tsx @@ -9,7 +9,7 @@ import { LabsList, NewsList, ProjectsList, -} from "@/pages/CardListPages/CardListPages"; +} from "@/widgets/CardList/CardList"; const MainPage = () => { const { setRef } = useContext(RootContext); diff --git a/src/pages/WpPostPage/WpPostPage.tsx b/src/pages/WpPostPage/WpPostPage.tsx index aba694a..6c3161e 100644 --- a/src/pages/WpPostPage/WpPostPage.tsx +++ b/src/pages/WpPostPage/WpPostPage.tsx @@ -1,9 +1,9 @@ import { usePostById } from "@/modules"; import { WpPost } from "@/widgets/WpPost"; import { useParams } from "react-router-dom"; -import { ProjectsList } from "../CardListPages/CardListPages"; +import { ProjectsList } from "@/widgets/CardList/CardList"; -function PostPage() { +function WpPostPage() { const params = useParams(); const postId = params.id ? parseInt(params.id, 10) : null; @@ -28,11 +28,11 @@ function PostPage() { return (<> {post && <> - + {post?.categories?.includes("labs") && } } ); } -export default PostPage; +export default WpPostPage; diff --git a/src/widgets/Card/Card.module.scss b/src/shared/Components/Card/Card.module.scss similarity index 100% rename from src/widgets/Card/Card.module.scss rename to src/shared/Components/Card/Card.module.scss diff --git a/src/widgets/Card/Card.tsx b/src/shared/Components/Card/Card.tsx similarity index 100% rename from src/widgets/Card/Card.tsx rename to src/shared/Components/Card/Card.tsx diff --git a/src/widgets/Card/types.ts b/src/shared/Components/Card/types.ts similarity index 100% rename from src/widgets/Card/types.ts rename to src/shared/Components/Card/types.ts diff --git a/src/widgets/CardList/CardList.module.scss b/src/widgets/CardList/CardList.module.scss index 9e7b4b0..778cba5 100644 --- a/src/widgets/CardList/CardList.module.scss +++ b/src/widgets/CardList/CardList.module.scss @@ -1,3 +1,9 @@ +.mainContainer { + margin: 0 10%; + @include mediaMax($mobile-xs-width) { + margin: 0 5%; + } +} .title { font-size: 36px; font-weight: 600; @@ -9,40 +15,3 @@ margin-top: 0; } } -.list { - display: grid; - gap: 2rem; - width: 100%; - max-width: 100%; - box-sizing: border-box; - margin-bottom: 32px; - &__lab { - grid-template-columns: repeat(var(--desktop-columns, 3), 1fr); - @include mediaMax($desktop-small-width) { - grid-template-columns: repeat(var(--tablet-columns, 3), 1fr); - } - @include mediaMax($tablet-max-width) { - grid-template-columns: repeat(var(--mobile-columns, 3), 1fr); - } - } - - &__news { - grid-template-columns: repeat(var(--desktop-columns, 3), 1fr); - @include mediaMax($desktop-small-width) { - grid-template-columns: repeat(var(--tablet-columns, 3), 1fr); - } - @include mediaMax($tablet-max-width) { - grid-template-columns: repeat(var(--mobile-columns, 3), 1fr); - } - } - - &__project { - grid-template-columns: repeat(var(--desktop-columns, 3), 1fr); - @include mediaMax($desktop-small-width) { - grid-template-columns: repeat(var(--tablet-columns, 3), 1fr); - } - @include mediaMax($tablet-max-width) { - grid-template-columns: repeat(var(--mobile-columns, 3), 1fr); - } - } -} diff --git a/src/widgets/CardList/CardList.tsx b/src/widgets/CardList/CardList.tsx index 11da5b6..4aaafc7 100644 --- a/src/widgets/CardList/CardList.tsx +++ b/src/widgets/CardList/CardList.tsx @@ -1,34 +1,104 @@ -// widgets/CardList/CardList.tsx -import { CardListProps } from "@/widgets/CardList/types"; +// pages/MainPage/ui/MainPage/Lists.tsx +import { CardListTemplate } from "@/widgets/CardList/CardListTemplate"; +import { GridConfig } from "@/widgets/CardList/types"; +import { usePosts } from "@/modules/posts/hooks/usePosts"; import styles from "./CardList.module.scss"; -import { Card } from "@/widgets/Card/Card"; -import { classNames } from "@/shared/lib/classNames/classNames"; +import { useNews } from "@/modules"; +import { + transformNewsToCardData, + transformPostsToCardData, +} from "@/widgets/CardList/CardListFunctions"; +import { usePostProjects } from "@/modules/posts/hooks/usePostProjects"; -export const CardList = ({ - items, - variant = "lab", // Значение по умолчанию +interface ListProps { + gridConfig?: GridConfig; + tag?: number; +} + +const NewsList = ({ gridConfig = { desktop: 3, tablet: 2, mobile: 1 }, - title = "Лаборатории", -}: CardListProps) => { - const itemsArray = Object.values(items); +}: ListProps) => { + const { data: newsData, isLoading, isError } = useNews(); + + if (isLoading) + return ( +
+

Новости

+ +
+ ); + + if (isError) return
Ошибка при загрузке данных
; return ( -
-

{title}

-
- {itemsArray.map((item) => ( - - ))} -
+
+ {newsData && ( + + )}
); }; + +const LabsList = ({ + gridConfig = { desktop: 3, tablet: 2, mobile: 1 }, +}: ListProps) => { + const { data: postsData, isLoading, isError } = usePosts(); + const labs = postsData?.labs ? Object.values(postsData.labs) : []; + + if (isLoading) + return ( +
+

Лаборатории

+ +
+ ); + + if (isError) return
Ошибка при загрузке данных
; + + return ( +
+ +
+ ); +}; + +const ProjectsList = ({ + gridConfig = { desktop: 3, tablet: 2, mobile: 1 }, + tag = -1, +}: ListProps) => { + const { data, isError, isLoading } = usePostProjects(tag); + const projects = data ?? []; + + if (isLoading) + return ( +
+

Проекты

+ +
+ ); + + if (isError) return
Ошибка при загрузке данных
; + + return ( +
+ +
+ ); +}; + +export { NewsList, LabsList, ProjectsList }; diff --git a/src/pages/CardListPages/CardListFunctions.ts b/src/widgets/CardList/CardListFunctions.ts similarity index 93% rename from src/pages/CardListPages/CardListFunctions.ts rename to src/widgets/CardList/CardListFunctions.ts index a3be870..989c739 100644 --- a/src/pages/CardListPages/CardListFunctions.ts +++ b/src/widgets/CardList/CardListFunctions.ts @@ -1,4 +1,4 @@ -import { CardData } from "@/widgets/Card/types"; +import { CardData } from "@/shared/Components/Card/types"; import { App, SKBKit } from "@/shared/types/app"; export const transformPostsToCardData = ( posts: App.WpPost[] diff --git a/src/widgets/CardList/CardListTemplate.module.scss b/src/widgets/CardList/CardListTemplate.module.scss new file mode 100644 index 0000000..9e7b4b0 --- /dev/null +++ b/src/widgets/CardList/CardListTemplate.module.scss @@ -0,0 +1,48 @@ +.title { + font-size: 36px; + font-weight: 600; + line-height: 44px; + margin-top: 0; + margin-bottom: 8px; + @include mediaMax($tablet-max-width) { + font-size: 24px; + margin-top: 0; + } +} +.list { + display: grid; + gap: 2rem; + width: 100%; + max-width: 100%; + box-sizing: border-box; + margin-bottom: 32px; + &__lab { + grid-template-columns: repeat(var(--desktop-columns, 3), 1fr); + @include mediaMax($desktop-small-width) { + grid-template-columns: repeat(var(--tablet-columns, 3), 1fr); + } + @include mediaMax($tablet-max-width) { + grid-template-columns: repeat(var(--mobile-columns, 3), 1fr); + } + } + + &__news { + grid-template-columns: repeat(var(--desktop-columns, 3), 1fr); + @include mediaMax($desktop-small-width) { + grid-template-columns: repeat(var(--tablet-columns, 3), 1fr); + } + @include mediaMax($tablet-max-width) { + grid-template-columns: repeat(var(--mobile-columns, 3), 1fr); + } + } + + &__project { + grid-template-columns: repeat(var(--desktop-columns, 3), 1fr); + @include mediaMax($desktop-small-width) { + grid-template-columns: repeat(var(--tablet-columns, 3), 1fr); + } + @include mediaMax($tablet-max-width) { + grid-template-columns: repeat(var(--mobile-columns, 3), 1fr); + } + } +} diff --git a/src/widgets/CardList/CardListTemplate.tsx b/src/widgets/CardList/CardListTemplate.tsx new file mode 100644 index 0000000..034892d --- /dev/null +++ b/src/widgets/CardList/CardListTemplate.tsx @@ -0,0 +1,38 @@ +// widgets/CardList/CardList.tsx +import { CardListProps } from "@/widgets/CardList/types"; +import styles from "./CardListTemplate.module.scss"; +import { Card } from "@/shared/Components/Card/Card"; +import { classNames } from "@/shared/lib/classNames/classNames"; + +export const CardListTemplate = ({ + items, + variant = "lab", // Значение по умолчанию + gridConfig = { desktop: 3, tablet: 2, mobile: 1 }, + title = "Лаборатории", +}: CardListProps) => { + const itemsArray = Object.values(items); + + return ( + <> + {itemsArray?.length !== 0 && +
+

{title}

+
+ {itemsArray.map((item) => ( + + ))} +
+
+ } + + ); +};