From 22dd7c9a0a2bcbb92bae1d83d5b9aa365d10e41a Mon Sep 17 00:00:00 2001 From: Marcos Hernandez Date: Sun, 12 Nov 2023 15:47:26 -0800 Subject: [PATCH 1/8] accidently forgot to branch --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 36bbe3af..d85cab47 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,7 @@ "@mui/material": "^5.14.13", "@mui/styled-engine-sc": "^6.0.0-alpha.1", "@mui/system": "^5.14.13", - "@react-native-async-storage/async-storage": "1.18.2", + "@react-native-async-storage/async-storage": "^1.18.2", "@react-native-community/datetimepicker": "7.2.0", "@react-navigation/bottom-tabs": "^6.5.9", "@react-navigation/material-bottom-tabs": "^6.2.17", diff --git a/package.json b/package.json index 2d951965..d978c864 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "@mui/material": "^5.14.13", "@mui/styled-engine-sc": "^6.0.0-alpha.1", "@mui/system": "^5.14.13", - "@react-native-async-storage/async-storage": "1.18.2", + "@react-native-async-storage/async-storage": "^1.18.2", "@react-native-community/datetimepicker": "7.2.0", "@react-navigation/bottom-tabs": "^6.5.9", "@react-navigation/material-bottom-tabs": "^6.2.17", From 17de10b8fb11b00b69b4260198e5c1c7ddf77d5a Mon Sep 17 00:00:00 2001 From: Marcos Hernandez Date: Sun, 21 Apr 2024 12:28:54 -0700 Subject: [PATCH 2/8] fixed minor import warnings --- src/components/ContentCard/ContentCard.tsx | 4 ++-- src/components/PreviewCard/PreviewCard.tsx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/ContentCard/ContentCard.tsx b/src/components/ContentCard/ContentCard.tsx index c766751a..ae813289 100644 --- a/src/components/ContentCard/ContentCard.tsx +++ b/src/components/ContentCard/ContentCard.tsx @@ -1,3 +1,4 @@ +import { Image } from 'expo-image'; import { GestureResponderEvent, Pressable, @@ -5,11 +6,10 @@ import { View, TouchableOpacity, } from 'react-native'; -import { Image } from 'expo-image'; +import Emoji from 'react-native-emoji'; import styles from './styles'; import globalStyles from '../../styles/globalStyles'; -import Emoji from 'react-native-emoji'; import SaveStoryButton from '../SaveStoryButton/SaveStoryButton'; type ContentCardProps = { diff --git a/src/components/PreviewCard/PreviewCard.tsx b/src/components/PreviewCard/PreviewCard.tsx index 71d6d057..aa82e8eb 100644 --- a/src/components/PreviewCard/PreviewCard.tsx +++ b/src/components/PreviewCard/PreviewCard.tsx @@ -1,4 +1,5 @@ import * as cheerio from 'cheerio'; +import { Image } from 'expo-image'; import { GestureResponderEvent, Pressable, @@ -7,7 +8,6 @@ import { View, } from 'react-native'; import Emoji from 'react-native-emoji'; -import { Image } from 'expo-image'; import styles from './styles'; import globalStyles from '../../styles/globalStyles'; From 51cff77a62b48db647bfee35dbea144e1b92f6ec Mon Sep 17 00:00:00 2001 From: Marcos Hernandez Date: Sun, 21 Apr 2024 16:50:19 -0700 Subject: [PATCH 3/8] idk --- src/app/(tabs)/genre/index.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/app/(tabs)/genre/index.tsx b/src/app/(tabs)/genre/index.tsx index 87712eb5..80adfc17 100644 --- a/src/app/(tabs)/genre/index.tsx +++ b/src/app/(tabs)/genre/index.tsx @@ -19,6 +19,7 @@ import { fetchStoryPreviewByIds } from '../../../queries/stories'; import { StoryPreview, GenreStories } from '../../../queries/types'; import globalStyles from '../../../styles/globalStyles'; import PreviewCard from '../../../components/PreviewCard/PreviewCard'; +import React from 'react'; function GenreScreen() { const [genreStoryData, setGenreStoryData] = useState(); From 607055fc1da1ca746ad1df2630aaca1fd53f2dec Mon Sep 17 00:00:00 2001 From: Marcos Hernandez Date: Sun, 21 Apr 2024 17:55:58 -0700 Subject: [PATCH 4/8] temp --- src/app/(tabs)/home/index.tsx | 1 + src/queries/stories.tsx | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/app/(tabs)/home/index.tsx b/src/app/(tabs)/home/index.tsx index b5c7b343..90d30b1d 100644 --- a/src/app/(tabs)/home/index.tsx +++ b/src/app/(tabs)/home/index.tsx @@ -23,6 +23,7 @@ import { import { StoryCard, StoryPreview } from '../../../queries/types'; import globalStyles from '../../../styles/globalStyles'; import { useSession } from '../../../utils/AuthContext'; +import React from 'react'; function HomeScreen() { const { user } = useSession(); diff --git a/src/queries/stories.tsx b/src/queries/stories.tsx index 9b8e833b..6828e3e5 100644 --- a/src/queries/stories.tsx +++ b/src/queries/stories.tsx @@ -114,3 +114,33 @@ export async function fetchStoryPreviewByIds( return data; } } + +export async function fetchFeaturedStoriesDescriptionHeader(): Promise { + const { data, error } = await supabase + .from('featured_stories_description') + .select('header'); + + if (error) { + console.log(error); + throw new Error( + `An error occured when trying to fetch featured story description: ${error}`, + ); + } else { + return data[0].header; + } +} + +export async function fetchFeaturedStoriesDescriptionDescription(): Promise { + const { data, error } = await supabase + .from('featured_stories_description') + .select('description'); + + if (error) { + console.log(error); + throw new Error( + `An error occured when trying to fetch featured story description: ${error}`, + ); + } else { + return data[0].description; + } +} From b58075af985d49ff64f2da11d20c228fcebc9912 Mon Sep 17 00:00:00 2001 From: Marcos Hernandez Date: Sun, 21 Apr 2024 17:57:54 -0700 Subject: [PATCH 5/8] added description and header --- src/app/(tabs)/home/index.tsx | 156 +++++++++++++++++++++++++--------- 1 file changed, 114 insertions(+), 42 deletions(-) diff --git a/src/app/(tabs)/home/index.tsx b/src/app/(tabs)/home/index.tsx index 90d30b1d..1f5cba1e 100644 --- a/src/app/(tabs)/home/index.tsx +++ b/src/app/(tabs)/home/index.tsx @@ -1,64 +1,147 @@ +import AsyncStorage from '@react-native-async-storage/async-storage'; import { router } from 'expo-router'; -import { useEffect, useState } from 'react'; -import { - ActivityIndicator, - Pressable, - ScrollView, - Text, - View, -} from 'react-native'; +import React, { useEffect, useState } from 'react'; +import { ActivityIndicator, ScrollView, Text, View } from 'react-native'; 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'; import { fetchFeaturedStoriesDescription, + fetchFeaturedStoriesDescriptionDescription, + fetchFeaturedStoriesDescriptionHeader, fetchFeaturedStoryPreviews, fetchNewStories, fetchRecommendedStories, + fetchStoryPreviewById, } from '../../../queries/stories'; import { StoryCard, StoryPreview } from '../../../queries/types'; import globalStyles from '../../../styles/globalStyles'; import { useSession } from '../../../utils/AuthContext'; -import React from 'react'; function HomeScreen() { const { user } = useSession(); const [username, setUsername] = useState(''); const [loading, setLoading] = useState(true); const [featuredStories, setFeaturedStories] = useState([]); + const [recentlyViewed, setRecentlyViewed] = useState([]); const [featuredStoriesDescription, setFeaturedStoriesDescription] = useState(''); const [recommendedStories, setRecommendedStories] = useState([]); const [newStories, setNewStories] = useState([]); + const [header, setHeader] = useState(''); + const [description, setDescription] = useState(''); + + const getRecentStory = async () => { + try { + const jsonValue = await AsyncStorage.getItem('GWN_RECENT_STORIES_ARRAY'); + return jsonValue != null ? JSON.parse(jsonValue) : []; + } catch (error) { + console.log(error); + } + }; + + const setRecentStory = async (recentStories: StoryCard[]) => { + try { + const jsonValue = JSON.stringify(recentStories); + await AsyncStorage.setItem('GWN_RECENT_STORIES_ARRAY', jsonValue); + } catch (error) { + console.log(error); + } + }; + + const handleStoryPreviewPressed = (story: StoryPreview) => { + recentlyViewedStacking(story); + router.push({ + pathname: '/story', + params: { storyId: story.id.toString() }, + }); + }; + + const handleStoryCardPressed = async (story: StoryCard) => { + const newStoryArray = await fetchStoryPreviewById(story.id); + recentlyViewedStacking(newStoryArray[0]); + router.push({ + pathname: '/story', + params: { storyId: story.id.toString() }, + }); + }; + + const recentlyViewedStacking = async (story: StoryPreview) => { + const maxArrayLength = 5; + const newRecentlyViewed = [...recentlyViewed]; + + for (let i = 0; i < recentlyViewed.length; i++) { + if (story.id === recentlyViewed[i].id) { + newRecentlyViewed.splice(i, 1); + break; + } + } + + if (newRecentlyViewed.length >= maxArrayLength) { + newRecentlyViewed.splice(-1, 1); + } + + newRecentlyViewed.splice(0, 0, story); + + setRecentStory(newRecentlyViewed); + setRecentlyViewed(newRecentlyViewed); + }; useEffect(() => { + const getRecommendedStories = async () => { + const recentStoryResponse = await getRecentStory(); + + const recommendedStoriesResponse = + await fetchRecommendedStories(recentStoryResponse); + setRecommendedStories(recommendedStoriesResponse); + }; + (async () => { const [ usernameResponse, featuredStoryResponse, featuredStoryDescriptionResponse, - recommendedStoriesResponse, newStoriesResponse, + recentStoryResponse, ] = await Promise.all([ fetchUsername(user?.id).catch(() => ''), fetchFeaturedStoryPreviews().catch(() => []), fetchFeaturedStoriesDescription().catch(() => ''), - fetchRecommendedStories().catch(() => []), fetchNewStories().catch(() => []), + getRecentStory(), ]); - setUsername(usernameResponse); setFeaturedStories(featuredStoryResponse); setFeaturedStoriesDescription(featuredStoryDescriptionResponse); - setRecommendedStories(recommendedStoriesResponse); setNewStories(newStoriesResponse); + setRecentlyViewed(recentStoryResponse); + await getRecommendedStories(); })().finally(() => { setLoading(false); }); + + (async () => { + const temp = await fetchFeaturedStoriesDescriptionHeader(); + if (temp != null) { + setHeader(temp); + return; + } + + setHeader(''); + })(); + + (async () => { + const temp = await fetchFeaturedStoriesDescriptionDescription(); + if (temp != null) { + setDescription(temp); + return; + } + + setDescription(''); + })(); }, [user]); if (loading) { @@ -80,20 +163,22 @@ function HomeScreen() { {username ? `Welcome, ${username}` : 'Welcome!'} - router.push('/settings')}> - - - - {featuredStories.length > 0 && ( Featured Stories - - {featuredStoriesDescription} + {featuredStoriesDescription != null && + featuredStoriesDescription.length > 0 && ( + + {featuredStoriesDescription} + + )} + {header} + + {description} - + {featuredStories.map(story => ( - router.push({ - pathname: '/story', - params: { storyId: story.id.toString() }, - }) - } + pressFunction={() => handleStoryPreviewPressed(story)} /> ))} @@ -130,17 +210,13 @@ function HomeScreen() { > {recommendedStories.map(story => ( - router.push({ - pathname: '/story', - params: { storyId: story.id.toString() }, - }) - } + pressFunction={() => handleStoryCardPressed(story)} image={story.featured_media} /> ))} @@ -160,17 +236,13 @@ function HomeScreen() { > {newStories.map(story => ( - router.push({ - pathname: '/story', - params: { storyId: story.id.toString() }, - }) - } + pressFunction={() => handleStoryCardPressed(story)} image={story.featured_media} /> ))} From 70f8bf13134e6cdb3a8ac4e37f849a24318ee5e8 Mon Sep 17 00:00:00 2001 From: Marcos Hernandez Date: Sun, 21 Apr 2024 17:58:41 -0700 Subject: [PATCH 6/8] merging --- src/app/(tabs)/home/index.tsx | 2 -- src/components/ContentCard/ContentCard.tsx | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/app/(tabs)/home/index.tsx b/src/app/(tabs)/home/index.tsx index 1f5cba1e..c06a5e00 100644 --- a/src/app/(tabs)/home/index.tsx +++ b/src/app/(tabs)/home/index.tsx @@ -210,7 +210,6 @@ function HomeScreen() { > {recommendedStories.map(story => ( {newStories.map(story => ( Date: Sun, 21 Apr 2024 22:16:11 -0700 Subject: [PATCH 7/8] Fix styling --- src/app/(tabs)/home/index.tsx | 56 ++++++++++++----------------------- src/app/(tabs)/home/styles.ts | 3 +- src/queries/stories.tsx | 19 ++---------- 3 files changed, 22 insertions(+), 56 deletions(-) diff --git a/src/app/(tabs)/home/index.tsx b/src/app/(tabs)/home/index.tsx index 1f5cba1e..8a7284f9 100644 --- a/src/app/(tabs)/home/index.tsx +++ b/src/app/(tabs)/home/index.tsx @@ -1,6 +1,6 @@ import AsyncStorage from '@react-native-async-storage/async-storage'; import { router } from 'expo-router'; -import React, { useEffect, useState } from 'react'; +import { useEffect, useState } from 'react'; import { ActivityIndicator, ScrollView, Text, View } from 'react-native'; import { SafeAreaView } from 'react-native-safe-area-context'; @@ -10,8 +10,7 @@ import PreviewCard from '../../../components/PreviewCard/PreviewCard'; import { fetchUsername } from '../../../queries/profiles'; import { fetchFeaturedStoriesDescription, - fetchFeaturedStoriesDescriptionDescription, - fetchFeaturedStoriesDescriptionHeader, + fetchFeaturedStoriesHeader, fetchFeaturedStoryPreviews, fetchNewStories, fetchRecommendedStories, @@ -29,10 +28,9 @@ function HomeScreen() { const [recentlyViewed, setRecentlyViewed] = useState([]); const [featuredStoriesDescription, setFeaturedStoriesDescription] = useState(''); + const [featuredStoriesHeader, setFeaturedStoriesHeader] = useState(''); const [recommendedStories, setRecommendedStories] = useState([]); const [newStories, setNewStories] = useState([]); - const [header, setHeader] = useState(''); - const [description, setDescription] = useState(''); const getRecentStory = async () => { try { @@ -91,7 +89,7 @@ function HomeScreen() { }; useEffect(() => { - const getRecommendedStories = async () => { + const updateRecommendedStories = async () => { const recentStoryResponse = await getRecentStory(); const recommendedStoriesResponse = @@ -103,45 +101,30 @@ function HomeScreen() { const [ usernameResponse, featuredStoryResponse, + featuredStoryHeaderResponse, featuredStoryDescriptionResponse, newStoriesResponse, recentStoryResponse, + _, ] = await Promise.all([ fetchUsername(user?.id).catch(() => ''), fetchFeaturedStoryPreviews().catch(() => []), + fetchFeaturedStoriesHeader().catch(() => ''), fetchFeaturedStoriesDescription().catch(() => ''), fetchNewStories().catch(() => []), getRecentStory(), + updateRecommendedStories(), ]); + setUsername(usernameResponse); setFeaturedStories(featuredStoryResponse); + setFeaturedStoriesHeader(featuredStoryHeaderResponse); setFeaturedStoriesDescription(featuredStoryDescriptionResponse); setNewStories(newStoriesResponse); setRecentlyViewed(recentStoryResponse); - await getRecommendedStories(); })().finally(() => { setLoading(false); }); - - (async () => { - const temp = await fetchFeaturedStoriesDescriptionHeader(); - if (temp != null) { - setHeader(temp); - return; - } - - setHeader(''); - })(); - - (async () => { - const temp = await fetchFeaturedStoriesDescriptionDescription(); - if (temp != null) { - setDescription(temp); - return; - } - - setDescription(''); - })(); }, [user]); if (loading) { @@ -160,25 +143,24 @@ function HomeScreen() { contentContainerStyle={{ paddingHorizontal: 8 }} > - + {username ? `Welcome, ${username}` : 'Welcome!'} {featuredStories.length > 0 && ( - Featured Stories + Featured Stories {featuredStoriesDescription != null && featuredStoriesDescription.length > 0 && ( - - {featuredStoriesDescription} - + <> + {featuredStoriesHeader} + + {featuredStoriesDescription} + + )} - {header} - - {description} - - + {featuredStories.map(story => ( { } } -export async function fetchFeaturedStoriesDescription(): Promise { - const { data, error } = await supabase - .from('featured_stories') - .select('description'); - - if (error) { - console.log(error); - throw new Error( - `An error occured when trying to fetch featured story description: ${error}`, - ); - } else { - return data[0].description; - } -} - export async function fetchRecommendedStories( inputStories: StoryPreview[], ): Promise { @@ -198,7 +183,7 @@ export async function fetchStoryPreviewByIds( } } -export async function fetchFeaturedStoriesDescriptionHeader(): Promise { +export async function fetchFeaturedStoriesHeader(): Promise { const { data, error } = await supabase .from('featured_stories_description') .select('header'); @@ -213,7 +198,7 @@ export async function fetchFeaturedStoriesDescriptionHeader(): Promise { } } -export async function fetchFeaturedStoriesDescriptionDescription(): Promise { +export async function fetchFeaturedStoriesDescription(): Promise { const { data, error } = await supabase .from('featured_stories_description') .select('description'); From 0fdf1de7801343d6d32bcee2c69838b890d08322 Mon Sep 17 00:00:00 2001 From: Aditya Pawar Date: Sun, 21 Apr 2024 22:24:39 -0700 Subject: [PATCH 8/8] Fix small styling bugs --- src/app/(tabs)/home/index.tsx | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/app/(tabs)/home/index.tsx b/src/app/(tabs)/home/index.tsx index 8a7284f9..911f8a57 100644 --- a/src/app/(tabs)/home/index.tsx +++ b/src/app/(tabs)/home/index.tsx @@ -150,15 +150,20 @@ function HomeScreen() { {featuredStories.length > 0 && ( - Featured Stories - {featuredStoriesDescription != null && - featuredStoriesDescription.length > 0 && ( - <> - {featuredStoriesHeader} - - {featuredStoriesDescription} - - + + Featured Stories + + {featuredStoriesHeader != null && featuredStoriesHeader != '' && ( + + {featuredStoriesHeader} + + )} + {featuredStoriesHeader != '' && + featuredStoriesDescription != null && + featuredStoriesDescription != '' && ( + + {featuredStoriesDescription} + )} {featuredStories.map(story => (