|
1 | 1 | import { Card, CustomTimeline, _TimelineItem1 } from "@kleros/ui-components-library";
|
2 |
| -import React from "react"; |
| 2 | +import React, { useMemo } from "react"; |
3 | 3 | import styled, { css, Theme, useTheme } from "styled-components";
|
4 | 4 | import Header from "./Header";
|
5 | 5 | import { useItemRequests } from "queries/useRequestsQuery";
|
@@ -34,25 +34,41 @@ const StyledTimeline = styled(CustomTimeline)`
|
34 | 34 | }
|
35 | 35 | `;
|
36 | 36 |
|
| 37 | +const StyledLabel = styled.label` |
| 38 | + align-self: center; |
| 39 | + padding-bottom: 32px; |
| 40 | +`; |
| 41 | + |
37 | 42 | interface IHistory {
|
38 | 43 | itemId: string;
|
39 | 44 | isItem?: boolean;
|
40 | 45 | }
|
41 | 46 |
|
42 | 47 | const History: React.FC<IHistory> = ({ itemId, isItem }) => {
|
43 | 48 | const theme = useTheme();
|
44 |
| - const { data } = useItemRequests(itemId); |
| 49 | + const { data, isLoading } = useItemRequests(itemId); |
| 50 | + |
| 51 | + const items = useMemo( |
| 52 | + () => |
| 53 | + data?.requests.reduce<_TimelineItem1[]>((acc, request) => { |
| 54 | + const history = constructItemsFromRequest(request, theme, isItem); |
| 55 | + acc.push(...history); |
| 56 | + return acc; |
| 57 | + }, []), |
| 58 | + [data] |
| 59 | + ); |
| 60 | + |
| 61 | + const Component = useMemo(() => { |
| 62 | + if (!items || isLoading) return <HistorySkeletonCard />; |
| 63 | + else if (items.length === 0) return <StyledLabel>No requests yet.</StyledLabel>; |
45 | 64 |
|
46 |
| - const items = data?.requests.reduce<_TimelineItem1[]>((acc, request) => { |
47 |
| - const history = constructItemsFromRequest(request, theme, isItem); |
48 |
| - acc.push(...history); |
49 |
| - return acc; |
50 |
| - }, []); |
| 65 | + return <StyledTimeline {...{ items }} />; |
| 66 | + }, [items, isLoading]); |
51 | 67 |
|
52 | 68 | return (
|
53 | 69 | <Container>
|
54 | 70 | <Header />
|
55 |
| - {items ? <StyledTimeline {...{ items }} /> : <HistorySkeletonCard />} |
| 71 | + {Component} |
56 | 72 | </Container>
|
57 | 73 | );
|
58 | 74 | };
|
|
0 commit comments