@@ -6,6 +6,7 @@ import { Linkify } from 'react-easy-linkify';
66import { Platform , StyleSheet , View } from 'react-native' ;
77import rehypeRaw from 'rehype-raw' ;
88import rehypeSanitize from 'rehype-sanitize' ;
9+ import remarkGfm from 'remark-gfm' ;
910
1011import { A , colors , darkColors , H6 , Headline , Label , P , useLayout } from '~/common/styleguide' ;
1112import { Button } from '~/components/Button' ;
@@ -29,21 +30,23 @@ import { getExampleDescription } from '~/util/strings';
2930import urlWithQuery from '~/util/urlWithQuery' ;
3031
3132type Props = {
33+ packageName : string ;
3234 apiData : {
3335 libraries : LibraryType [ ] ;
3436 } ;
35- registryData : NpmLatestRegistryData ;
36- packageName : string ;
37+ registryData ?: NpmLatestRegistryData ;
3738 readmeContent ?: string ;
3839} ;
3940
41+ // TODO: async render/data fetch
42+ // TODO: responsive/mobile viewports
4043export default function PackagePage ( { apiData, registryData, packageName, readmeContent } : Props ) {
4144 const { isDark } = useContext ( CustomAppearanceContext ) ;
4245 const { isSmallScreen } = useLayout ( ) ;
4346
4447 const library = apiData . libraries . find ( lib => lib . npmPkg === packageName ) ;
4548
46- if ( ! library ) {
49+ if ( ! library || ! registryData ) {
4750 return (
4851 < >
4952 < Navigation />
@@ -62,7 +65,6 @@ export default function PackagePage({ apiData, registryData, packageName, readme
6265 ) ;
6366 }
6467
65- const { description } = library . github ;
6668 const { author, maintainers, dependencies, devDependencies, peerDependencies, engines } =
6769 registryData ;
6870
@@ -92,13 +94,13 @@ export default function PackagePage({ apiData, registryData, packageName, readme
9294 < UpdatedAtView library = { library } />
9395 </ View >
9496 < CompatibilityTags library = { library } />
95- { description && description . length && (
97+ { library . github . description && library . github . description . length && (
9698 < Headline style = { styles . description } >
9799 < Linkify
98100 options = { {
99101 linkWrapper : props => < A { ...props } > { props . children } </ A > ,
100102 } } >
101- { emoji . emojify ( description ) }
103+ { emoji . emojify ( library . github . description ) }
102104 </ Linkify >
103105 </ Headline >
104106 ) }
@@ -118,10 +120,12 @@ export default function PackagePage({ apiData, registryData, packageName, readme
118120 hr : ( ) => null ,
119121 a : ( props : any ) => < A containerStyle = { { display : 'inline-flex' } } { ...props } /> ,
120122 // TODO: decide if we want to remove images/assets, or fix relative assets links
121- // TODO: render code block in a better way
122123 // TODO: render blockquotes in a better way, support GH themed notes
124+ // TODO: render code block in a better way
125+ // TODO: render tables in a better way
123126 } }
124- rehypePlugins = { [ rehypeRaw , rehypeSanitize ] } >
127+ rehypePlugins = { [ rehypeRaw , rehypeSanitize ] }
128+ remarkPlugins = { [ remarkGfm ] } >
125129 { readmeContent }
126130 </ Md >
127131 </ View >
@@ -166,7 +170,7 @@ export default function PackagePage({ apiData, registryData, packageName, readme
166170 </ >
167171 ) }
168172 < H6 style = { [ styles . mainContentHeader , headerColorStyle ] } > Additional information</ H6 >
169- < View style = { { gap : 6 } } >
173+ < View style = { styles . rowSpacing } >
170174 < MetaData library = { library } secondary skipExamples />
171175 </ View >
172176 { library . images && library . images . length ? (
@@ -187,7 +191,7 @@ export default function PackagePage({ apiData, registryData, packageName, readme
187191 < H6 style = { [ styles . mainContentHeader , headerColorStyle ] } > Popularity</ H6 >
188192 < TrendingMark library = { library } />
189193 < H6 style = { [ styles . contentHeader , headerColorStyle ] } > Package analysis</ H6 >
190- < View style = { { gap : 4 } } >
194+ < View style = { styles . rowSpacing } >
191195 < A
192196 href = { `https://bundlephobia.com/package/${ library . npmPkg } ` }
193197 target = "_blank"
@@ -350,6 +354,9 @@ const styles = StyleSheet.create({
350354 borderWidth : 1 ,
351355 borderStyle : 'solid' ,
352356 } ,
357+ rowSpacing : {
358+ gap : 6 ,
359+ } ,
353360} ) ;
354361
355362export async function getServerSideProps ( ctx : NextPageContext ) {
0 commit comments