Skip to content

Commit

Permalink
updated the TimeAgo component
Browse files Browse the repository at this point in the history
  • Loading branch information
radumojic committed Nov 6, 2023
1 parent 346974d commit f8edb61
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
14 changes: 11 additions & 3 deletions src/components/TimeAgo/TimeAgo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import { timeAgo } from './helpers/timeAgo';
export const TimeAgo = ({
value,
short = false,
tooltip = false
tooltip = false,
showAgo = false
}: {
value: number;
short?: boolean;
tooltip?: boolean;
showAgo?: boolean;
}) => {
const ms = value * 1000;
let result = timeAgo(ms);
Expand All @@ -31,9 +33,15 @@ export const TimeAgo = ({
</Tooltip>
)}
>
<span>{result}</span>
<span>
{result}
{showAgo ? ' ago' : ''}
</span>
</OverlayTrigger>
) : (
<>{result}</>
<>
{result}
{showAgo ? ' ago' : ''}
</>
);
};
10 changes: 4 additions & 6 deletions src/components/TimeAgo/helpers/timeAgo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ export function dhms(ms: number) {
const minsms = hrsms % (60 * 1000);
const secs = Math.floor(minsms / 1000);

// let diff = ' ago';
const diff = '';
let secsString = secs + ' sec';
let minsString = mins + ' min';
let hrsString = hrs + ' hr';
Expand All @@ -21,17 +19,17 @@ export function dhms(ms: number) {
if (hrs > 1) hrsString = hrs + ' hrs';
if (days > 1) daysString = days + ' days';

if (days >= 1) return daysString + ' ' + hrsString + diff;
if (days >= 1) return daysString + ' ' + hrsString;
if (hrs >= 1) {
const minutesString = mins === 0 ? '' : ' ' + minsString + diff;
const minutesString = mins === 0 ? '' : ' ' + minsString;
return hrsString + minutesString;
}
if (mins >= 1) {
const secString = secs === 0 ? '' : ' ' + secsString + diff;
const secString = secs === 0 ? '' : ' ' + secsString;
return minsString + secString;
}

return secsString + diff;
return secsString;
}

export const timeAgo = (timestamp: number) => {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/AccountDetails/AccountContracts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export const AccountContracts = () => {
</div>
</td>
<td>
<TimeAgo value={contract.timestamp} tooltip /> ago
<TimeAgo value={contract.timestamp} tooltip showAgo />
&nbsp;
</td>
<td>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/AccountDetails/AccountUpgrades.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export const AccountUpgrades = () => {
</div>
</td>
<td>
<TimeAgo value={upgrade.timestamp} tooltip /> ago
<TimeAgo value={upgrade.timestamp} tooltip showAgo />
&nbsp;
</td>
<td>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Home/components/LatestBlocks/LatestBlocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export const LatestBlocks = () => {
</div>

<span className='text-neutral-400'>
<TimeAgo value={block.timestamp} /> ago
<TimeAgo value={block.timestamp} showAgo />
</span>
</div>
<div className='d-flex'>
Expand Down

0 comments on commit f8edb61

Please sign in to comment.