Skip to content

Commit

Permalink
Merge pull request #58 from kleros/fix/direct-operation-history
Browse files Browse the repository at this point in the history
fix(web): fix-history-view-for-direct-operations
  • Loading branch information
Harman-singh-waraich authored Sep 11, 2024
2 parents f281f00 + 9dfe549 commit 94a4e79
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions web/src/components/HistoryDisplay/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Card, CustomTimeline, _TimelineItem1 } from "@kleros/ui-components-library";
import React from "react";
import React, { useMemo } from "react";
import styled, { css, Theme, useTheme } from "styled-components";
import Header from "./Header";
import { useItemRequests } from "queries/useRequestsQuery";
Expand Down Expand Up @@ -34,25 +34,41 @@ const StyledTimeline = styled(CustomTimeline)`
}
`;

const StyledLabel = styled.label`
align-self: center;
padding-bottom: 32px;
`;

interface IHistory {
itemId: string;
isItem?: boolean;
}

const History: React.FC<IHistory> = ({ itemId, isItem }) => {
const theme = useTheme();
const { data } = useItemRequests(itemId);
const { data, isLoading } = useItemRequests(itemId);

const items = useMemo(
() =>
data?.requests.reduce<_TimelineItem1[]>((acc, request) => {
const history = constructItemsFromRequest(request, theme, isItem);
acc.push(...history);
return acc;
}, []),
[data]
);

const Component = useMemo(() => {
if (!items || isLoading) return <HistorySkeletonCard />;
else if (items.length === 0) return <StyledLabel>No requests yet.</StyledLabel>;

const items = data?.requests.reduce<_TimelineItem1[]>((acc, request) => {
const history = constructItemsFromRequest(request, theme, isItem);
acc.push(...history);
return acc;
}, []);
return <StyledTimeline {...{ items }} />;
}, [items, isLoading]);

return (
<Container>
<Header />
{items ? <StyledTimeline {...{ items }} /> : <HistorySkeletonCard />}
{Component}
</Container>
);
};
Expand Down

0 comments on commit 94a4e79

Please sign in to comment.