index.js (2171B)
1 import React, { useEffect, useState } from 'react'; 2 import { 3 SafeAreaView, 4 Text, 5 Linking, 6 FlatList, 7 Platform, 8 View, 9 TouchableOpacity 10 } from 'react-native'; 11 import moment from 'moment'; 12 import HTML from 'react-native-render-html'; 13 import renderSeparator from '../renderSeparator'; 14 15 import Comment from '../comment'; 16 17 import { 18 APIurl, 19 version 20 } from '../../../assets/constants/API'; 21 import styles from '../../../assets/styles'; 22 23 function StoryModal({ storyData, setShowStoryModal }) { 24 return ( 25 <SafeAreaView style={styles.storyModalContainer}> 26 <Text style={styles.storyUser}> 27 {storyData.by} • {parseTime(storyData.time)} 28 </Text> 29 <TouchableOpacity 30 onPress={() => setShowStoryModal(false)} 31 > 32 <Text style={styles.storyTitle}> 33 {storyData.title} 34 </Text> 35 </TouchableOpacity> 36 37 {storyData.text ? ( 38 <HTML html={storyData.text} /> 39 ) : ( 40 <></> 41 )} 42 {storyData.url ? ( 43 <Text 44 style={styles.storyUrl} 45 onPress={() => Linking.openURL(storyData.url)} 46 > 47 Open URL 🔗 48 </Text> 49 ) : ( 50 <></> 51 )} 52 <Text> 53 {storyData.score} upvote 54 {storyData.score == 1 ? '' : 's'} •{' '} 55 {storyData.descendants} comment 56 {storyData.descendants == 1 ? '' : 's'} 57 </Text> 58 <View style={styles.commentSeperator} /> 59 <Text style={styles.commentStarter}>Comments</Text> 60 {storyData.kids ? ( 61 <FlatList 62 showsVerticalScrollIndicator={false} 63 data={storyData.kids} 64 renderItem={comment => ( 65 <Comment commentID={comment.item} /> 66 )} 67 keyExtractor={comment => { 68 return String(comment); 69 }} 70 ItemSeparatorComponent={ 71 Platform.OS == 'ios' && renderSeparator 72 } 73 /> 74 ) : ( 75 <Null /> 76 )} 77 </SafeAreaView> 78 ); 79 } 80 81 function Null() { 82 return ( 83 <View> 84 <Text>No comments so far.</Text> 85 </View> 86 ); 87 } 88 89 function parseTime(UNIXtime) { 90 return moment(UNIXtime * 1000).fromNow(); 91 } 92 93 export default StoryModal;