|
@@ -1,6 +1,6 @@
|
|
-import {StyleSheet, Text, View, ScrollView} from 'react-native';
|
|
|
|
-import React, {useContext, useEffect} from 'react';
|
|
|
|
-import {ToggleButton} from 'react-native-paper';
|
|
|
|
|
|
+import { StyleSheet, Text, View, ScrollView, FlatList } from 'react-native';
|
|
|
|
+import React, { useContext, useEffect } from 'react';
|
|
|
|
+import { ToggleButton } from 'react-native-paper';
|
|
import fonts from '../../../constants/fonts';
|
|
import fonts from '../../../constants/fonts';
|
|
import colors from '../../../constants/colors';
|
|
import colors from '../../../constants/colors';
|
|
import HorizontalNewsCardVariant from '../../molecules/Cards/HorizontalNewsCardVariant';
|
|
import HorizontalNewsCardVariant from '../../molecules/Cards/HorizontalNewsCardVariant';
|
|
@@ -17,19 +17,19 @@ import {
|
|
moderateScale,
|
|
moderateScale,
|
|
verticalScale,
|
|
verticalScale,
|
|
} from '../../../constants/metrics';
|
|
} from '../../../constants/metrics';
|
|
-import {ThemeContext} from '../../../context/theme.context';
|
|
|
|
-import {getArticlesByCategory, getCategories} from '../../../api/data';
|
|
|
|
|
|
+import { ThemeContext } from '../../../context/theme.context';
|
|
|
|
+import { getArticlesByCategory, getCategories } from '../../../api/data';
|
|
import LoadingScreen from './LoadingScreen';
|
|
import LoadingScreen from './LoadingScreen';
|
|
import { NEWSCOUT_NEWS_URL, PAGINATE_BY } from '../../../api/urls';
|
|
import { NEWSCOUT_NEWS_URL, PAGINATE_BY } from '../../../api/urls';
|
|
|
|
|
|
|
|
|
|
-const CategorySection = ({navigation}) => {
|
|
|
|
|
|
+const CategorySection = ({ navigation }) => {
|
|
const theme = useContext(ThemeContext);
|
|
const theme = useContext(ThemeContext);
|
|
const currentTheme = theme.state.theme;
|
|
const currentTheme = theme.state.theme;
|
|
|
|
|
|
const [isLoading, setLoading] = React.useState(true);
|
|
const [isLoading, setLoading] = React.useState(true);
|
|
|
|
|
|
- const [news, setNews] = React.useState({all: []});
|
|
|
|
|
|
+ const [news, setNews] = React.useState({ all: [] });
|
|
const updateNewsByCategories = (key, value) => {
|
|
const updateNewsByCategories = (key, value) => {
|
|
setNews(prevObject => ({
|
|
setNews(prevObject => ({
|
|
...prevObject,
|
|
...prevObject,
|
|
@@ -47,11 +47,11 @@ const CategorySection = ({navigation}) => {
|
|
setCategories(categoryData);
|
|
setCategories(categoryData);
|
|
setNews(
|
|
setNews(
|
|
categoryData.reduce(
|
|
categoryData.reduce(
|
|
- (result, key) => ({...result, [key.heading.name]: []}),
|
|
|
|
|
|
+ (result, key) => ({ ...result, [key.heading.name]: [] }),
|
|
{},
|
|
{},
|
|
),
|
|
),
|
|
)
|
|
)
|
|
-
|
|
|
|
|
|
+
|
|
return categoryData
|
|
return categoryData
|
|
}).then(categoryData => {
|
|
}).then(categoryData => {
|
|
categoryData.forEach((category) => fetchNews(category.heading.name))
|
|
categoryData.forEach((category) => fetchNews(category.heading.name))
|
|
@@ -68,7 +68,7 @@ const CategorySection = ({navigation}) => {
|
|
getArticlesByCategory(category)
|
|
getArticlesByCategory(category)
|
|
.then(res => {
|
|
.then(res => {
|
|
console.log(`Fetch News Trial : ${res.data.body.results}`)
|
|
console.log(`Fetch News Trial : ${res.data.body.results}`)
|
|
- updateNewsByCategories(category, res.data.body.results.slice(0,PAGINATE_BY))
|
|
|
|
|
|
+ updateNewsByCategories(category, res.data.body.results.slice(0, PAGINATE_BY))
|
|
})
|
|
})
|
|
.catch(err => console.error(`Fetch News : ${err}`))
|
|
.catch(err => console.error(`Fetch News : ${err}`))
|
|
.finally(() => console.log('Fetch News Executed'));
|
|
.finally(() => console.log('Fetch News Executed'));
|
|
@@ -133,70 +133,70 @@ const CategorySection = ({navigation}) => {
|
|
});
|
|
});
|
|
|
|
|
|
return (
|
|
return (
|
|
- <View style={styles.categoriesContainer}>
|
|
|
|
- <SectionHeader label={'Categories'} onPress={() => navigateToListViewPage(navigation,"category",categoryValue)}/>
|
|
|
|
|
|
+ <View>
|
|
|
|
+ <SectionHeader label={'Categories'} onPress={() => navigateToListViewPage(navigation, "category", categoryValue)} />
|
|
{isLoading === true ? (
|
|
{isLoading === true ? (
|
|
<LoadingScreen containerHeight={240} />
|
|
<LoadingScreen containerHeight={240} />
|
|
) : (
|
|
) : (
|
|
<>
|
|
<>
|
|
- <View style={styles.categoriesPillContainer}>
|
|
|
|
- <ScrollView horizontal showsHorizontalScrollIndicator={false}>
|
|
|
|
- <ToggleButton.Group
|
|
|
|
- onValueChange={value => {
|
|
|
|
- setCategoryValue(value)
|
|
|
|
- }}>
|
|
|
|
- {categories.map(category => (
|
|
|
|
- <ToggleButton
|
|
|
|
- key={category.heading.name}
|
|
|
|
- icon={() => (
|
|
|
|
- <Text
|
|
|
|
- style={[
|
|
|
|
- category.heading.name === categoryValue
|
|
|
|
- ? styles.selectedPillText
|
|
|
|
- : styles.pillText,
|
|
|
|
- ]}>
|
|
|
|
- {category.heading.name}
|
|
|
|
- </Text>
|
|
|
|
- )}
|
|
|
|
- style={[
|
|
|
|
- category.heading.name === categoryValue
|
|
|
|
- ? styles.selectedContainer
|
|
|
|
- : styles.container,
|
|
|
|
- {marginHorizontal: horizontalScale(4)},
|
|
|
|
- ]}
|
|
|
|
- value={category.heading.name}
|
|
|
|
- />
|
|
|
|
- ))}
|
|
|
|
- </ToggleButton.Group>
|
|
|
|
- </ScrollView>
|
|
|
|
- </View>
|
|
|
|
|
|
+ <ScrollView horizontal contentContainerStyle={styles.categoriesPillContainer} showsHorizontalScrollIndicator={false}>
|
|
|
|
+ <ToggleButton.Group
|
|
|
|
+ onValueChange={value => {
|
|
|
|
+ setCategoryValue(value)
|
|
|
|
+ }}>
|
|
|
|
+ {categories.map(category => (
|
|
|
|
+ <ToggleButton
|
|
|
|
+ key={category.heading.name}
|
|
|
|
+ icon={() => (
|
|
|
|
+ <Text
|
|
|
|
+ style={[
|
|
|
|
+ category.heading.name === categoryValue
|
|
|
|
+ ? styles.selectedPillText
|
|
|
|
+ : styles.pillText,
|
|
|
|
+ ]}>
|
|
|
|
+ {category.heading.name}
|
|
|
|
+ </Text>
|
|
|
|
+ )}
|
|
|
|
+ style={[
|
|
|
|
+ category.heading.name === categoryValue
|
|
|
|
+ ? styles.selectedContainer
|
|
|
|
+ : styles.container,
|
|
|
|
+ { marginHorizontal: horizontalScale(4) },
|
|
|
|
+ ]}
|
|
|
|
+ value={category.heading.name}
|
|
|
|
+ />
|
|
|
|
+ ))}
|
|
|
|
+ </ToggleButton.Group>
|
|
|
|
+ </ScrollView>
|
|
<View>
|
|
<View>
|
|
- <ScrollView showsVerticalScrollIndicator={false}>
|
|
|
|
- <View style={styles.categoriesNewsContainer}>
|
|
|
|
- {news[categoryValue] !== undefined ? (
|
|
|
|
- news[categoryValue].map(item => (
|
|
|
|
- <HorizontalNewsCardVariant
|
|
|
|
- headline={item.title}
|
|
|
|
- image={{uri: item.cover_image}}
|
|
|
|
- timestamp={item.published_on}
|
|
|
|
- tagline={""}
|
|
|
|
- onPress={() =>
|
|
|
|
- navigateToArticle(navigation, item.id, item.slug)
|
|
|
|
- }
|
|
|
|
- onSharePress={() => {
|
|
|
|
- onShare({
|
|
|
|
|
|
+ <ScrollView contentContainerStyle={styles.categoriesNewsContainer} showsVerticalScrollIndicator={false}>
|
|
|
|
+
|
|
|
|
+ {news[categoryValue] !== undefined ?
|
|
|
|
+ <FlatList
|
|
|
|
+ data={news[categoryValue]}
|
|
|
|
+ renderItem={newsObject =>
|
|
|
|
+ <HorizontalNewsCardVariant
|
|
|
|
+ headline={newsObject.item.title}
|
|
|
|
+ image={{ uri: newsObject.item.cover_image }}
|
|
|
|
+ timestamp={newsObject.item.published_on}
|
|
|
|
+ tagline={""}
|
|
|
|
+ onPress={() =>
|
|
|
|
+ navigateToArticle(navigation, newsObject.item.id, newsObject.item.slug)
|
|
|
|
+ }
|
|
|
|
+ onSharePress={() => {
|
|
|
|
+ onShare({
|
|
title: "Newscout",
|
|
title: "Newscout",
|
|
message: "Check out unbiased news in Newscout",
|
|
message: "Check out unbiased news in Newscout",
|
|
- url: NEWSCOUT_NEWS_URL(item.slug),
|
|
|
|
|
|
+ url: NEWSCOUT_NEWS_URL(newsObject.item.slug),
|
|
}).catch(err => console.error(err))
|
|
}).catch(err => console.error(err))
|
|
- .finally(() => console.log("Share Link Button"))
|
|
|
|
|
|
+ .finally(() => console.log("Share Link Button"))
|
|
}}
|
|
}}
|
|
- />
|
|
|
|
- ))
|
|
|
|
- ) : (
|
|
|
|
- <LoadingScreen containerHeight={240}/>
|
|
|
|
- )}
|
|
|
|
- </View>
|
|
|
|
|
|
+ />}
|
|
|
|
+
|
|
|
|
+ /> : (
|
|
|
|
+ <LoadingScreen containerHeight={240} />
|
|
|
|
+ )}
|
|
|
|
+
|
|
</ScrollView>
|
|
</ScrollView>
|
|
</View>
|
|
</View>
|
|
</>
|
|
</>
|