From 0fb682b86655061c8c5c2059f1ff510068f19072 Mon Sep 17 00:00:00 2001 From: Burhan YILMAZ Date: Mon, 15 Jan 2024 00:10:08 +0300 Subject: [PATCH] feat: added explore tab - updated activity indicator color - refactored components --- .../BlogTabHeader/BlogTabHeaderGoBack.tsx | 4 + src/components/Post/PostCard.tsx | 23 +++--- src/components/core/Button.tsx | 3 +- src/components/core/Input.tsx | 24 +++--- src/hooks/useDebounce.ts | 17 ++++ src/navigators/BlogNavigator.tsx | 3 +- src/screens/Blog/ExploreScreen.tsx | 49 ++++++++++++ src/screens/Blog/HomeScreen.tsx | 9 ++- src/screens/Welcome/index.tsx | 3 +- src/services/Api.ts | 11 ++- src/store/PostStore.ts | 6 +- src/store/SearchStore.ts | 80 +++++++++++++++++++ src/theme/colors.js | 13 +++ 13 files changed, 218 insertions(+), 27 deletions(-) create mode 100644 src/hooks/useDebounce.ts create mode 100644 src/screens/Blog/ExploreScreen.tsx create mode 100644 src/store/SearchStore.ts diff --git a/src/components/BlogTabHeader/BlogTabHeaderGoBack.tsx b/src/components/BlogTabHeader/BlogTabHeaderGoBack.tsx index e474998..f68bc6e 100644 --- a/src/components/BlogTabHeader/BlogTabHeaderGoBack.tsx +++ b/src/components/BlogTabHeader/BlogTabHeaderGoBack.tsx @@ -5,6 +5,10 @@ import { Pressable } from 'react-native'; const BlogTabHeaderGoBack = () => { const { dispatch } = useNavigation(); + if (!__DEV__) { + return null; + } + return ( dispatch(StackActions.popToTop)}> diff --git a/src/components/Post/PostCard.tsx b/src/components/Post/PostCard.tsx index 37423f5..10d0dcf 100644 --- a/src/components/Post/PostCard.tsx +++ b/src/components/Post/PostCard.tsx @@ -15,7 +15,7 @@ const CARD_IMAGE_WIDTH = (width - 40) * 0.3; const CARD_IMAGE_HEIGHT = (width - 40) * 0.35; type Props = { - title: string; + title?: string; image?: string; category?: string; onPressPost: () => void; @@ -25,22 +25,27 @@ type Props = { const PostCard = ({ image, title, category, onPressPost, onPressSave }: Props) => ( - + {image ? ( ) : ( )} - - - {category} + + + + {category} + + + {title} + - - {title} - - + diff --git a/src/components/core/Button.tsx b/src/components/core/Button.tsx index cb35d66..eb52794 100644 --- a/src/components/core/Button.tsx +++ b/src/components/core/Button.tsx @@ -1,3 +1,4 @@ +import colors from '@theme/colors'; import { text } from '@theme/text'; import { ActivityIndicator, Text, TouchableOpacity } from 'react-native'; @@ -10,7 +11,7 @@ type Props = { const Button = ({ title, onPress, isLoading }: Props) => ( {isLoading ? ( - + ) : ( {title} diff --git a/src/components/core/Input.tsx b/src/components/core/Input.tsx index 6d640ec..7281fd5 100644 --- a/src/components/core/Input.tsx +++ b/src/components/core/Input.tsx @@ -1,20 +1,26 @@ -import { TextInput } from 'react-native'; +import { ReactNode } from 'react'; +import { TextInput, View } from 'react-native'; type Props = { value?: string; placeholder?: string; + rightIcon?: ReactNode; containerClass?: string; - onPressClose?: () => void; onChangeText: (value: string) => void; }; -const Input = ({ value, containerClass, placeholder, onChangeText }: Props) => ( - +const Input = ({ value, containerClass, placeholder, onChangeText, rightIcon }: Props) => ( + + + {rightIcon ? ( + {rightIcon} + ) : null} + ); export default Input; diff --git a/src/hooks/useDebounce.ts b/src/hooks/useDebounce.ts new file mode 100644 index 0000000..c3a4bde --- /dev/null +++ b/src/hooks/useDebounce.ts @@ -0,0 +1,17 @@ +import { useEffect, useState } from 'react'; + +const useDebounce = (value: string, delay: number) => { + const [debouncedValue, setDebouncedValue] = useState(value); + + useEffect(() => { + const handler = setTimeout(() => { + setDebouncedValue(value); + }, delay); + + return () => clearTimeout(handler); + }, [value]); + + return debouncedValue; +}; + +export default useDebounce; diff --git a/src/navigators/BlogNavigator.tsx b/src/navigators/BlogNavigator.tsx index 92d06a2..26014a9 100644 --- a/src/navigators/BlogNavigator.tsx +++ b/src/navigators/BlogNavigator.tsx @@ -4,6 +4,7 @@ import BlogTabHeaderTitle from '@components/BlogTabHeader/BlogTabHeaderTitle'; import BottomTab from '@components/BottomTab'; import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; +import ExploreScreen from '@screens/Blog/ExploreScreen'; import BlogHomeScreen from '@screens/Blog/HomeScreen'; import TestScreen from '@screens/Test'; @@ -33,7 +34,7 @@ const BlogTab = () => ( headerTitle: props => , }}> - + ); diff --git a/src/screens/Blog/ExploreScreen.tsx b/src/screens/Blog/ExploreScreen.tsx new file mode 100644 index 0000000..978d370 --- /dev/null +++ b/src/screens/Blog/ExploreScreen.tsx @@ -0,0 +1,49 @@ +import Input from '@components/core/Input'; +import Post from '@containers/Post'; +import useDebounce from '@hooks/useDebounce'; +import searchStore from '@store/SearchStore'; +import colors from '@theme/colors'; +import { Search } from 'lucide-react-native'; +import { observer } from 'mobx-react-lite'; +import { useEffect } from 'react'; +import { ActivityIndicator, FlatList, SafeAreaView, View } from 'react-native'; + +const ExploreScreen = () => { + const value = useDebounce(searchStore.term, 300); + + useEffect(() => { + if (value.length > 2) { + searchStore.searchPost(); + } + }, [value]); + + return ( + + + + ) : ( + + ) + } + /> + + + } + /> + + ); +}; + +export default observer(ExploreScreen); diff --git a/src/screens/Blog/HomeScreen.tsx b/src/screens/Blog/HomeScreen.tsx index eab90fc..ba2e068 100644 --- a/src/screens/Blog/HomeScreen.tsx +++ b/src/screens/Blog/HomeScreen.tsx @@ -1,5 +1,6 @@ import Post from '@containers/Post'; import postStore, { PostType } from '@store/PostStore'; +import colors from '@theme/colors'; import { observer } from 'mobx-react-lite'; import { useEffect } from 'react'; import { ActivityIndicator, FlatList, ListRenderItem, View } from 'react-native'; @@ -19,7 +20,11 @@ const BlogHomeScreen = () => { return ( {postStore.loading && posts.length > 0 && ( - + )} { maxToRenderPerBatch={6} renderItem={RenderItem} onEndReached={postStore.increasePage} - ListEmptyComponent={} + ListEmptyComponent={} /> ); diff --git a/src/screens/Welcome/index.tsx b/src/screens/Welcome/index.tsx index fd7437d..6349bb1 100644 --- a/src/screens/Welcome/index.tsx +++ b/src/screens/Welcome/index.tsx @@ -49,10 +49,11 @@ const WelcomeScreen = () => { +