forked from react-native-community/directory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.tsx
67 lines (60 loc) · 1.79 KB
/
index.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
import fetch from 'isomorphic-fetch';
import { NextPageContext } from 'next';
import dynamic from 'next/dynamic';
import { useRouter } from 'next/router';
import React from 'react';
import { View, StyleSheet } from 'react-native';
import ContentContainer from '../components/ContentContainer';
import LoadingContent from '../components/Library/LoadingContent';
import Navigation from '../components/Navigation';
import Pagination from '../components/Pagination';
import Search from '../components/Search';
import getApiUrl from '../util/getApiUrl';
import urlWithQuery from '../util/urlWithQuery';
const LibrariesWithLoading = dynamic(() => import('../components/Libraries'), {
loading: () => (
<View
style={{
paddingTop: 8,
}}>
<LoadingContent />
<LoadingContent />
<LoadingContent />
<LoadingContent />
<LoadingContent />
<LoadingContent />
<LoadingContent />
<LoadingContent />
</View>
),
});
const Index = ({ data, query }) => {
const router = useRouter();
const total = data && data.total;
return (
<>
<Navigation noHeader query={router.query?.search} />
<Search query={router.query} total={total} />
<ContentContainer style={styles.container}>
<Pagination query={query} total={total} />
<LibrariesWithLoading libraries={data && data.libraries} />
<Pagination query={query} total={total} />
</ContentContainer>
</>
);
};
Index.getInitialProps = async (ctx: NextPageContext) => {
const url = getApiUrl(urlWithQuery('/libraries', ctx.query), ctx);
const response = await fetch(url);
const result = await response.json();
return {
data: result,
query: ctx.query,
};
};
const styles = StyleSheet.create({
container: {
padding: 16,
},
});
export default Index;