Skip to content

Commit

Permalink
fix(recommendations): uses query response directly for recommendations
Browse files Browse the repository at this point in the history
  • Loading branch information
oahnh committed Apr 16, 2024
1 parent 7b9de74 commit 3c181e6
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/app/(tabs)/home/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import AsyncStorage from '@react-native-async-storage/async-storage';
import { router } from 'expo-router';
import { useEffect, useState } from 'react';
import { Pressable, ScrollView, Text, View } from 'react-native';
Expand All @@ -7,7 +8,6 @@ import styles from './styles';
import Icon from '../../../../assets/icons';
import ContentCard from '../../../components/ContentCard/ContentCard';
import PreviewCard from '../../../components/PreviewCard/PreviewCard';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { fetchUsername } from '../../../queries/profiles';
import {
fetchFeaturedStoriesDescription,
Expand Down Expand Up @@ -51,36 +51,48 @@ function HomeScreen() {
}
};

const getRecommendedStories = async () => {
const recentStoryResponse = await getRecentStory();
// console.log('recentStoryResponse', recentStoryResponse);
// setRecentlyViewed(recentStoryResponse);
// console.log('state: recentlyViewed', recentlyViewed);
const recommendedStoriesResponse =
await fetchRecommendedStories(recentStoryResponse);
setRecommendedStories(recommendedStoriesResponse);
// return recommendedStoriesResponse;
};

(async () => {
const [
usernameResponse,
featuredStoryResponse,
featuredStoryDescriptionResponse,
recommendedStoriesResponse,
// recommendedStoriesResponse,
newStoriesResponse,
recentStoryResponse,
// recentStoryResponse,
] = await Promise.all([
fetchUsername(user?.id).catch(() => ''),
fetchFeaturedStoryPreviews().catch(() => []),
fetchFeaturedStoriesDescription().catch(() => ''),
fetchRecommendedStories(recentlyViewed).catch(() => []),
// fetchRecommendedStories(recentlyViewed).catch(() => []), // need to set recentlyViewed before
fetchNewStories().catch(() => []),
getRecentStory(),
// getRecentStory(),
]);
setUsername(usernameResponse);
setFeaturedStories(featuredStoryResponse);
setFeaturedStoriesDescription(featuredStoryDescriptionResponse);
setRecommendedStories(recommendedStoriesResponse);
// setRecommendedStories(recommendedStoriesResponse);
setNewStories(newStoriesResponse);
setRecentlyViewed(recentStoryResponse);
// setRecentlyViewed(recentStoryResponse);
await getRecommendedStories();
})().finally(() => {
setLoading(false);
});
}, [user]);

useEffect(() => {}, []);

console.log(recommendedStories);
// console.log(recommendedStories);
return (
<SafeAreaView
style={[globalStyles.container, { marginLeft: -8, marginRight: -32 }]}
Expand Down

0 comments on commit 3c181e6

Please sign in to comment.