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

add minMonthlyDownloads filter for Trending, a11y fixes #1327

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion common/styleguide.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ export const HoverEffect = ({ children }) => {
<View
ref={ref}
style={[isHovered && { opacity: 0.8 }, isActive && { opacity: 0.5 }]}
focusable={false}
accessible={false}>
{children}
</View>
Expand Down
2 changes: 1 addition & 1 deletion components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const Header = () => {
</Tooltip>
<Button
openInNewTab
aria-label="GitHub"
aria-label="GitHub repository"
href="https://github.com/react-native-community/directory"
style={[styles.button, styles.themeButtonSmall]}>
<GitHub fill={isDark ? colors.white : colors.black} />
Expand Down
2 changes: 1 addition & 1 deletion components/Library/TrendingMark.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const getPopularityStyles = (popularity, markOnly) => {
} else if (popularity > 0.25) {
return {
width: 24,
backgroundColor: '#e20026',
backgroundColor: '#e70a2f',
top,
};
} else if (popularity > 0.1) {
Expand Down
4 changes: 2 additions & 2 deletions components/Library/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const Library = ({ library, skipMetadata, showTrendingMark }: Props) => {
<Tooltip
sideOffset={8}
trigger={
<View style={styles.popularityContainer}>
<View style={styles.trendingMarkContainer}>
<TrendingMark library={library} />
</View>
}>
Expand Down Expand Up @@ -236,7 +236,7 @@ const styles = StyleSheet.create({
unmaintained: {
opacity: 0.88,
},
popularityContainer: {
trendingMarkContainer: {
alignSelf: 'flex-start',
},
});
Expand Down
6 changes: 4 additions & 2 deletions components/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { StyleSheet, View } from 'react-native';

import ContentContainer from './ContentContainer';
import NavigationTab from './NavigationTab';
import { colors, darkColors, H1, P } from '../common/styleguide';
import { colors, darkColors, H1, H2 } from '../common/styleguide';
import CustomAppearanceContext from '../context/CustomAppearanceContext';

type NavigationProps = PropsWithChildren<{
Expand Down Expand Up @@ -33,7 +33,7 @@ const Navigation = ({ title, description, children, noHeader = false }: Navigati
{ backgroundColor: isDark ? darkColors.dark : colors.gray6 },
]}>
<H1 style={styles.header}>{title}</H1>
<P style={styles.headerDescription}>{description}</P>
<H2 style={styles.headerDescription}>{description}</H2>
{children}
</View>
) : null}
Expand Down Expand Up @@ -62,6 +62,8 @@ const styles = StyleSheet.create({
headerDescription: {
textAlign: 'center',
color: colors.pewter,
fontWeight: '500',
fontSize: 16,
paddingTop: 4,
paddingBottom: 6,
paddingHorizontal: 40,
Expand Down
2 changes: 1 addition & 1 deletion pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const App = ({ pageProps, Component }) => (
<Head>
<meta
name="viewport"
content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1.00001,viewport-fit=cover"
content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=2,viewport-fit=cover"
/>
<style>
{`html {
Expand Down
1 change: 1 addition & 0 deletions pages/api/libraries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) {
isRecommended: req.query.isRecommended,
wasRecentlyUpdated: req.query.wasRecentlyUpdated,
minPopularity: req.query.minPopularity,
minMonthlyDownloads: req.query.minMonthlyDownloads,
newArchitecture: req.query.newArchitecture,
skipLibs: req.query.skipLibs,
skipTools: req.query.skipTools,
Expand Down
2 changes: 1 addition & 1 deletion pages/trending.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const Trending = ({ data, query }) => {
Trending.getInitialProps = async (ctx: NextPageContext) => {
const trendingQuery = {
...ctx.query,
...{ minPopularity: 5, order: 'popularity' as QueryOrder },
...{ minPopularity: 5, minMonthlyDownloads: 1000, order: 'popularity' as QueryOrder },
};
const url = getApiUrl(urlWithQuery('/libraries', trendingQuery), ctx);
const response = await fetch(url);
Expand Down
1 change: 1 addition & 0 deletions types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export type Query = {
isRecommended?: string;
wasRecentlyUpdated?: string;
minPopularity?: string | number;
minMonthlyDownloads?: string | number;
newArchitecture?: string;
};

Expand Down
12 changes: 11 additions & 1 deletion util/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,17 @@ export const handleFilterLibraries = ({
isRecommended,
wasRecentlyUpdated,
minPopularity,
minMonthlyDownloads,
newArchitecture,
skipLibs,
skipTools,
skipTemplates,
}) => {
const viewerHasChosenTopic = !isEmptyOrNull(queryTopic);
const viewerHasTypedSearch = !isEmptyOrNull(querySearch);

const minPopularityValue = minPopularity && parseFloat(minPopularity) / 100;
const minMonthlyDownloadsValue = minMonthlyDownloads && parseInt(minMonthlyDownloads, 10);

const processedLibraries = viewerHasTypedSearch
? libraries.map(library => ({
Expand Down Expand Up @@ -169,8 +172,15 @@ export const handleFilterLibraries = ({
return false;
}

if (minPopularityValue) {
if (minPopularityValue && minMonthlyDownloadsValue) {
return (
library.popularity >= minPopularityValue &&
library.npm.downloads >= minMonthlyDownloadsValue
);
} else if (minPopularityValue) {
return library.popularity >= minPopularityValue;
} else if (minMonthlyDownloadsValue) {
return library.npm.downloads >= minMonthlyDownloadsValue;
}

if (!viewerHasChosenTopic && !viewerHasTypedSearch) {
Expand Down