diff --git a/src/app/(tabs)/home/index.tsx b/src/app/(tabs)/home/index.tsx index eac0a4a..c7c920c 100644 --- a/src/app/(tabs)/home/index.tsx +++ b/src/app/(tabs)/home/index.tsx @@ -150,7 +150,7 @@ function HomeScreen() { {featuredStories.length > 0 && ( Featured Stories - {featuredStoriesDescription.length > 0 && ( + {featuredStoriesDescription != null && featuredStoriesDescription.length > 0 && ( {featuredStoriesDescription} diff --git a/src/app/(tabs)/library/index.tsx b/src/app/(tabs)/library/index.tsx index 8f086e2..9390099 100644 --- a/src/app/(tabs)/library/index.tsx +++ b/src/app/(tabs)/library/index.tsx @@ -13,6 +13,7 @@ import { fetchUserStoriesReadingList, } from '../../../queries/savedStories'; import { FlatList } from 'react-native-gesture-handler'; +import { usePubSub } from '../../../utils/PubSubContext'; function LibraryScreen() { const { user } = useSession(); @@ -22,19 +23,50 @@ function LibraryScreen() { const [readingListStories, setReadingListStories] = useState( [], ); + const { channels } = usePubSub(); const favoritesPressed = () => { setFavoritesSelected(true); setReadingSelected(false); - console.log(favoriteStories); }; const readingPressed = () => { setFavoritesSelected(false); setReadingSelected(true); - console.log(readingListStories); }; + const renderItem = ({ item }: { item: StoryPreview }) => { + return ( + + + router.push({ + pathname: '/story', + params: { storyId: item.id.toString() }, + }) + } + /> + + ); + } + + useEffect(() => { + setTimeout(() => fetchUserStoriesReadingList(user?.id).then(readingList => { + setReadingListStories(readingList); + }), 3000) + }, [channels]) + useEffect(() => { (async () => { await Promise.all([ @@ -42,7 +74,6 @@ function LibraryScreen() { setFavoriteStories(favorites), ), fetchUserStoriesReadingList(user?.id).then(readingList => { - console.log(readingList); setReadingListStories(readingList); }), ]); @@ -85,66 +116,41 @@ function LibraryScreen() { - {favoritesSelected && ( - { - return ( - - - router.push({ - pathname: '/story', - params: { storyId: item.id.toString() }, - }) - } - /> - - ); - }} - /> - )} + {favoritesSelected && + ( + favoriteStories.length > 0 ? ( + + ) : ( + + + Favorited stories + + + will appear here. + + ) + )} - {readingSelected && ( - { - return ( - - - router.push({ - pathname: '/story', - params: { storyId: item.id.toString() }, - }) - } - /> - - ); - }} - /> - )} + {readingSelected && + ( + readingListStories.length > 0 ? ( + + ) : ( + + + Saved stories + + + will appear here. + + ) + )} ); diff --git a/src/queries/savedStories.tsx b/src/queries/savedStories.tsx index 9cb3e56..9decdc6 100644 --- a/src/queries/savedStories.tsx +++ b/src/queries/savedStories.tsx @@ -11,14 +11,14 @@ async function fetchUserStories( name: string | undefined, ) { let { data, error } = await supabase.rpc('get_saved_stories_for_user', { - user_id, - saved_list_name: name, + user_id_string: user_id, + saved_list_name: name }); if (error) { if (process.env.NODE_ENV !== 'production') { throw new Error( - `An error occured when trying to set user saved stories: ${JSON.stringify( + `An error occured when trying to get user saved stories: ${JSON.stringify( error, )}`, );