Skip to content

Commit

Permalink
Add timestamp zone toggle to Explorer (#22616)
Browse files Browse the repository at this point in the history
* Add timestamp zone toggle to Explorer

* style: code formatting
  • Loading branch information
radupasparuga authored Jan 22, 2022
1 parent d6011ba commit 88bf3c7
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
48 changes: 48 additions & 0 deletions explorer/src/components/common/TimestampToggle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { useState } from "react";
import { displayTimestampUtc, displayTimestamp } from "utils/date";

type State = "hide" | "show";

function Tooltip({ state }: { state: State }) {
const tooltip = {
maxWidth: "20rem",
};

if (state === "hide") return null;
return (
<div className="popover bs-popover-bottom show" style={tooltip}>
<div className="arrow" />
<div className="popover-body">
(Click to toggle between local and UTC)
</div>
</div>
);
}

export function TimestampToggle({ unixTimestamp }: { unixTimestamp: number }) {
const [isTimestampTypeUtc, toggleTimestampType] = useState(true);
const [showTooltip, toggleTooltip] = useState<State>("hide");

const toggle = () => {
toggleTimestampType(!isTimestampTypeUtc);
};

const tooltipContainer = {
cursor: "pointer",
};

return (
<div className="popover-container w-100" style={tooltipContainer}>
<span
onClick={toggle}
onMouseOver={() => toggleTooltip("show")}
onMouseOut={() => toggleTooltip("hide")}
>
{isTimestampTypeUtc === true
? displayTimestampUtc(unixTimestamp)
: displayTimestamp(unixTimestamp)}
</span>
<Tooltip state={showTooltip} />
</div>
);
}
5 changes: 3 additions & 2 deletions explorer/src/pages/ClusterStatsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import {
import { abbreviatedNumber, lamportsToSol, slotsToHumanString } from "utils";
import { ClusterStatus, useCluster } from "providers/cluster";
import { TpsCard } from "components/TpsCard";
import { displayTimestampWithoutDate, displayTimestampUtc } from "utils/date";
import { displayTimestampWithoutDate } from "utils/date";
import { Status, useFetchSupply, useSupply } from "providers/supply";
import { ErrorCard } from "components/common/ErrorCard";
import { LoadingCard } from "components/common/LoadingCard";
import { useVoteAccounts } from "providers/accounts/vote-accounts";
import { CoingeckoStatus, useCoinGecko } from "utils/coingecko";
import { Epoch } from "components/common/Epoch";
import { TimestampToggle } from "components/common/TimestampToggle";

const CLUSTER_STATS_TIMEOUT = 5000;

Expand Down Expand Up @@ -253,7 +254,7 @@ function StatsCardBody() {
<tr>
<td className="w-100">Cluster time</td>
<td className="text-lg-end font-monospace">
{displayTimestampUtc(blockTime)}
<TimestampToggle unixTimestamp={blockTime}></TimestampToggle>
</td>
</tr>
)}
Expand Down

1 comment on commit 88bf3c7

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for explorer ready!

✅ Preview
https://explorer-rl39uqx4w-solana-labs.vercel.app

Built with commit 88bf3c7.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.