diff --git a/assets/icon.png b/assets/icon.png index a0b1526..4edbdfe 100644 Binary files a/assets/icon.png and b/assets/icon.png differ diff --git a/src/app/(tabs)/home/index.tsx b/src/app/(tabs)/home/index.tsx index ddca1a3..67b4a51 100644 --- a/src/app/(tabs)/home/index.tsx +++ b/src/app/(tabs)/home/index.tsx @@ -11,7 +11,6 @@ import { import { SafeAreaView } from 'react-native-safe-area-context'; import styles from './styles'; -import Icon from '../../../../assets/icons'; import ContentCard from '../../../components/ContentCard/ContentCard'; import PreviewCard from '../../../components/PreviewCard/PreviewCard'; import { fetchUsername } from '../../../queries/profiles'; @@ -146,20 +145,18 @@ function HomeScreen() { {username ? `Welcome, ${username}` : 'Welcome!'} - router.push('/settings')}> - - - - {featuredStories.length > 0 && ( Featured Stories - - {featuredStoriesDescription} - - + {featuredStoriesDescription != null && + featuredStoriesDescription.length > 0 && ( + + {featuredStoriesDescription} + + )} + {featuredStories.map(story => ( ([]); + const [readingListStories, setReadingListStories] = useState( + [], + ); + const { channels } = usePubSub(); + let updateReadingListTimeout: NodeJS.Timeout | null = null; + + const favoritesPressed = () => { + setFavoritesSelected(true); + setReadingSelected(false); + }; + + const readingPressed = () => { + setFavoritesSelected(false); + setReadingSelected(true); + }; + + const renderItem = ({ item }: { item: StoryPreview }) => { + return ( + + + router.push({ + pathname: '/story', + params: { storyId: item.id.toString() }, + }) + } + /> + + ); + }; + + useEffect(() => { + if (updateReadingListTimeout) { + clearTimeout(updateReadingListTimeout); + } + + updateReadingListTimeout = setTimeout( + () => + fetchUserStoriesReadingList(user?.id).then(readingList => { + setReadingListStories(readingList); + }), + 5000, + ); + }, [channels]); + + useEffect(() => { + (async () => { + await Promise.all([ + fetchUserStoriesFavorites(user?.id).then(favorites => + setFavoriteStories(favorites), + ), + fetchUserStoriesReadingList(user?.id).then(readingList => { + setReadingListStories(readingList); + }), + ]); + })(); + }, [user]); + return ( - - Library - + + + + + + + + + Favorites + + + + + + + + + Reading List + + + + + + + + {favoritesSelected && + (favoriteStories.length > 0 ? ( + + ) : ( + + + Favorited stories + + + will appear here. + + + ))} + + {readingSelected && + (readingListStories.length > 0 ? ( + + ) : ( + + + Saved stories + + + will appear here. + + + ))} + + ); } diff --git a/src/app/(tabs)/library/styles.ts b/src/app/(tabs)/library/styles.ts index ebaf5c7..5da69e4 100644 --- a/src/app/(tabs)/library/styles.ts +++ b/src/app/(tabs)/library/styles.ts @@ -1,5 +1,43 @@ import { StyleSheet } from 'react-native'; +import colors from '../../../styles/colors'; -const styles = StyleSheet.create({}); +const styles = StyleSheet.create({ + container: { + flex: 1, + backgroundColor: 'white', + alignItems: 'flex-start', + justifyContent: 'flex-start', + }, + selector: { + display: 'flex', + width: '100%', + flexDirection: 'row', + justifyContent: 'space-around', + backgroundColor: '#fbfbfb', + marginBottom: 24, + }, + header: { + paddingHorizontal: 24, + marginBottom: 24, + marginTop: 60, + }, + selectedText: { + textAlign: 'center', + color: colors.gwnOrange, + paddingVertical: 8, + }, + unselectedText: { + textAlign: 'center', + color: colors.black, + paddingVertical: 8, + }, + selectedButton: { + borderBottomWidth: 1, + borderBottomColor: colors.gwnOrange, + }, + scrollView: { + width: '100%', + }, +}); export default styles; diff --git a/src/components/LibraryHeader/LibraryHeader.tsx b/src/components/LibraryHeader/LibraryHeader.tsx new file mode 100644 index 0000000..e9e4a19 --- /dev/null +++ b/src/components/LibraryHeader/LibraryHeader.tsx @@ -0,0 +1,35 @@ +import { View, Text, Image, Pressable } from 'react-native'; +import { router } from 'expo-router'; +import { useEffect, useState } from 'react'; +import Icon from '../../../assets/icons'; + +import styles from './styles'; +import globalStyles from '../../styles/globalStyles'; +import colors from '../../styles/colors'; +import { useSession } from '../../utils/AuthContext'; + +export default function LibraryHeader() { + const { user } = useSession(); + + return ( + + + + + {user?.user_metadata.username} + + + + + router.push('/settings')}> + + + + + + + ); +} diff --git a/src/components/LibraryHeader/styles.ts b/src/components/LibraryHeader/styles.ts new file mode 100644 index 0000000..a3aafbb --- /dev/null +++ b/src/components/LibraryHeader/styles.ts @@ -0,0 +1,31 @@ +import { StyleSheet } from 'react-native'; +import colors from '../../styles/colors'; + +const styles = StyleSheet.create({ + container: { + display: 'flex', + flexGrow: 1, + width: '100%', + }, + image: { + height: 51, + width: 51, + borderRadius: 51 / 2, + marginBottom: 12, + }, + textContainer: { + flexDirection: 'row', + }, + username: { + paddingLeft: 12, + }, + horizontal: { + display: 'flex', + flexDirection: 'row', + justifyContent: 'space-between', + width: '100%', + alignContent: 'center', + }, +}); + +export default styles; diff --git a/src/components/PreviewCard/PreviewCard.tsx b/src/components/PreviewCard/PreviewCard.tsx index f561cd4..8302d48 100644 --- a/src/components/PreviewCard/PreviewCard.tsx +++ b/src/components/PreviewCard/PreviewCard.tsx @@ -26,6 +26,7 @@ type PreviewCardProps = { storyId: number; author: string; authorImage: string; + defaultSavedStoriesState?: boolean; excerpt: { html: string }; tags: string[]; reactions?: string[] | null; @@ -40,6 +41,7 @@ function PreviewCard({ authorImage, excerpt, tags, + defaultSavedStoriesState = false, pressFunction, reactions: preloadedReactions = null, }: PreviewCardProps) { @@ -68,8 +70,13 @@ 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 a9578b4..5ab847d 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,27 @@ 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_string: 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 get 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]); - } - } + // console.log(data[0]); + // console.log("As preview:"); + // console.log(data[0] as StoryPreview) + // console.log(data as StoryPreview[]); - return storyData; + return data as StoryPreview[]; } export async function fetchUserStoriesFavorites(user_id: string | undefined) {