-
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.
- add empty list component for saved and explore
- Loading branch information
1 parent
0fb682b
commit e73f542
Showing
5 changed files
with
91 additions
and
5 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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import Post from '@containers/Post'; | ||
import savedStore from '@store/SavedStore'; | ||
import { text } from '@theme/text'; | ||
import { BookMarked } from 'lucide-react-native'; | ||
import { observer } from 'mobx-react-lite'; | ||
import { FlatList, SafeAreaView, Text, View } from 'react-native'; | ||
|
||
const SavedScreen = () => { | ||
const ListEmpty = () => ( | ||
<View className="items-center mt-4"> | ||
<BookMarked className="text-zinc-500 mb-2" size={28} /> | ||
<Text className={text({ type: 'subtitle', class: 'text-zinc-600' })}> | ||
There is no saved posts. | ||
</Text> | ||
</View> | ||
); | ||
|
||
return ( | ||
<SafeAreaView className="bg-white flex-1"> | ||
<FlatList | ||
windowSize={6} | ||
className="px-5 pt-4" | ||
removeClippedSubviews | ||
initialNumToRender={6} | ||
maxToRenderPerBatch={6} | ||
ListEmptyComponent={ListEmpty} | ||
data={savedStore.listResult || []} | ||
renderItem={({ item }) => <Post post={item} />} | ||
/> | ||
</SafeAreaView> | ||
); | ||
}; | ||
|
||
export default observer(SavedScreen); |
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,42 @@ | ||
import { destroy, t } from 'mobx-state-tree'; | ||
|
||
import { Post, PostType } from './PostStore'; | ||
|
||
const SavedStore = t | ||
.model('SavedStore', { | ||
saved: t.map(Post), | ||
}) | ||
.views(self => ({ | ||
get listResult() { | ||
return Array.from(self.saved.values()); | ||
}, | ||
})) | ||
.actions(self => ({ | ||
addPost: (post: PostType) => { | ||
const savedPost = self.saved.get(post.id); | ||
if (savedPost) { | ||
destroy(savedPost); | ||
|
||
return; | ||
} | ||
self.saved.set( | ||
post.id, | ||
Post.create({ | ||
id: post.id, | ||
mediaUrl: post.mediaUrl, | ||
title: post.title, | ||
category: post.category, | ||
image: post.image, | ||
imageLoaded: post.imageLoaded, | ||
}), | ||
); | ||
}, | ||
|
||
clearAll() { | ||
self.saved.clear(); | ||
}, | ||
})); | ||
|
||
const savedStore = SavedStore.create({}); | ||
|
||
export default savedStore; |