-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
91 additions
and
52 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React, { useCallback, useState } from 'react' | ||
import { FlatList } from 'react-native' | ||
import ArticleListItem from '../Common/ArticleListItem' | ||
|
||
const ArticleList = ({ articles, refetch, navigation }) => { | ||
const [refreshing, setRefreshing] = useState(false) | ||
|
||
const handleRefresh = useCallback(() => { | ||
setRefreshing(true) | ||
refetch().then(() => setRefreshing(false)) | ||
}, []) | ||
|
||
const renderItem = useCallback((info) => { | ||
return <ArticleListItem navigation={navigation} article={info.item} /> | ||
}, []) | ||
|
||
return <FlatList data={articles} renderItem={renderItem} keyExtractor={(item) => item._id} refreshing={refreshing} onRefresh={handleRefresh} /> | ||
} | ||
|
||
export default ArticleList |
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,23 @@ | ||
import gql from 'graphql-tag' | ||
|
||
export const GET_CATEGORIES_QUERY = gql` | ||
query headlineScreenQuery { | ||
getArticles { | ||
_id | ||
title | ||
shortDescription | ||
content | ||
link | ||
imageLink | ||
createdDate | ||
modifiedDate | ||
category | ||
tags | ||
totalWeight | ||
source { | ||
name | ||
logoLink | ||
} | ||
} | ||
} | ||
` |
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 |
---|---|---|
@@ -1,15 +1,30 @@ | ||
import React from 'react' | ||
import { createNativeStackNavigator } from '@react-navigation/native-stack' | ||
import MainScreen from './MainScreen' | ||
import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs' | ||
import { useQuery } from '@apollo/client' | ||
import ArticleList from './ArticleList' | ||
import { GET_CATEGORIES_QUERY } from './GET_CATEGORIES_QUERY' | ||
|
||
const Stack = createNativeStackNavigator() | ||
const Tab = createMaterialTopTabNavigator() | ||
|
||
const categoryTabs = ({ navigation }) => { | ||
const { loading, error, refetch, data } = useQuery(GET_CATEGORIES_QUERY) | ||
|
||
const articles = data?.getArticles | ||
|
||
const tabNames = ['news', 'entertainment', 'sports', 'cartoon', 'business', 'social', 'health', 'technology', 'share', 'agriculture'] | ||
|
||
const Home = () => { | ||
return ( | ||
<Stack.Navigator initialRouteName="Main" screenOptions={{ headerShown: false }}> | ||
<Stack.Screen name="MainScreen" component={MainScreen} /> | ||
</Stack.Navigator> | ||
<Tab.Navigator> | ||
{tabNames.map((tabname, index) => { | ||
const categoryArricles = articles?.filter((a) => a.category === tabname) | ||
return ( | ||
<Tab.Screen name={tabname} options={{ tabBarScrollEnabled: true, tabBarBounces: true }} key={index}> | ||
{() => <ArticleList articles={categoryArricles} refetch={refetch} navigation={navigation} />} | ||
</Tab.Screen> | ||
) | ||
})} | ||
</Tab.Navigator> | ||
) | ||
} | ||
|
||
export default Home | ||
export default categoryTabs |
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
src/screens/Home/ArticleListItem.tsx → src/screens/Common/ArticleListItem.tsx
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