Skip to content

Commit cea5d0c

Browse files
committed
refactor: finish RegistryDetails and related components migration
1 parent 81b91e2 commit cea5d0c

File tree

4 files changed

+59
-114
lines changed

4 files changed

+59
-114
lines changed

web/src/components/HistoryDisplay/index.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ interface IHistory {
1616
isItem?: boolean;
1717
}
1818

19-
type TimelineItems = React.ComponentProps<typeof CustomTimeline>["items"];
19+
type TimelineItem = React.ComponentProps<typeof CustomTimeline>["items"][number];
2020

2121
const History: React.FC<IHistory> = ({ itemId, isItem }) => {
2222
const { data, isLoading } = useItemRequests(itemId);
@@ -25,7 +25,7 @@ const History: React.FC<IHistory> = ({ itemId, isItem }) => {
2525

2626
const items = useMemo(
2727
() =>
28-
data?.requests.reduce<TimelineItems>((acc, request) => {
28+
data?.requests.reduce<TimelineItem[]>((acc, request) => {
2929
const history = constructItemsFromRequest(request, isLightTheme, isItem);
3030
acc.push(...history);
3131
return acc;
@@ -57,8 +57,8 @@ const constructItemsFromRequest = (
5757
request: RequestDetailsFragment,
5858
isLightTheme: boolean,
5959
isItem?: boolean
60-
): TimelineItems => {
61-
const historyItems: TimelineItems = [];
60+
): TimelineItem => {
61+
const historyItems: TimelineItem[] = [];
6262

6363
if (request.requestType === Status.RegistrationRequested) {
6464
historyItems.push({
@@ -121,6 +121,7 @@ const constructItemsFromRequest = (
121121
});
122122
}
123123
}
124+
124125
return historyItems;
125126
};
126127

web/src/components/ItemCard/index.tsx

Lines changed: 39 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,18 @@
11
import React from "react";
2-
import styled, { css } from "styled-components";
32
import { Button, Card } from "@kleros/ui-components-library";
4-
import { landscapeStyle } from "styles/landscapeStyle";
53
import { useNavigateAndScrollTop } from "hooks/useNavigateAndScrollTop";
64
import { responsiveSize } from "styles/responsiveSize";
75
import StatusBanner, { mapFromSubgraphStatus } from "../RegistryCard/StatusBanner";
86
import ArrowIcon from "svgs/icons/arrow.svg";
97
import { ItemDetailsFragment } from "src/graphql/graphql";
108
import ItemField from "./ItemField";
9+
import { cn } from "~src/utils";
10+
import clsx from "clsx";
1111

12-
const StyledListItem = styled(Card)`
13-
display: flex;
14-
flex-grow: 1;
15-
width: 100%;
16-
height: max-content;
17-
${landscapeStyle(
18-
() => css`
19-
height: 64px;
20-
`
21-
)}
22-
`;
12+
const landscapeGridColsCalc =
13+
"lg:grid-cols-[1fr_calc(150px+(180-150)*(min(max(100vw,900px),1250px)-900px)/(1250-900))_max-content]";
14+
const landscapeGapCalc = "lg:gap-[calc(16px+(36-16)*(min(max(100vw,900px),1250px)-900px)/(1250-900))]";
2315

24-
const Container = styled.div`
25-
width: 100%;
26-
height: max-content;
27-
align-items: center;
28-
display: grid;
29-
grid-template-rows: repeat(3, min-content);
30-
grid-template-columns: 1fr min-content;
31-
column-gap: ${responsiveSize(12, 32, 900)};
32-
row-gap: 8px;
33-
padding: 16px;
34-
${landscapeStyle(
35-
() => css`
36-
height: 64px;
37-
justify-content: space-between;
38-
grid-template-rows: 1fr;
39-
grid-template-columns: 1fr ${responsiveSize(150, 180, 900)} max-content;
40-
padding: 0 32px;
41-
`
42-
)}
43-
`;
44-
45-
const StyledButton = styled(Button)`
46-
background-color: transparent;
47-
padding: 0;
48-
flex-direction: row-reverse;
49-
gap: 8px;
50-
.button-text {
51-
color: ${({ theme }) => theme.primaryBlue};
52-
font-weight: 400;
53-
}
54-
55-
:focus,
56-
:hover {
57-
background-color: transparent;
58-
}
59-
`;
60-
61-
const FieldsContainer = styled.div`
62-
display: flex;
63-
flex-direction: column;
64-
justify-content: space-between;
65-
align-items: start;
66-
width: fit-content;
67-
gap: 16px;
68-
grid-column: span 2;
69-
${landscapeStyle(
70-
() => css`
71-
flex-direction: row;
72-
align-items: center;
73-
grid-column: span 1;
74-
gap: ${responsiveSize(16, 36, 900)};
75-
`
76-
)}
77-
`;
7816
interface IItemCard extends ItemDetailsFragment {}
7917

8018
const ItemCard: React.FC<IItemCard> = ({ id, status, disputed, props }) => {
@@ -84,13 +22,41 @@ const ItemCard: React.FC<IItemCard> = ({ id, status, disputed, props }) => {
8422
const sortedProps = sortItemProps(props);
8523

8624
return (
87-
<StyledListItem hover onClick={() => navigateAndScrollTop(`/lists/item/${id?.toString()}`)}>
88-
<Container>
89-
<FieldsContainer>{sortedProps.map((prop) => prop.isIdentifier && <ItemField {...prop} />)}</FieldsContainer>
25+
<Card
26+
className="flex grow w-full h-max lg:h-16"
27+
hover
28+
onClick={() => navigateAndScrollTop(`/lists/item/${id?.toString()}`)}
29+
>
30+
<div
31+
className={cn(
32+
"grid grid-rows-[repeat(3,)min-content] grid-cols-[1fr_min-content]",
33+
"w-full h-max p-4 gap-y-2 items-center",
34+
"lg:h-16 lg:justify-between lg:grid-rows-[1fr] lg:py-0 lg:px-8",
35+
landscapeGridColsCalc
36+
)}
37+
style={{ columnGap: responsiveSize(12, 32, 900) }}
38+
>
39+
<div
40+
className={cn(
41+
"flex flex-col justify-between items-start gap-4 w-fit col-span-2",
42+
"lg:flex-row lg:items-center lg:col-span-1",
43+
landscapeGapCalc
44+
)}
45+
>
46+
{sortedProps.map((prop) => prop.isIdentifier && <ItemField {...prop} />)}
47+
</div>
9048
<StatusBanner {...{ status: mapFromSubgraphStatus(status, disputed) }} isListView />
91-
<StyledButton text="Open" Icon={ArrowIcon} />
92-
</Container>
93-
</StyledListItem>
49+
<Button
50+
className={clsx(
51+
"bg-transparent p-0 flex-row-reverse gap-2",
52+
"[&_.button-text]:text-klerosUIComponentsPrimaryBlue [&_.button-text]:font-normal",
53+
"focus:bg-transparent hover:bg-transparent"
54+
)}
55+
text="Open"
56+
Icon={ArrowIcon}
57+
/>
58+
</div>
59+
</Card>
9460
);
9561
};
9662

web/src/pages/AllLists/RegistryDetails/ItemsDownloadLabel.tsx

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,8 @@
11
import React, { useEffect, useRef, useState } from "react";
2-
import styled from "styled-components";
32
import { useRegistryItemsQuery } from "queries/useRegistryAllItemsQuery";
43
import { json2csv } from "json-2-csv";
54
import ExportIcon from "svgs/icons/export.svg";
6-
7-
const StyledLink = styled.a`
8-
display: flex;
9-
flex-direction: row;
10-
align-items: end;
11-
gap: 8px;
12-
text-decoration: none;
13-
color: ${({ theme }) => theme.primaryBlue};
14-
margin-top: 48px;
15-
align-self: flex-end;
16-
cursor: pointer;
17-
`;
18-
19-
const StyledExportIcon = styled(ExportIcon)`
20-
path {
21-
stroke: ${({ theme }) => theme.primaryBlue};
22-
}
23-
`;
5+
import clsx from "clsx";
246

257
const ItemsDownloadLabel: React.FC<{ registryAddress?: string }> = ({ registryAddress }) => {
268
const [isPreparing, setIsPreparing] = useState(false);
@@ -60,15 +42,23 @@ const ItemsDownloadLabel: React.FC<{ registryAddress?: string }> = ({ registryAd
6042
}, [items]);
6143

6244
return (
63-
<StyledLink onClick={() => refetch()} aria-disabled={isRefetching} ref={ref}>
45+
<a
46+
className={clsx(
47+
"flex flex-row items-end self-end gap-2 mt-12",
48+
"no-underline text-klerosUIComponentsPrimaryBlue cursor-pointer"
49+
)}
50+
onClick={() => refetch()}
51+
aria-disabled={isRefetching}
52+
ref={ref}
53+
>
6454
{isRefetching || isPreparing ? (
6555
<>Exporting list...</>
6656
) : (
6757
<>
68-
Export as csv <StyledExportIcon />
58+
Export as csv <ExportIcon className="stroke-klerosUIComponentsPrimaryBlue" />
6959
</>
7060
)}
71-
</StyledLink>
61+
</a>
7262
);
7363
};
7464

web/src/pages/AllLists/RegistryDetails/List/index.tsx

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { useMemo } from "react";
2-
import styled from "styled-components";
32
import Skeleton from "react-loading-skeleton";
43
import StatsAndFilters from "components/StatsAndFilters";
54
import ItemCard from "components/ItemCard";
@@ -11,17 +10,6 @@ import { useRegistryDetailsQuery } from "hooks/queries/useRegistryDetailsQuery";
1110
import { List_filters } from "consts/filters";
1211
import { Address } from "viem";
1312

14-
const ListContainer = styled.div`
15-
display: flex;
16-
flex-direction: column;
17-
justify-content: center;
18-
gap: 8px;
19-
`;
20-
21-
const SkeletonItemCard = styled(Skeleton)`
22-
height: 64px;
23-
`;
24-
2513
interface IList {
2614
registryAddress: Address;
2715
}
@@ -68,11 +56,11 @@ const List: React.FC<IList> = ({ registryAddress }) => {
6856
<>
6957
<Search />
7058
<StatsAndFilters fields={[{ label: "Items", value: totalItems?.toString() }]} />
71-
<ListContainer>
59+
<div className="flex flex-col gap-2 justify-center">
7260
{registryDetails?.registry?.items
7361
? registryDetails?.registry.items.map((item) => <ItemCard key={item.id} {...(item as ItemDetailsFragment)} />)
74-
: Array.from({ length: 3 }).map((_, index) => <SkeletonItemCard key={index} />)}
75-
</ListContainer>
62+
: Array.from({ length: 3 }).map((_, index) => <Skeleton height={64} key={index} />)}
63+
</div>
7664
</>
7765
);
7866
};

0 commit comments

Comments
 (0)