-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading post for mobile alpha version:
. Basic style for post . Loading post using FlatList Co-author: Duke Manh <manhducdkcb@gmail.com>
- Loading branch information
Showing
9 changed files
with
191 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { StyleSheet, Text, View, useWindowDimensions } from 'react-native'; | ||
import useSWR from 'swr'; | ||
import RenderHtml from 'react-native-render-html'; | ||
import { tagsStyles, baseStyles } from './styles/post'; | ||
|
||
const styles = StyleSheet.create({ | ||
post: { | ||
minHeight: 300, | ||
}, | ||
title: { | ||
color: '#A0D1FB', | ||
fontSize: 28, | ||
fontWeight: 'bold', | ||
letterSpacing: -1.5, | ||
paddingVertical: 16, | ||
textAlign: 'center', | ||
}, | ||
}); | ||
|
||
export default function Post({ postURL }) { | ||
const { data: post, error } = useSWR(postURL); | ||
const { width } = useWindowDimensions(); | ||
|
||
if (error) { | ||
console.error(error); | ||
return ( | ||
<View style={styles.post}> | ||
<Text>Error Loading Post</Text> | ||
</View> | ||
); | ||
} | ||
|
||
if (!post) { | ||
return ( | ||
<View style={styles.post}> | ||
<Text>Loading</Text> | ||
</View> | ||
); | ||
} | ||
|
||
return ( | ||
<View style={styles.post}> | ||
<Text style={styles.title}>{post.title}</Text> | ||
<RenderHtml | ||
contentWidth={width} | ||
source={{ html: `${post.html}` }} | ||
tagsStyles={tagsStyles} | ||
baseStyle={baseStyles} | ||
/> | ||
</View> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import Constants from 'expo-constants'; | ||
import { FlatList, View, Button, StyleSheet } from 'react-native'; | ||
import useSWRInfinite from 'swr/infinite'; | ||
import Post from './Post'; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
}, | ||
divider: { | ||
backgroundColor: '#9f9f9f', | ||
height: 1, | ||
marginHorizontal: 'auto', | ||
marginVertical: 16, | ||
width: '80%', | ||
}, | ||
}); | ||
|
||
const POST_URL = 'https://dev.api.telescope.cdot.systems/v1/posts'; // Constants.manifest.extra.postsURL; | ||
|
||
function Posts() { | ||
const { | ||
data: pages, | ||
error, | ||
setSize, | ||
size, | ||
} = useSWRInfinite((index) => `${POST_URL}?page=${index + 1}&per_page=2`); | ||
|
||
if (error || !pages || !pages.length) { | ||
return null; | ||
} | ||
|
||
const renderPost = ({ item }) => | ||
item.map((post) => ( | ||
<View key={post.id}> | ||
<Post postURL={post.url} /> | ||
<View style={styles.divider} /> | ||
</View> | ||
)); | ||
|
||
return ( | ||
<View style={styles.container}> | ||
<FlatList | ||
data={pages} | ||
renderItem={renderPost} | ||
keyExtractor={(item, index) => index.toString()} | ||
/> | ||
<Button title="Load More" onPress={() => setSize(size + 1)} /> | ||
</View> | ||
); | ||
} | ||
|
||
export default Posts; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
const baseStyles = { | ||
fontFamily: 'PT Serif, serif', | ||
fontSize: 18, | ||
letterSpacing: 0.5, | ||
lineHeight: 18, | ||
textAlign: 'left', | ||
}; | ||
|
||
const tagsStyles = { | ||
code: { | ||
fontSize: 12, | ||
fontFamily: "Menlo, Consolas, Monaco, 'Liberation Mono', 'Lucida Console', monospace", | ||
borderRadius: 3, | ||
}, | ||
p: { | ||
margin: 16, | ||
}, | ||
pre: { | ||
fontSize: 15, | ||
lineHeight: 15, | ||
maxWidth: '100%', | ||
paddingHorizontal: 16, | ||
paddingVertical: 8, | ||
}, | ||
iframe: { | ||
position: 'absolute', | ||
top: 0, | ||
left: 0, | ||
width: '100%', | ||
height: '100%', | ||
}, | ||
q: { | ||
lineHeight: 1.5, | ||
marginVertical: 10, | ||
marginLeft: 50, | ||
paddingLeft: 15, | ||
display: 'block', | ||
fontStyle: 'italic', | ||
}, | ||
blockquote: { | ||
lineHeight: 15, | ||
marginTop: 10, | ||
marginBottom: 10, | ||
marginLeft: 50, | ||
paddingLeft: 15, | ||
display: 'block', | ||
fontStyle: 'italic', | ||
}, | ||
img: { | ||
margin: '0 auto', | ||
maxHeight: 80, | ||
paddingTop: 20, | ||
paddingBottom: 16, | ||
display: 'block', | ||
height: 'auto', | ||
}, | ||
h1: { | ||
fontSize: 24, | ||
marginLeft: 10, | ||
lineHeight: 25, | ||
}, | ||
}; | ||
|
||
export { tagsStyles, baseStyles }; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters