import { StyleSheet, Text, View, TouchableWithoutFeedback, ScrollView, Image, } from 'react-native'; import React, {useCallback} from 'react'; import NewscoutTitleHeader from '../../components/molecules/Header/NewscoutTitleHeader'; import MaterialIcon from 'react-native-vector-icons/MaterialIcons'; import colors from '../../constants/colors'; import { horizontalScale, moderateScale, verticalScale, } from '../../constants/metrics'; import { getArticleBySlug, getCommentByArticleID, getRecommendationByArticleID, } from '../../api/data'; import LoadingScreen from '../../components/organisms/Sections/LoadingScreen'; import { getTimestamp, navigateToArticle, useConstructor, } from '../../constants/functions'; import fonts from '../../constants/fonts'; import BookmarkButton from '../../components/atoms/Buttons/BookmarkButton'; import ShareButton from '../../components/atoms/Buttons/ShareButton'; import IonIcon from 'react-native-vector-icons/Ionicons'; import { BottomSheetModal, BottomSheetModalProvider, BottomSheetView, BottomSheetScrollView, } from '@gorhom/bottom-sheet'; import ButtonWrapper from '../../components/atoms/Buttons/ButtonWrapper'; import images from '../../assets/images/images'; import SectionHeader from '../../components/molecules/Header/SectionHeader'; import VerticalNewsCard from '../../components/molecules/Cards/VerticalNewsCard'; const NewsDetailPage = props => { const {navigation, route} = props; const {id, slug} = route.params; const [isLoading, setLoading] = React.useState(true); const [article, setArticle] = React.useState({}); const [comments, setComments] = React.useState({ total_article_likes: 0, results: [], }); const [recommendations, setRecommendations] = React.useState([]); const mainPageRef = React.useRef(null); const bottomSheetModalRef = React.useRef(''); // Comments Modal const snapPoints = React.useMemo(() => ['70%', '100%'], []); const handlePresentModalPress = useCallback(() => { bottomSheetModalRef.current?.present(); }, []); const handleCloseModalPress = () => bottomSheetModalRef.current.close(); const handleSheetChanges = useCallback(index => { console.log('handleSheetChanges', index); }, []); const fetchArticle = slug => { getArticleBySlug(slug) .then(res => { console.log(res.data); setArticle(res.data.body.article); setLoading(false); }) .catch(error => console.log(error)); }; const fetchComments = id => { getCommentByArticleID(id) .then(res => { console.log(res.data.body); setComments(res.data.body); }) .catch(err => console.log(err)); }; const fetchRecommendations = id => { getRecommendationByArticleID(id) .then(res => setRecommendations(res.data.body.results)) .catch(err => console.log(err)); }; useConstructor(function () { fetchArticle(slug); fetchComments(id); fetchRecommendations(id); }); const styles = StyleSheet.create({ container: {backgroundColor: colors().dominant, minHeight: '100%'}, newsContainer: {paddingHorizontal: horizontalScale(16)}, newsTitle: { fontFamily: fonts.type.semibold, color: colors().recessive, fontSize: moderateScale(16), }, newsTagline: { color: colors().recessive_variant, fontFamily: fonts.type.regular, paddingVertical: verticalScale(12), }, newsDescriptorContainer: { flexDirection: 'row', gap: horizontalScale(8), }, newsDescriptor: { color: colors().recessive, fontFamily: fonts.type.semibold, fontSize: moderateScale(12), }, imagesContainer: { width: 'auto', height: verticalScale(200), marginTop: verticalScale(16), }, image: { borderRadius: moderateScale(4), width: '100%', height: '100%', }, buttonStyle: { padding: moderateScale(8), }, commentSection: { alignItems: 'center', justifyContent: 'center', flexDirection: 'row', gap: moderateScale(8), paddingLeft: horizontalScale(4), }, commentText: { fontFamily: fonts.type.regular, color: colors().grayShade_200, }, commentInputContainer: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', paddingVertical: verticalScale(4), }, profileImage: { height: 42, width: 42, borderRadius: 32, marginRight: horizontalScale(16), }, commentInput: { paddingVertical: verticalScale(16), alignItems: 'center', justifyContent: 'flex-start', flexDirection: 'row', }, utilButtons: { flexDirection: 'row', justifyContent: 'space-between', paddingVertical: verticalScale(4), }, newsText: { color: colors().grayShade_200, fontFamily: fonts.type.regular, lineHeight: verticalScale(24), paddingVertical: verticalScale(4), }, backToTop: { alignItems: 'center', justifyContent: 'center', paddingTop: verticalScale(16), paddingBottom: verticalScale(8), }, backToTopText: { color: colors().primaryColor, fontFamily: fonts.type.medium, textDecorationLine: 'underline', fontSize: moderateScale(16), }, recommendationContainer: { paddingHorizontal: horizontalScale(16), gap: moderateScale(4), paddingBottom: verticalScale(16), backgroundColor: colors().dominant, flexDirection: 'row', }, }); return ( navigation.goBack()}> navigation.toggleDrawer()}> {isLoading === true ? ( ) : ( {article.title} {'No Tagline'} {getTimestamp(article.published_on)} {(article.author !== undefined || article.author.length <= 0) ?? ( By {article.author} )} {article.source} {comments.results.length ?? 123} COMMENTS {article.blurb} mainPageRef.current.scrollTo({ y: 0, }) }> Back To Top <> Comments Comment Text Input <> View all Comments({comments.results.length}) {comments.results.length <= 0 ? ( ) : ( comments.results.map(() => ) )} )} {recommendations.map(item => ( navigateToArticle(navigation, item.id, item.slug)} /> ))} ); }; export default NewsDetailPage;