Skip to content

Commit

Permalink
perf: short website overview display
Browse files Browse the repository at this point in the history
  • Loading branch information
moonrailgun committed Oct 30, 2023
1 parent 58d5702 commit 503321d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 2 additions & 6 deletions src/client/components/website/MetricsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from 'react';
import { AppRouterOutput, trpc } from '../../api/trpc';
import { useCurrentWorkspaceId } from '../../store/user';
import { sum } from 'lodash-es';
import millify from 'millify';
import { formatNumber } from '../../utils/common';

type MetricsItemType = AppRouterOutput['website']['metrics'][number];

Expand Down Expand Up @@ -53,11 +53,7 @@ export const MetricsTable: React.FC<MetricsTableProps> = React.memo((props) => {

return (
<div className="flex">
<div className="w-12 text-right">
{millify(val, {
lowercase: true,
})}
</div>
<div className="w-12 text-right">{formatNumber(val)}</div>
<div className="inline-block w-12 relative border-l ml-1 px-1">
<div
className="bg-blue-300 absolute h-full bg-opacity-25 left-0 top-0 pointer-events-none"
Expand Down
8 changes: 6 additions & 2 deletions src/client/utils/common.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import millify from 'millify';

export function parseTime(val: number) {
const days = ~~(val / 86400);
const hours = ~~(val / 3600) - days * 24;
Expand All @@ -14,8 +16,10 @@ export function parseTime(val: number) {
};
}

export function formatNumber(n: number) {
return Number(n).toFixed(0);
export function formatNumber(n: number): string {
return millify(n, {
lowercase: true,
});
}

export function formatShortTime(val: number, formats = ['m', 's'], space = '') {
Expand Down

0 comments on commit 503321d

Please sign in to comment.