-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create crate detail page (#98)
* chore: update libraries * feat: create crate detail page
- Loading branch information
1 parent
52e65f9
commit dd9f9b5
Showing
9 changed files
with
456 additions
and
445 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
61 changes: 61 additions & 0 deletions
61
web/src/components/details/[crate_name]/CrateSizeChart.tsx
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,61 @@ | ||
import ReactECharts from 'components/echarts/ReactEChart'; | ||
import { Version } from 'interfaces/crate'; | ||
import { css } from '@emotion/react'; | ||
import prettyBytes from 'pretty-bytes'; | ||
import type { EChartsOption } from 'echarts'; | ||
import { Typography } from '@mui/material'; | ||
import { useMemo } from 'react'; | ||
|
||
interface Props { | ||
versionList: Version[]; | ||
} | ||
|
||
const CrateSizeChart = ({ versionList }: Props): JSX.Element => { | ||
const option: EChartsOption = useMemo(() => { | ||
return { | ||
tooltip: { | ||
trigger: 'axis', | ||
axisPointer: { type: 'shadow' }, | ||
valueFormatter: (val) => prettyBytes(Number(val)), | ||
}, | ||
xAxis: { | ||
type: 'category', | ||
data: versionList.map((version) => version.num), | ||
}, | ||
yAxis: { | ||
type: 'value', | ||
axisLabel: { | ||
formatter: (val) => prettyBytes(Number(val)), | ||
}, | ||
}, | ||
series: [ | ||
{ | ||
data: versionList.map((version) => version?.crate_size ?? 0), | ||
type: 'bar', | ||
}, | ||
], | ||
dataZoom: [ | ||
{ realtime: true, show: true, type: 'slider' }, | ||
{ realtime: true, show: true, type: 'inside', zoomLock: true }, | ||
], | ||
}; | ||
}, [versionList]); | ||
|
||
return ( | ||
<div> | ||
<div css={SizeChart}> | ||
<Typography variant="h6" component="h3" gutterBottom> | ||
Crate Size Transition | ||
</Typography> | ||
<ReactECharts option={option} /> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
const SizeChart = css` | ||
width: 100%; | ||
height: 45vh; | ||
`; | ||
|
||
export default CrateSizeChart; |
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,37 @@ | ||
import { useRouter } from 'next/router'; | ||
import { css } from '@emotion/react'; | ||
import { useRecoilValue } from 'recoil'; | ||
import { crateDataResultsState } from 'recoil/atoms'; | ||
import CrateSizeChart from 'components/details/[crate_name]/CrateSizeChart'; | ||
import { Typography } from '@mui/material'; | ||
|
||
const CrateDetailView = (): JSX.Element => { | ||
const router = useRouter(); | ||
const { crate_name } = router.query; | ||
const crateNameList = crate_name ? [crate_name.toString()] : []; | ||
const crateDataResult = useRecoilValue(crateDataResultsState(crateNameList)); | ||
|
||
return ( | ||
<> | ||
<div css={Wrapper}> | ||
<div> | ||
{crateDataResult.map((crate) => ( | ||
<div key={crate.crate.id}> | ||
<Typography variant="h5" component="h2" gutterBottom> | ||
{crate.crate.name} | ||
</Typography> | ||
<Typography variant="body1">{crate.crate.description}</Typography> | ||
<CrateSizeChart versionList={[...crate.versions].reverse()} /> | ||
</div> | ||
))} | ||
</div> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
const Wrapper = css` | ||
flex: 1; | ||
`; | ||
|
||
export default CrateDetailView; |
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,13 @@ | ||
import React from 'react'; | ||
import CrateDetailView from 'components/shared/CrateDetailView'; | ||
import Spinner from 'components/shared/Spinner'; | ||
|
||
const CrateDetailPage = (): JSX.Element => { | ||
return ( | ||
<React.Suspense fallback={<Spinner />}> | ||
<CrateDetailView /> | ||
</React.Suspense> | ||
); | ||
}; | ||
|
||
export default CrateDetailPage; |