Skip to content

Commit

Permalink
feat: on stacks created show starts in X minutes our X hours (#116)
Browse files Browse the repository at this point in the history
* feat: on stacks created show starts in X minutes our X hours if is less then 24h away.

* fix: convert pluralize to arrow function

* update: replace logic with formatDistanceToNow from date-fns
  • Loading branch information
Diogomartf authored and berteotti committed Nov 9, 2023
1 parent 0016c7c commit 66c3b02
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions packages/app/components/StacksTable.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use client";

import { PropsWithChildren, useState } from "react";
import { formatDistanceToNow } from "date-fns";
import {
BodyText,
Button,
Expand All @@ -20,10 +21,7 @@ import {
orderPairSymbolsText,
totalOrderSlotsDone,
} from "@/models/order";
import {
formatTimestampToDate,
formatTimestampToDateWithSuffix,
} from "@/utils/datetime";
import { formatTimestampToDate } from "@/utils/datetime";
import {
StackOrder,
StackOrderProps,
Expand Down Expand Up @@ -154,23 +152,32 @@ const CellWrapper = ({ children }: PropsWithChildren) => (
);

const OrdersProgressText = ({ stackOrder }: StackOrderProps) => {
if (stackOrder.cancelledAt)
if (stackOrder.cancelledAt) {
return (
<BodyText className="text-em-low">
Cancelled at {formatTimestampToDate(stackOrder.cancelledAt)}
</BodyText>
);
}

if (totalOrderSlotsDone(stackOrder) !== 0) {
return (
<>
<BodyText className="text-em-high">
{totalStackOrdersDone(stackOrder).toString()}
</BodyText>
<BodyText className="text-em-low">{`/ ${stackOrder.orderSlots.length} orders`}</BodyText>
</>
);
}

return totalOrderSlotsDone(stackOrder) === 0 ? (
const firtTimeSlot = Number(stackOrder.orderSlots[0]);
const date = new Date(firtTimeSlot * 1000); // Convert seconds to milliseconds
const distanceToNow = formatDistanceToNow(date, { addSuffix: true });

return (
<BodyText className="text-primary-700">
Starts on {formatTimestampToDateWithSuffix(stackOrder.orderSlots[0])}
{`Starts ${distanceToNow}`}
</BodyText>
) : (
<>
<BodyText className="text-em-high">
{totalStackOrdersDone(stackOrder).toString()}
</BodyText>
<BodyText className="text-em-low">{`/ ${stackOrder.orderSlots.length} orders`}</BodyText>
</>
);
};

0 comments on commit 66c3b02

Please sign in to comment.