Skip to content

Commit

Permalink
Finish library screen
Browse files Browse the repository at this point in the history
  • Loading branch information
adityapawar1 committed Apr 21, 2024
1 parent 93f26a3 commit b1f6185
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 48 deletions.
Binary file modified assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 6 additions & 5 deletions src/app/(tabs)/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,12 @@ function HomeScreen() {
{featuredStories.length > 0 && (
<View>
<Text style={globalStyles.h3}>Featured Stories</Text>
{featuredStoriesDescription != null && featuredStoriesDescription.length > 0 && (
<Text style={[globalStyles.body1, styles.featuredDescription]}>
{featuredStoriesDescription}
</Text>
)}
{featuredStoriesDescription != null &&
featuredStoriesDescription.length > 0 && (
<Text style={[globalStyles.body1, styles.featuredDescription]}>
{featuredStoriesDescription}
</Text>
)}
<View style={{ marginRight: 24, marginTop: 16 }}>
{featuredStories.map(story => (
<PreviewCard
Expand Down
79 changes: 39 additions & 40 deletions src/app/(tabs)/library/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function LibraryScreen() {
[],
);
const { channels } = usePubSub();
let updateReadingListTimeout: NodeJS.Timeout | null = null;

const favoritesPressed = () => {
setFavoritesSelected(true);
Expand All @@ -47,9 +48,7 @@ function LibraryScreen() {
author={item.author_name}
authorImage={item.author_image}
excerpt={item.excerpt}
tags={item.genre_medium
.concat(item.tone)
.concat(item.topic)}
tags={item.genre_medium.concat(item.tone).concat(item.topic)}
pressFunction={() =>
router.push({
pathname: '/story',
Expand All @@ -59,13 +58,21 @@ function LibraryScreen() {
/>
</View>
);
}
};

useEffect(() => {
setTimeout(() => fetchUserStoriesReadingList(user?.id).then(readingList => {
setReadingListStories(readingList);
}), 3000)
}, [channels])
if (updateReadingListTimeout) {
clearTimeout(updateReadingListTimeout);
}

updateReadingListTimeout = setTimeout(
() =>
fetchUserStoriesReadingList(user?.id).then(readingList => {
setReadingListStories(readingList);
}),
5000,
);
}, [channels]);

useEffect(() => {
(async () => {
Expand Down Expand Up @@ -117,40 +124,32 @@ function LibraryScreen() {

<View style={{ width: '100%', flex: 1, marginBottom: 100 }}>
{favoritesSelected &&
(
favoriteStories.length > 0 ? (
<FlatList
data={favoriteStories}
renderItem={renderItem}
/>
) : (
<View style={{ paddingBottom: 16 }}>
<Text style={[globalStyles.h3, { textAlign: 'center' }]}>
Favorited stories
</Text>
<Text style={[globalStyles.h3, { textAlign: 'center' }]}>
will appear here.
</Text>
</View>)
)}
(favoriteStories.length > 0 ? (
<FlatList data={favoriteStories} renderItem={renderItem} />
) : (
<View style={{ paddingBottom: 16 }}>
<Text style={[globalStyles.h3, { textAlign: 'center' }]}>
Favorited stories
</Text>
<Text style={[globalStyles.h3, { textAlign: 'center' }]}>
will appear here.
</Text>
</View>
))}

{readingSelected &&
(
readingListStories.length > 0 ? (
<FlatList
data={readingListStories}
renderItem={renderItem}
/>
) : (
<View style={{ paddingBottom: 16 }}>
<Text style={[globalStyles.h3, { textAlign: 'center' }]}>
Saved stories
</Text>
<Text style={[globalStyles.h3, { textAlign: 'center' }]}>
will appear here.
</Text>
</View>)
)}
(readingListStories.length > 0 ? (
<FlatList data={readingListStories} renderItem={renderItem} />
) : (
<View style={{ paddingBottom: 16 }}>
<Text style={[globalStyles.h3, { textAlign: 'center' }]}>
Saved stories
</Text>
<Text style={[globalStyles.h3, { textAlign: 'center' }]}>
will appear here.
</Text>
</View>
))}
</View>
</View>
);
Expand Down
3 changes: 1 addition & 2 deletions src/components/LibraryHeader/LibraryHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ export default function LibraryHeader() {
<View style={styles.textContainer}>
<Image
style={styles.image}
//rendering the logo for now but this will change to the user's profile picture
source={require('../../../assets/logo.png')}
source={require('../../../assets/icon.png')}
/>
<View style={styles.username}>
<Text style={globalStyles.h1}>{user?.user_metadata.username} </Text>
Expand Down
2 changes: 1 addition & 1 deletion src/queries/savedStories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async function fetchUserStories(
) {
let { data, error } = await supabase.rpc('get_saved_stories_for_user', {
user_id_string: user_id,
saved_list_name: name
saved_list_name: name,
});

if (error) {
Expand Down

0 comments on commit b1f6185

Please sign in to comment.