Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(deploy-web): fix provider uptime sorting during ssr #214

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading