forked from react-native-community/directory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrending.tsx
102 lines (95 loc) · 2.83 KB
/
trending.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import { NextPageContext } from 'next';
import dynamic from 'next/dynamic';
import React, { useContext } from 'react';
import { Image, StyleSheet, View } from 'react-native';
import { A, H4, colors, darkColors, P } from '../common/styleguide';
import ContentContainer from '../components/ContentContainer';
import { Filters } from '../components/Filters';
import LoadingContent from '../components/Library/LoadingContent';
import Navigation from '../components/Navigation';
import CustomAppearanceContext from '../context/CustomAppearanceContext';
import { Library as LibraryType } from '../types';
import getApiUrl from '../util/getApiUrl';
import urlWithQuery from '../util/urlWithQuery';
const LibraryWithLoading = dynamic(() => import('../components/Library'), {
loading: () => <LoadingContent />,
});
const Trending = ({ data, query }) => {
const { isDark } = useContext(CustomAppearanceContext);
return (
<>
<Navigation
title="Trending libraries"
description="See the libraries that are trending today."
/>
<ContentContainer style={styles.container}>
<Filters query={query} basePath="/trending" style={styles.filtersWrapper} />
{data.length ? (
data.map((item: LibraryType, index: number) => (
<LibraryWithLoading
key={`list-item-${index}-${item.github.name}`}
library={item}
showPopularity
/>
))
) : (
<View style={styles.noResultWrapper}>
<Image style={styles.noResultImg} source={require('../assets/notfound.png')} />
<H4>Nothing was found!</H4>
</View>
)}
<P style={[styles.note, { color: isDark ? darkColors.secondary : colors.gray5 }]}>
Unfortunately that's all, what's trending now. Want to explore more libraries? Check out
the{' '}
<A href={urlWithQuery('/', {})} target="_self">
directory home page
</A>
.
</P>
</ContentContainer>
</>
);
};
Trending.getInitialProps = async (ctx: NextPageContext) => {
const url = getApiUrl(
urlWithQuery('/libraries', {
...ctx.query,
...{ limit: 9999, minPopularity: 5, order: 'popularity' },
}),
ctx
);
const response = await fetch(url);
const result = await response.json();
return {
data: result.libraries,
query: ctx.query,
};
};
const styles = StyleSheet.create({
container: {
paddingHorizontal: 16,
paddingVertical: 12,
},
filtersWrapper: {
backgroundColor: 'transparent',
marginBottom: 16,
paddingTop: 0,
},
note: {
padding: 24,
fontSize: 14,
},
noResultWrapper: {
alignItems: 'center',
marginTop: 24,
marginBottom: 42,
},
noResult: {
marginTop: 12,
},
noResultImg: {
width: 64,
height: 64,
},
});
export default Trending;