Skip to content

Commit

Permalink
initial version of package page concept
Browse files Browse the repository at this point in the history
  • Loading branch information
Simek committed May 5, 2024
1 parent c2f5c14 commit bc9d052
Show file tree
Hide file tree
Showing 12 changed files with 45,517 additions and 14,459 deletions.
59,382 changes: 44,966 additions & 14,416 deletions assets/data.json

Large diffs are not rendered by default.

33 changes: 3 additions & 30 deletions components/Libraries.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import dynamic from 'next/dynamic';
import { Image, StyleSheet, View } from 'react-native';
import { StyleSheet, View } from 'react-native';

import LoadingContent from './Library/LoadingContent';
import { H3, A, P } from '../common/styleguide';
import { NotFoundContent } from './NotFoundContent';
import { Library as LibraryType } from '../types';

type Props = {
Expand All @@ -15,18 +15,7 @@ const LibraryWithLoading = dynamic(() => import('../components/Library'), {

const Libraries = ({ libraries }: Props) => {
if (!libraries || !libraries.length) {
return (
<View style={styles.container}>
<Image style={styles.img} source={require('../assets/notfound.png')} alt="No results" />
<H3 style={styles.text}>Nothing was found! Try another search.</H3>
<View style={{ marginTop: 20 }} />
<P style={styles.text}>
Want to contribute a library you like? Submit a PR to the{' '}
<A href="https://github.com/react-native-community/react-native-directory">Github Repo</A>
.
</P>
</View>
);
return <NotFoundContent />;
}

return (
Expand All @@ -39,25 +28,9 @@ const Libraries = ({ libraries }: Props) => {
};

const styles = StyleSheet.create({
container: {
alignItems: 'center',
width: '100%',
paddingHorizontal: 24,
marginTop: 40,
marginBottom: 80,
},
librariesContainer: {
paddingTop: 12,
},
img: {
marginTop: 48,
marginBottom: 24,
width: 64,
height: 64,
},
text: {
textAlign: 'center',
},
});

export default Libraries;
14 changes: 10 additions & 4 deletions components/Library/MetaData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@ import {
type Props = {
library: LibraryType;
secondary?: boolean;
skipExamples?: boolean;
};

const generateData = (library: LibraryType, secondary: boolean, isDark: boolean) => {
const generateData = (
library: LibraryType,
secondary: boolean,
isDark: boolean,
skipExamples = false
) => {
const { github, newArchitecture, examples, score, npm, npmPkg } = library;

if (secondary) {
Expand Down Expand Up @@ -84,7 +90,7 @@ const generateData = (library: LibraryType, secondary: boolean, isDark: boolean)
),
}
: null,
examples && examples.length
!skipExamples && examples && examples.length
? {
id: 'examples',
icon: <Code fill={iconColor} width={16} height={16} />,
Expand Down Expand Up @@ -183,9 +189,9 @@ const generateData = (library: LibraryType, secondary: boolean, isDark: boolean)
}
};

export function MetaData({ library, secondary }: Props) {
export function MetaData({ library, secondary, skipExamples = false }: Props) {
const { isDark } = useContext(CustomAppearanceContext);
const data = generateData(library, secondary, isDark);
const data = generateData(library, secondary, isDark, skipExamples);

return (
<>
Expand Down
39 changes: 32 additions & 7 deletions components/Library/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import UnmaintainedLabel from './UnmaintainedLabel';
import { colors, useLayout, A, darkColors, Headline } from '../../common/styleguide';
import CustomAppearanceContext from '../../context/CustomAppearanceContext';
import { Library as LibraryType } from '../../types';
import { getLibraryDisplayName } from '../../util/strings';
import { CompatibilityTags } from '../CompatibilityTags';

type Props = {
Expand All @@ -23,7 +24,8 @@ const Library = ({ library, skipMeta, showPopularity }: Props) => {
const { isDark } = useContext(CustomAppearanceContext);
const { github } = library;
const { isSmallScreen, isBelowMaxWidth } = useLayout();
const libName = library.nameOverride || library.npmPkg || github.name;
const libName = getLibraryDisplayName(library);
const detailsLinkHoverStyle = isDark && { color: colors.primaryDark };

return (
<View
Expand All @@ -39,14 +41,27 @@ const Library = ({ library, skipMeta, showPopularity }: Props) => {
<View style={styles.columnOne}>
{library.unmaintained && <UnmaintainedLabel />}
{showPopularity && library.popularity && <PopularityMark library={library} />}
<View style={isSmallScreen ? styles.containerColumn : styles.displayHorizontal}>
<View
style={[
styles.nameWrapper,
isSmallScreen ? styles.containerColumn : styles.displayHorizontal,
]}>
<View style={isSmallScreen ? styles.containerColumn : styles.displayHorizontal}>
<A
href={library.githubUrl || github.urls.repo}
style={styles.name}
hoverStyle={styles.nameHovered}>
{libName}
</A>
{library.goldstar && <RecommendedLabel isSmallScreen={isSmallScreen} />}
</View>
<A
href={library.githubUrl || github.urls.repo}
style={styles.name}
hoverStyle={styles.nameHovered}>
{libName}
href={`package/${library.npmPkg}`}
target="_self"
style={styles.detailsLink}
hoverStyle={detailsLinkHoverStyle}>
See details
</A>
{library.goldstar && <RecommendedLabel isSmallScreen={isSmallScreen} />}
</View>
<View style={styles.verticalMargin}>
<CompatibilityTags library={library} />
Expand Down Expand Up @@ -136,6 +151,10 @@ const styles = StyleSheet.create({
borderLeftWidth: 0,
borderTopWidth: 1,
},
nameWrapper: {
justifyContent: 'space-between',
alignItems: 'center',
},
name: {
backgroundColor: 'transparent',
fontWeight: '600',
Expand Down Expand Up @@ -186,6 +205,12 @@ const styles = StyleSheet.create({
fontSize: 13,
color: colors.gray5,
},
detailsLink: {
fontSize: 14,
color: colors.gray4,
backgroundColor: 'transparent',
textDecorationLine: 'none',
},
bottomBar: {
width: '100%',
position: 'absolute',
Expand Down
51 changes: 51 additions & 0 deletions components/NotFoundContent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { type ReactNode } from 'react';
import { Image, StyleSheet, View } from 'react-native';

import { A, H3, P } from '../common/styleguide';

type Props = {
header?: string;
alt?: string;
bottomSlot?: ReactNode;
};

export function NotFoundContent({
header = 'Nothing was found! Try another search.',
alt = 'No results',
bottomSlot,
}: Props) {
return (
<View style={styles.container}>
<Image style={styles.img} source={require('../assets/notfound.png')} alt={alt} />
<H3 style={styles.text}>{header}</H3>
{bottomSlot}
<View style={{ marginTop: 20 }} />
<P style={styles.text}>
Want to contribute a library you like? Submit a PR to the{' '}
<A href="https://github.com/react-native-community/react-native-directory">Github Repo</A>.
</P>
</View>
);
}

const styles = StyleSheet.create({
container: {
alignItems: 'center',
width: '100%',
paddingHorizontal: 24,
marginTop: 40,
marginBottom: 80,
},
librariesContainer: {
paddingTop: 8,
},
img: {
marginTop: 48,
marginBottom: 24,
width: 64,
height: 64,
},
text: {
textAlign: 'center',
},
});
81 changes: 81 additions & 0 deletions components/PackageAuthor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { View } from 'react-native';

import { A, Caption, Label } from '../common/styleguide';
import { PackageJsonData } from '../types';

type Props = {
author?: PackageJsonData['author'];
size?: 'sm' | 'md';
};

export function PackageAuthor({ author }: Props) {
if (!author) {
return (
<View>
<Label>Unknown</Label>
</View>
);
}

if (typeof author !== 'string') {
if (author?.url) {
return (
<View>
<A href={author?.url} target="_blank">
<Label>{author?.name ?? 'Unknown'}</Label>
</A>
</View>
);
}
return (
<View>
<Label>{author?.name ?? 'Unknown'}</Label>
</View>
);
}

if (author.includes('github.com/')) {
const [potentialName, potentialGHUsername] = author.split('github.com/');
const ghUsername = potentialGHUsername.replace(/[<>()]/g, '');
const validName = getValidName(potentialName);

return (
<View>
<A
href={`https://github.com/${ghUsername}`}
target="_blank"
style={{
display: 'flex',
flexDirection: 'row',
gap: 12,
alignItems: 'center',
backgroundColor: 'transparent',
}}>
<img
src={`https://github.com/${ghUsername}.png`}
style={{ width: 36, height: 36, borderRadius: '100%' }}
alt={`${ghUsername} avatar`}
/>
<View>
<Caption style={{ lineHeight: 16 }}>{ghUsername}</Caption>
<Label>{validName}</Label>
</View>
</A>
</View>
);
}

return (
<View>
<Label>{getValidName(author) ?? author ?? 'Unknown'}</Label>
</View>
);
}

function getValidName(potentialName: string): string {
const cleanName = potentialName
.split(' ')
.filter(word => !(word.includes('(') || word.includes('/') || word.includes('<')))
.join(' ');
return cleanName.length ? cleanName : potentialName.replace(/[<>()]/g, '');
}

0 comments on commit bc9d052

Please sign in to comment.