Skip to content

Commit

Permalink
fix(deploy-web): fix provider uptime sorting during ssr
Browse files Browse the repository at this point in the history
  • Loading branch information
Redm4x committed Jun 3, 2024
1 parent 62acb44 commit 8aeda90
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions apps/deploy-web/src/components/providers/ProviderDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const ProviderDetail: React.FunctionComponent<Props> = ({ owner, _provide
function groupUptimeChecksByPeriod(uptimeChecks: { isOnline: boolean; checkDate: string }[] = []) {
const groupedSnapshots: { checkDate: Date; checks: boolean[] }[] = [];

const sortedUptimeChecks = uptimeChecks.toSorted((a, b) => new Date(a.checkDate).getTime() - new Date(b.checkDate).getTime());
const sortedUptimeChecks = [...uptimeChecks].sort((a, b) => new Date(a.checkDate).getTime() - new Date(b.checkDate).getTime());

for (const snapshot of sortedUptimeChecks) {
const recentGroup = groupedSnapshots.find(x => differenceInMinutes(new Date(snapshot.checkDate), x.checkDate) < 15);
Expand All @@ -101,7 +101,7 @@ export const ProviderDetail: React.FunctionComponent<Props> = ({ owner, _provide
}

const uptimePeriods = useMemo(() => groupUptimeChecksByPeriod(provider?.uptime || []), [provider?.uptime]);
const wasRecentlyOnline = provider && (provider.isOnline || (provider.lastCheckDate && new Date(provider.lastCheckDate) >= sub(new Date(), { hours: 24 })));
const wasRecentlyOnline = provider && (provider.isOnline || (provider.lastOnlineDate && new Date(provider.lastOnlineDate) >= sub(new Date(), { hours: 24 })));

return (
<Layout isLoading={isLoading}>
Expand All @@ -114,7 +114,7 @@ export const ProviderDetail: React.FunctionComponent<Props> = ({ owner, _provide
</div>
)}

{provider && !wasRecentlyOnline && !isLoading && (
{provider && !wasRecentlyOnline && !isLoadingProvider && (
<Alert variant="warning" className="flex items-center justify-center p-8 text-lg">
This provider is inactive.
</Alert>
Expand All @@ -141,7 +141,7 @@ export const ProviderDetail: React.FunctionComponent<Props> = ({ owner, _provide

<p className="mb-4">Up time (24h)</p>
<div className="mb-8 flex items-center space-x-1">
{uptimePeriods.map((x, i) => (
{uptimePeriods.map(x => (
<CustomNoDivTooltip
key={x.date.toISOString()}
title={<FormattedDate value={x.date} year="numeric" month="2-digit" day="2-digit" hour="2-digit" minute="2-digit" />}
Expand Down

0 comments on commit 8aeda90

Please sign in to comment.