Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[retool] Add way to set description of featured stories #92

Merged
merged 16 commits into from
Apr 22, 2024
2 changes: 1 addition & 1 deletion src/app/(tabs)/genre/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useLocalSearchParams, router } from 'expo-router';
import { useEffect, useState, useMemo, ReactNode } from 'react';
import React, { useEffect, useState, useMemo } from 'react';
import {
ActivityIndicator,
ScrollView,
Expand Down
37 changes: 23 additions & 14 deletions src/app/(tabs)/home/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
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 { ActivityIndicator, ScrollView, Text, View } from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';

import styles from './styles';
Expand All @@ -16,6 +10,7 @@ import PreviewCard from '../../../components/PreviewCard/PreviewCard';
import { fetchUsername } from '../../../queries/profiles';
import {
fetchFeaturedStoriesDescription,
fetchFeaturedStoriesHeader,
fetchFeaturedStoryPreviews,
fetchNewStories,
fetchRecommendedStories,
Expand All @@ -33,6 +28,7 @@ function HomeScreen() {
const [recentlyViewed, setRecentlyViewed] = useState<StoryPreview[]>([]);
const [featuredStoriesDescription, setFeaturedStoriesDescription] =
useState<string>('');
const [featuredStoriesHeader, setFeaturedStoriesHeader] = useState('');
const [recommendedStories, setRecommendedStories] = useState<StoryCard[]>([]);
const [newStories, setNewStories] = useState<StoryCard[]>([]);

Expand Down Expand Up @@ -93,7 +89,7 @@ function HomeScreen() {
};

useEffect(() => {
const getRecommendedStories = async () => {
const updateRecommendedStories = async () => {
const recentStoryResponse = await getRecentStory();

const recommendedStoriesResponse =
Expand All @@ -105,22 +101,27 @@ 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);
});
Expand All @@ -142,21 +143,29 @@ function HomeScreen() {
contentContainerStyle={{ paddingHorizontal: 8 }}
>
<View style={styles.headerContainer}>
<Text style={globalStyles.h1}>
<Text style={[globalStyles.h1, { paddingBottom: 24 }]}>
{username ? `Welcome, ${username}` : 'Welcome!'}
</Text>
</View>

{featuredStories.length > 0 && (
<View>
<Text style={globalStyles.h3}>Featured Stories</Text>
{featuredStoriesDescription != null &&
featuredStoriesDescription.length > 0 && (
<Text style={[globalStyles.h2, { paddingBottom: 16 }]}>
Featured Stories
</Text>
{featuredStoriesHeader != null && featuredStoriesHeader != '' && (
<Text style={[globalStyles.h3, { paddingBottom: 16 }]}>
{featuredStoriesHeader}
</Text>
)}
{featuredStoriesHeader != '' &&
featuredStoriesDescription != null &&
featuredStoriesDescription != '' && (
<Text style={[globalStyles.body1, styles.featuredDescription]}>
{featuredStoriesDescription}
</Text>
)}
<View style={{ marginRight: 24, marginTop: 16 }}>
<View style={{ marginRight: 24 }}>
{featuredStories.map(story => (
<PreviewCard
key={story.id}
Expand Down
3 changes: 1 addition & 2 deletions src/app/(tabs)/home/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ const styles = StyleSheet.create({
marginRight: 24,
},
featuredDescription: {
marginBottom: 16,
marginTop: 8,
marginBottom: 24,
marginRight: 24,
},
});
Expand Down
6 changes: 2 additions & 4 deletions src/components/ContentCard/ContentCard.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import { Image } from 'expo-image';
import { useEffect, useState } from 'react';
import React, { useEffect, useState } from 'react';
import {
GestureResponderEvent,
Pressable,
Text,
View,
TouchableOpacity,
} from 'react-native';
import Emoji from 'react-native-emoji';

import styles from './styles';
import { fetchAllReactionsToStory } from '../../queries/reactions';
import { Reactions } from '../../queries/types';
import globalStyles from '../../styles/globalStyles';
import SaveStoryButton from '../SaveStoryButton/SaveStoryButton';
import ReactionDisplay from '../ReactionDisplay/ReactionDisplay';
import SaveStoryButton from '../SaveStoryButton/SaveStoryButton';

type ContentCardProps = {
id: number;
Expand Down
6 changes: 2 additions & 4 deletions src/components/PreviewCard/PreviewCard.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import * as cheerio from 'cheerio';
import { Image } from 'expo-image';
import { useEffect, useState } from 'react';
import React, { useEffect, useState } from 'react';
import {
GestureResponderEvent,
Pressable,
Text,
TouchableOpacity,
View,
} from 'react-native';
import Emoji from 'react-native-emoji';

import styles from './styles';
import { fetchAllReactionsToStory } from '../../queries/reactions';
import { Reactions } from '../../queries/types';
import globalStyles from '../../styles/globalStyles';
import SaveStoryButton from '../SaveStoryButton/SaveStoryButton';
import ReactionDisplay from '../ReactionDisplay/ReactionDisplay';
import SaveStoryButton from '../SaveStoryButton/SaveStoryButton';

const placeholderImage =
'https://gwn-uploads.s3.amazonaws.com/wp-content/uploads/2021/10/10120952/Girls-Write-Now-logo-avatar.png';
Expand Down
49 changes: 31 additions & 18 deletions src/queries/stories.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import AsyncStorage from '@react-native-async-storage/async-storage';
import {
Story,
StoryPreview,
StoryCard,
StoryPreviewWithPreloadedReactions,
} from './types';
import supabase from '../utils/supabase';
import { useState } from 'react';

export async function fetchAllStoryPreviews(): Promise<
StoryPreviewWithPreloadedReactions[]
Expand Down Expand Up @@ -51,25 +49,10 @@ export async function fetchFeaturedStoryPreviews(): Promise<StoryPreview[]> {
}
}

export async function fetchFeaturedStoriesDescription(): Promise<string> {
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<StoryPreview[]> {
if (inputStories.length == 0) {
if (inputStories.length === 0) {
return [];
}
const storyIDs = inputStories.map(story => story.id);
Expand Down Expand Up @@ -199,3 +182,33 @@ export async function fetchStoryPreviewByIds(
return data;
}
}

export async function fetchFeaturedStoriesHeader(): Promise<string> {
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 fetchFeaturedStoriesDescription(): Promise<string> {
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;
}
}
Loading