This repository has been archived by the owner on Feb 3, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
97af15e
commit cb367a0
Showing
8 changed files
with
170 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import React from 'react'; | ||
import { getPerfColorClass, getLCPColorClass, getFIDColorClass, getCLSColorClass } from '../utils/getColorClass'; | ||
|
||
const CardDetail = ({ data, title }): React.ReactElement => { | ||
return ( | ||
<div className="mt-4 p-4 bg-white shadow overflow-hidden rounded-lg"> | ||
<div className="flex justify-center space-between"> | ||
<div className="text-gray-600 my-2 mr-2"> | ||
<small className="text-sm font-bold">{title}</small> | ||
<div className={`text-5xl font-bold capitalize ${getPerfColorClass(data.perf)}`}> | ||
{(data.perf * 100).toFixed(0)} | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div className="flex justify-center space-between my-2"> | ||
<div className="w-20 my-2 mr-4 text-center"> | ||
<small className="text-sm text-blue-400 font-bold">LCP</small> | ||
<div className="text-center"> | ||
<span className={`text-3xl text-gray-600 font-bold capitalize ${getLCPColorClass(data.lcp)}`}> | ||
{(data.lcp / 1000).toFixed(2)} | ||
</span> | ||
<small className="text-lg font-bold text-gray-600 ml-1">s</small> | ||
</div> | ||
</div> | ||
<div className="w-20 my-2 mr-4 text-center"> | ||
<small className="text-sm text-blue-400 font-bold">FID</small> | ||
<div className="text-center"> | ||
<span className={`text-3xl text-gray-600 font-bold capitalize ${getFIDColorClass(data.fid)}`}> | ||
{data.fid.toFixed(0)} | ||
</span> | ||
<small className="text-lg font-bold text-gray-600 ml-1">ms</small> | ||
</div> | ||
</div> | ||
<div className="w-20 my-2 mr-4 text-center"> | ||
<small className="text-sm text-blue-400 font-bold">CLS</small> | ||
<div className={`text-3xl text-gray-600 font-bold capitalize ${getCLSColorClass(data.cls)}`}> | ||
{data.cls.toFixed(2)} | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div className="flex justify-center space-between my-2"> | ||
<div className="w-20 my-2 mr-4 text-center"> | ||
<small className="text-sm text-blue-400 font-bold">TBT</small> | ||
<div className="text-center"> | ||
<span className={`text-3xl text-gray-600 font-bold capitalize`}>{(data.tbt / 1000).toFixed(2)}</span> | ||
<small className="text-lg font-bold text-gray-600 ml-1">s</small> | ||
</div> | ||
</div> | ||
<div className="w-20 my-2 mr-4 text-center"> | ||
<small className="text-sm text-blue-400 font-bold">FCP</small> | ||
<div className="text-center"> | ||
<span className={`text-3xl text-gray-600 font-bold capitalize`}>{(data.fcp / 1000).toFixed(2)}</span> | ||
<small className="text-lg font-bold text-gray-600 ml-1">s</small> | ||
</div> | ||
</div> | ||
<div className="w-20 my-2 mr-4 text-center"> | ||
<small className="text-sm text-blue-400 font-bold">TTI</small> | ||
<div className="text-center"> | ||
<span className={`text-3xl text-gray-600 font-bold capitalize`}>{(data.tti / 1000).toFixed(2)}</span> | ||
<small className="text-lg font-bold text-gray-600 ml-1">s</small> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default CardDetail; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React from 'react'; | ||
import { GetStaticProps, GetStaticPaths } from 'next'; | ||
|
||
import Layout from '../components/Layout'; | ||
import CardDetail from '../components/CardDetail'; | ||
|
||
import reports from '../reports/output'; | ||
import dataEcommerce from '../constants/ecommerce'; | ||
import { EcommerceItem } from '../types'; | ||
|
||
const DetailPage = ({ data, lastUpdate }): React.ReactElement => { | ||
return ( | ||
<Layout> | ||
<h1 className="text-3xl font-bold capitalize">Web Performance: {data.n}</h1> | ||
<small className="text-gray-600 text-lg font-bold">Last update {lastUpdate}</small> | ||
|
||
<CardDetail data={data.d} title="Desktop" /> | ||
<CardDetail data={data.m} title="Mobile" /> | ||
</Layout> | ||
); | ||
}; | ||
|
||
export const getStaticPaths: GetStaticPaths = async () => { | ||
const paths = dataEcommerce.map((i: EcommerceItem) => `/${i.name.toLowerCase()}`); | ||
|
||
return { paths, fallback: false }; | ||
}; | ||
|
||
export const getStaticProps: GetStaticProps = async ({ params }) => { | ||
const id: string = params ? `${params.id}` : ''; | ||
|
||
const reportDates = Object.keys(reports) || []; | ||
const lastDate = reportDates[reportDates.length - 1] || ''; | ||
const lastReport = reports[lastDate] || []; | ||
const data = lastReport.length > 0 ? lastReport.find((item) => item.n.toLowerCase() === id.toLowerCase()) : {}; | ||
|
||
return { props: { data, lastUpdate: lastDate } }; | ||
}; | ||
|
||
export default DetailPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
export const getPerfColorClass = (value: number): string => { | ||
if (value <= 0.49) { | ||
return 'text-red-600'; | ||
} | ||
if (value <= 0.89) { | ||
return 'text-orange-500'; | ||
} | ||
|
||
return 'text-green-500'; | ||
}; | ||
|
||
export const getWebVitalColorClass = (value: number, good: number, avg: number): string => { | ||
if (value <= good) { | ||
return 'text-green-500'; | ||
} | ||
|
||
if (value <= avg) { | ||
return 'text-orange-500'; | ||
} | ||
|
||
return 'text-red-600'; | ||
}; | ||
|
||
export const getLCPColorClass = (value: number): string => { | ||
return getWebVitalColorClass(value, 2500, 4000); | ||
}; | ||
|
||
export const getFIDColorClass = (value: number): string => { | ||
return getWebVitalColorClass(value, 100, 300); | ||
}; | ||
|
||
export const getCLSColorClass = (value: number): string => { | ||
return getWebVitalColorClass(value, 0.1, 0.25); | ||
}; |
cb367a0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: