diff --git a/src/app/(tabs)/library/index.tsx b/src/app/(tabs)/library/index.tsx
index 1afb38f..5f5d9f4 100644
--- a/src/app/(tabs)/library/index.tsx
+++ b/src/app/(tabs)/library/index.tsx
@@ -13,6 +13,7 @@ import {
fetchUserStoriesFavorites,
fetchUserStoriesReadingList,
} from '../../../queries/savedStories';
+import { FlatList } from 'react-native-gesture-handler';
function LibraryScreen() {
const { user } = useSession();
@@ -26,22 +27,25 @@ function LibraryScreen() {
const favoritesPressed = () => {
setFavoritesSelected(true);
setReadingSelected(false);
+ console.log(favoriteStories);
};
const readingPressed = () => {
setFavoritesSelected(false);
setReadingSelected(true);
+ console.log(readingListStories);
};
useEffect(() => {
(async () => {
- const [favoriteStoriesResponse, readingListStoriesResponse] =
- await Promise.all([
- fetchUserStoriesFavorites(user?.id).catch(() => []),
- fetchUserStoriesReadingList(user?.id).catch(() => []),
- ]);
- setFavoriteStories(favoriteStoriesResponse);
- setReadingListStories(readingListStoriesResponse);
+ await Promise.all([
+ fetchUserStoriesFavorites(user?.id).catch(favorites =>
+ setFavoriteStories(favorites),
+ ),
+ fetchUserStoriesReadingList(user?.id).catch(readingList =>
+ setReadingListStories(readingList),
+ ),
+ ]);
})().finally(() => {});
}, [user]);
@@ -88,45 +92,61 @@ function LibraryScreen() {
>
{favoritesSelected && favoriteStories.length > 0 && (
- {favoriteStories.map(story => (
-
- router.push({
- pathname: '/story',
- params: { storyId: story.id.toString() },
- })
- }
- />
- ))}
+ {
+ return (
+
+ router.push({
+ pathname: '/story',
+ params: { storyId: item.id.toString() },
+ })
+ }
+ />
+ );
+ }}
+ />
)}
{readingSelected && readingListStories.length > 0 && (
- {readingListStories.map(story => (
-
- router.push({
- pathname: '/story',
- params: { storyId: story.id.toString() },
- })
- }
- />
- ))}
+ {
+ return (
+
+ router.push({
+ pathname: '/story',
+ params: { storyId: item.id.toString() },
+ })
+ }
+ />
+ );
+ }}
+ />
)}
diff --git a/src/components/PreviewCard/PreviewCard.tsx b/src/components/PreviewCard/PreviewCard.tsx
index 71d6d05..0bfba46 100644
--- a/src/components/PreviewCard/PreviewCard.tsx
+++ b/src/components/PreviewCard/PreviewCard.tsx
@@ -44,8 +44,10 @@ function PreviewCard({
{title}
-
-
+
+
+
+
diff --git a/src/components/PreviewCard/styles.ts b/src/components/PreviewCard/styles.ts
index d8d3ef1..e3e9b92 100644
--- a/src/components/PreviewCard/styles.ts
+++ b/src/components/PreviewCard/styles.ts
@@ -44,7 +44,9 @@ const styles = StyleSheet.create({
marginBottom: 12,
},
title: {
- marginBottom: 8,
+ flex: 1,
+ alignSelf: 'flex-start',
+ // marginBottom: 8,
},
titleContainer: {
paddingTop: 16,
@@ -54,8 +56,7 @@ const styles = StyleSheet.create({
borderBottomColor: '#EBEBEB',
borderBottomWidth: StyleSheet.hairlineWidth,
flexDirection: 'row',
- flexGrow: 1,
- justifyContent: 'space-between',
+ flex: 1,
},
tag: {
paddingHorizontal: 8,
diff --git a/src/queries/savedStories.tsx b/src/queries/savedStories.tsx
index 0416ecb..a61b10c 100644
--- a/src/queries/savedStories.tsx
+++ b/src/queries/savedStories.tsx
@@ -1,4 +1,5 @@
import supabase from '../utils/supabase';
+import { StoryPreview } from './types';
enum SavedList {
FAVORITES = 'favorites',
@@ -9,44 +10,23 @@ async function fetchUserStories(
user_id: string | undefined,
name: string | undefined,
) {
- const { data: storyObjects, error } = await supabase
- .from('saved_stories')
- .select('story_id')
- .eq('user_id', user_id)
- .eq('name', name);
+ let { data, error } = await supabase.rpc('get_saved_stories_for_user', {
+ user_id,
+ saved_list_name: name,
+ });
if (error) {
if (process.env.NODE_ENV !== 'production') {
throw new Error(
- `An error occured when trying to fetch user saved stories: ${JSON.stringify(
+ `An error occured when trying to set user saved stories: ${JSON.stringify(
error,
)}`,
);
}
- return [];
- }
-
- let storyData = [];
- for (const storyObject of storyObjects) {
- const storyId = storyObject['story_id'];
- const { data, error } = await supabase.rpc('fetch_story', {
- input_id: storyId,
- });
-
- if (error || data.length == 0) {
- if (process.env.NODE_ENV !== 'production') {
- throw new Error(
- `An error occured when trying to use rpc to get story data: ${JSON.stringify(
- error,
- )}`,
- );
- }
- } else {
- storyData.push(data[0]);
- }
}
- return storyData;
+ console.log(data[0]);
+ return data as StoryPreview[];
}
export async function fetchUserStoriesFavorites(user_id: string | undefined) {