mirror of
https://git.rdcenter.ru/RDCenter/skb-kit.git
synced 2026-12-05 03:39:45 +00:00
Вынес шимер в общий компонент, добавил компонент WithLoading
This commit is contained in:
1 parent
f2f6e453a1
commit
b466ddfc81
10 files changed
+215
-111
No files matched your search
@@ -1,33 +1,12 @@
|
||||
.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;
|
||||
}
|
||||
}
|
||||
|
||||
.skeletonGrid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
gap: 32px;
|
||||
width: 100%;
|
||||
margin: 0 auto;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
grid-template-columns: repeat(1, 1fr);
|
||||
}
|
||||
|
||||
@media (min-width: 769px) and (max-width: 1024px) {
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
// pages/MainPage/ui/MainPage/Lists.tsx
|
||||
import { CardListTemplate } from "@/widgets/CardList/CardListTemplate";
|
||||
import { WithLoading } from "@/shared/Components/WithLoading/WithLoading";
|
||||
import { GridConfig } from "@/widgets/CardList/types";
|
||||
import { usePosts } from "@/modules/posts/hooks/usePosts";
|
||||
import styles from "./CardList.module.scss";
|
||||
@@ -9,7 +10,6 @@ import {
|
||||
transformPostsToCardData,
|
||||
} from "@/widgets/CardList/CardListFunctions";
|
||||
import { usePostProjects } from "@/modules/posts/hooks/usePostProjects";
|
||||
import CardSkeleton from "./ui/CardSkeleton";
|
||||
|
||||
interface ListProps {
|
||||
gridConfig?: GridConfig;
|
||||
@@ -21,64 +21,48 @@ const NewsList = ({
|
||||
}: ListProps) => {
|
||||
const { data: newsData, isLoading, isError } = useNews();
|
||||
|
||||
if (isLoading)
|
||||
return (
|
||||
<div className="mainContainer">
|
||||
<h2 className={styles.title}>Новости</h2>
|
||||
<div className={styles.skeletonGrid }>
|
||||
{[...Array(3)].map((_, index) => (
|
||||
<CardSkeleton key={index} />
|
||||
))}
|
||||
</div>
|
||||
{/* <span className="loader"></span> анимация прогрузки */}
|
||||
</div>
|
||||
);
|
||||
|
||||
if (isError) return <center>Ошибка при загрузке данных</center>;
|
||||
|
||||
return (
|
||||
<div className={styles.mainContainer}>
|
||||
{newsData && (
|
||||
<CardListTemplate
|
||||
items={transformNewsToCardData(newsData)}
|
||||
variant="news"
|
||||
gridConfig={gridConfig}
|
||||
title="Новости"
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
<WithLoading
|
||||
isLoading={isLoading}
|
||||
isError={isError}
|
||||
count={4}
|
||||
gridConfig={gridConfig}
|
||||
>
|
||||
<div className={styles.mainContainer}>
|
||||
{newsData && (
|
||||
<CardListTemplate
|
||||
items={transformNewsToCardData(newsData)}
|
||||
variant="news"
|
||||
gridConfig={gridConfig}
|
||||
title="Новости"
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</WithLoading>
|
||||
);
|
||||
};
|
||||
// TODO: вынести array cardSkeleton Отдельно
|
||||
|
||||
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 (
|
||||
<div className="mainContainer">
|
||||
<h2 className={styles.title}>Лаборатории</h2>
|
||||
<div className={styles.skeletonGrid}>
|
||||
{[...Array(3)].map((_, index) => (
|
||||
<CardSkeleton key={index} variant="lab" />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
if (isError) return <div>Ошибка при загрузке данных</div>;
|
||||
|
||||
return (
|
||||
<div className={styles.mainContainer}>
|
||||
<CardListTemplate
|
||||
items={transformPostsToCardData(labs)}
|
||||
variant="lab"
|
||||
gridConfig={gridConfig}
|
||||
title="Наши лаборатории"
|
||||
/>
|
||||
</div>
|
||||
<WithLoading
|
||||
isLoading={isLoading}
|
||||
isError={isError}
|
||||
gridConfig={gridConfig}
|
||||
>
|
||||
<div className={styles.mainContainer}>
|
||||
<CardListTemplate
|
||||
items={transformPostsToCardData(labs)}
|
||||
variant="lab"
|
||||
gridConfig={gridConfig}
|
||||
title="Наши лаборатории"
|
||||
/>
|
||||
</div>
|
||||
</WithLoading>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -89,30 +73,22 @@ const ProjectsList = ({
|
||||
const { data, isError, isLoading } = usePostProjects(tag);
|
||||
const projects = data ?? [];
|
||||
|
||||
if (isLoading)
|
||||
return (
|
||||
<div className="mainContainer">
|
||||
<h2 className={styles.title}>Наши проекты</h2>
|
||||
<div className={styles.skeletonGrid}>
|
||||
{[...Array(3)].map((_, index) => (
|
||||
<CardSkeleton key={index} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
if (isError || !projects) return <div>Ошибка при загрузке данных</div>;
|
||||
|
||||
return (
|
||||
<div className={styles.mainContainer}>
|
||||
<CardListTemplate
|
||||
//@ts-ignore
|
||||
items={transformPostsToCardData(projects)}
|
||||
variant="project"
|
||||
gridConfig={gridConfig}
|
||||
title="Наши проекты"
|
||||
/>
|
||||
</div>
|
||||
<WithLoading
|
||||
isLoading={isLoading}
|
||||
isError={isError}
|
||||
gridConfig={gridConfig}
|
||||
>
|
||||
<div className={styles.mainContainer}>
|
||||
<CardListTemplate
|
||||
//@ts-ignore
|
||||
items={transformPostsToCardData(projects)}
|
||||
variant="project"
|
||||
gridConfig={gridConfig}
|
||||
title="Наши проекты"
|
||||
/>
|
||||
</div>
|
||||
</WithLoading>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,36 +1,40 @@
|
||||
@import "@/shared/styles/cardGrid.module.scss";
|
||||
|
||||
.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;
|
||||
@extend .gridСontainer;
|
||||
|
||||
&__lab {
|
||||
grid-template-columns: repeat(var(--desktop-columns, 3), 1fr);
|
||||
grid-template-columns: repeat(var(--desktop-columns), 1fr);
|
||||
|
||||
@include mediaMax($desktop-small-width) {
|
||||
grid-template-columns: repeat(var(--tablet-columns, 3), 1fr);
|
||||
grid-template-columns: repeat(var(--tablet-columns), 1fr);
|
||||
}
|
||||
|
||||
@include mediaMax($tablet-max-width) {
|
||||
grid-template-columns: repeat(var(--mobile-columns, 3), 1fr);
|
||||
grid-template-columns: repeat(var(--mobile-columns), 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);
|
||||
}
|
||||
@@ -38,11 +42,13 @@
|
||||
|
||||
&__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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
.card {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 250px;
|
||||
border-radius: 8px;
|
||||
background-color: #e0e0e0;
|
||||
overflow: hidden;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
height: 215px !important;
|
||||
}
|
||||
}
|
||||
|
||||
.pic {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border-radius: 8px;
|
||||
background-color: #ddd;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.shimmer {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: -150%;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: linear-gradient(90deg,
|
||||
rgba(255, 255, 255, 0) 0%,
|
||||
rgba(255, 255, 255, 0.6) 50%,
|
||||
rgba(255, 255, 255, 0) 100%);
|
||||
animation: shimmer 1.5s infinite;
|
||||
}
|
||||
|
||||
@keyframes shimmer {
|
||||
0% {
|
||||
left: -150%;
|
||||
}
|
||||
|
||||
100% {
|
||||
left: 150%;
|
||||
}
|
||||
}
|
||||
|
||||
.labsCard {
|
||||
height: 300px;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
height: 215px !important;
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
// shared/ui/CardSkeleton/CardSkeleton.tsx
|
||||
import styles from "./CardSkeleton.module.scss";
|
||||
|
||||
interface CardSkeletonProps {
|
||||
variant?: "default" | "lab";
|
||||
}
|
||||
|
||||
const CardSkeleton = ({ variant = "default" }: CardSkeletonProps) => {
|
||||
const cardClass =
|
||||
variant === "lab"
|
||||
? `${styles.card} ${styles.labsCard}`
|
||||
: styles.card;
|
||||
|
||||
return (
|
||||
<div className={cardClass}>
|
||||
<div className={styles.pic}>
|
||||
<div className={styles.shimmer}></div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default CardSkeleton;
|
||||
|
||||
Reference in new issue
Block a user