Skip to content

Commit 767a427

Browse files
committed
fix(web): correct skeleton width for disputecard and disputelistitems
1 parent 5d2d3a9 commit 767a427

File tree

3 files changed

+39
-11
lines changed

3 files changed

+39
-11
lines changed

web/src/components/CasesDisplay/CasesGrid.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useMemo } from "react";
22
import styled from "styled-components";
33
import { useWindowSize } from "react-use";
44
import { useParams } from "react-router-dom";
5-
import Skeleton from "react-loading-skeleton";
5+
import { SkeletonDisputeCard, SkeletonDisputeListItem } from "../StyledSkeleton";
66
import { StandardPagination } from "@kleros/ui-components-library";
77
import { BREAKPOINT_LANDSCAPE } from "styles/landscapeStyle";
88
import { useIsList } from "context/IsListProvider";
@@ -27,11 +27,6 @@ const ListContainer = styled.div`
2727
gap: 8px;
2828
`;
2929

30-
const StyledSkeleton = styled(Skeleton)`
31-
height: 260px;
32-
width: 310px;
33-
`;
34-
3530
// 24px as margin-top since we already have 8px from the flex gap
3631
const StyledPagination = styled(StandardPagination)`
3732
margin-top: 24px;
@@ -61,15 +56,15 @@ const CasesGrid: React.FC<ICasesGrid> = ({ disputes, casesPerPage, totalPages, c
6156
<ListContainer>
6257
<CasesListHeader />
6358
{isUndefined(disputes)
64-
? [...Array(casesPerPage)].map((_, i) => <StyledSkeleton key={i} />)
59+
? [...Array(casesPerPage)].map((_, i) => <SkeletonDisputeListItem key={i} />)
6560
: disputes.map((dispute) => {
6661
return <DisputeCard key={dispute.id} {...dispute} />;
6762
})}
6863
</ListContainer>
6964
) : (
7065
<GridContainer>
7166
{isUndefined(disputes)
72-
? [...Array(casesPerPage)].map((_, i) => <StyledSkeleton key={i} />)
67+
? [...Array(casesPerPage)].map((_, i) => <SkeletonDisputeCard key={i} />)
7368
: disputes.map((dispute) => {
7469
return <DisputeCard key={dispute.id} {...dispute} overrideIsList />;
7570
})}

web/src/components/LatestCases.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import styled from "styled-components";
33
import { Dispute_Filter } from "../graphql/graphql";
44
import { DisputeDetailsFragment, useCasesQuery } from "queries/useCasesQuery";
55
import DisputeCard from "components/DisputeCard";
6-
import { StyledSkeleton } from "components/StyledSkeleton";
6+
import { SkeletonDisputeCard } from "components/StyledSkeleton";
77
import { isUndefined } from "utils/index";
88

99
const Container = styled.div`
@@ -30,7 +30,7 @@ const LatestCases: React.FC<{ filters?: Dispute_Filter }> = ({ filters }) => {
3030
<Title>Latest Cases</Title>
3131
<DisputeContainer>
3232
{isUndefined(disputes)
33-
? Array.from({ length: 3 }).map((_, index) => <StyledSkeleton key={index} width={312} height={260} />)
33+
? Array.from({ length: 3 }).map((_, index) => <SkeletonDisputeCard key={index} />)
3434
: disputes.map((dispute) => <DisputeCard key={dispute.id} {...dispute} overrideIsList />)}
3535
</DisputeContainer>
3636
</Container>
Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,39 @@
1-
import styled from "styled-components";
1+
import React from "react";
2+
import styled, { css } from "styled-components";
3+
import { landscapeStyle } from "styles/landscapeStyle";
24
import Skeleton from "react-loading-skeleton";
35

46
export const StyledSkeleton = styled(Skeleton)`
57
z-index: 0;
68
`;
9+
10+
const SkeletonDisputeCardContainer = styled.div`
11+
width: 100%;
12+
${landscapeStyle(
13+
() =>
14+
css`
15+
/* Explanation of this formula:
16+
- The 48px accounts for the total width of gaps: 2 gaps * 24px each.
17+
- The 0.333 is used to equally distribute width among 3 cards per row.
18+
- The 294px ensures the card has a minimum width.
19+
*/
20+
width: max(calc((100% - 48px) * 0.333), 294px);
21+
`
22+
)}
23+
`;
24+
25+
const StyledSkeletonDisputeCard = styled(Skeleton)`
26+
height: 260px;
27+
`;
28+
29+
const StyledSkeletonDisputeListItem = styled(Skeleton)`
30+
height: 62px;
31+
`;
32+
33+
export const SkeletonDisputeCard = () => (
34+
<SkeletonDisputeCardContainer>
35+
<StyledSkeletonDisputeCard />
36+
</SkeletonDisputeCardContainer>
37+
);
38+
39+
export const SkeletonDisputeListItem = () => <StyledSkeletonDisputeListItem />;

0 commit comments

Comments
 (0)