-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- updated activity indicator color - refactored components
- Loading branch information
1 parent
1d36341
commit 0fb682b
Showing
13 changed files
with
218 additions
and
27 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
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,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) => ( | ||
<TextInput | ||
value={value} | ||
placeholder={placeholder} | ||
onChangeText={onChangeText} | ||
className={`border-[2px] rounded-lg h-[50px] border-zinc-700 text-zinc-600 px-4 pr-10 font-Medium bg-white ${containerClass}`} | ||
/> | ||
const Input = ({ value, containerClass, placeholder, onChangeText, rightIcon }: Props) => ( | ||
<View className=""> | ||
<TextInput | ||
value={value} | ||
placeholder={placeholder} | ||
onChangeText={onChangeText} | ||
className={`border-[2px] rounded-lg h-[50px] border-zinc-700 text-zinc-600 px-4 pr-10 font-Medium bg-white ${containerClass}`} | ||
/> | ||
{rightIcon ? ( | ||
<View className="justify-center items-center absolute right-4 h-full z-50">{rightIcon}</View> | ||
) : null} | ||
</View> | ||
); | ||
|
||
export default Input; |
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,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; |
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,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 ( | ||
<SafeAreaView className="bg-white flex-1"> | ||
<View className="px-4 mb-4"> | ||
<Input | ||
placeholder="Search..." | ||
onChangeText={searchStore.setTerm} | ||
rightIcon={ | ||
searchStore.loading ? ( | ||
<ActivityIndicator className="" color={colors.zinc[800]} /> | ||
) : ( | ||
<Search className="text-zinc-600" /> | ||
) | ||
} | ||
/> | ||
</View> | ||
|
||
<FlatList | ||
windowSize={6} | ||
className="px-5 pt-4" | ||
removeClippedSubviews | ||
initialNumToRender={6} | ||
maxToRenderPerBatch={6} | ||
data={searchStore.listResult || []} | ||
renderItem={({ item }) => <Post post={item} />} | ||
/> | ||
</SafeAreaView> | ||
); | ||
}; | ||
|
||
export default observer(ExploreScreen); |
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
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,80 @@ | ||
import { api } from '@services/Api'; | ||
import { removeHtmlAndDecimalEntities } from '@utils/helpers'; | ||
import { ApiPostType } from '@utils/types/BlogTypes'; | ||
import { Instance, detach, t } from 'mobx-state-tree'; | ||
|
||
import postStore, { Post } from './PostStore'; | ||
|
||
const SearchStore = t | ||
.model('SearchStore', { | ||
term: t.string, | ||
results: t.map(Post), | ||
loading: t.optional(t.boolean, false), | ||
}) | ||
.views(self => ({ | ||
get listResult() { | ||
return Array.from(self.results.values()); | ||
}, | ||
})) | ||
.actions(self => ({ | ||
addPost: (post: ApiPostType) => { | ||
self.results.set( | ||
post.id, | ||
Post.create({ | ||
id: post.id.toString(), | ||
mediaUrl: post?._links?.['wp:featuredmedia']?.[0]?.href || '', | ||
title: removeHtmlAndDecimalEntities(post?.title?.rendered || ''), | ||
category: removeHtmlAndDecimalEntities(post?.primary_category?.name || ''), | ||
}), | ||
); | ||
}, | ||
|
||
setTerm(term: string) { | ||
self.term = term; | ||
}, | ||
|
||
setLoading(loading: boolean) { | ||
self.loading = loading; | ||
}, | ||
|
||
clearResult() { | ||
detach(self.results); | ||
}, | ||
|
||
async searchPost() { | ||
if (!postStore.url) { | ||
return; | ||
} | ||
|
||
this.setLoading(true); | ||
try { | ||
const posts = await api.searchPost(self.term); | ||
this.clearResult(); | ||
if (posts?.length > 0) { | ||
posts.forEach(this.addPost); | ||
} | ||
|
||
this.setLoading(false); | ||
|
||
return posts; | ||
} catch { | ||
this.setLoading(false); | ||
|
||
return []; | ||
} | ||
}, | ||
|
||
clearAll() { | ||
self.term = ''; | ||
self.loading = false; | ||
self.results.clear(); | ||
}, | ||
})); | ||
|
||
const searchStore = SearchStore.create({ | ||
term: '', | ||
}); | ||
|
||
export default searchStore; | ||
|
||
export type PostType = Instance<typeof Post>; |
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,4 +1,17 @@ | ||
module.exports = { | ||
white: '#ffffff', | ||
black: '#000000', | ||
zinc: { | ||
50: '#fafafa', | ||
100: '#f4f4f5', | ||
200: '#e4e4e7', | ||
300: '#d4d4d8', | ||
400: '#a1a1aa', | ||
500: '#71717a', | ||
600: '#52525b', | ||
700: '#3f3f46', | ||
800: '#27272a', | ||
900: '#18181b', | ||
950: '#09090b', | ||
}, | ||
}; |