diff --git a/web/src/components/HistoryDisplay/index.tsx b/web/src/components/HistoryDisplay/index.tsx index ca5ed6a..9efd6ed 100644 --- a/web/src/components/HistoryDisplay/index.tsx +++ b/web/src/components/HistoryDisplay/index.tsx @@ -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"; @@ -34,6 +34,11 @@ const StyledTimeline = styled(CustomTimeline)` } `; +const StyledLabel = styled.label` + align-self: center; + padding-bottom: 32px; +`; + interface IHistory { itemId: string; isItem?: boolean; @@ -41,18 +46,29 @@ interface IHistory { const History: React.FC = ({ 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 ; + else if (items.length === 0) return No requests yet.; - const items = data?.requests.reduce<_TimelineItem1[]>((acc, request) => { - const history = constructItemsFromRequest(request, theme, isItem); - acc.push(...history); - return acc; - }, []); + return ; + }, [items, isLoading]); return (
- {items ? : } + {Component} ); };