From 99a79e7e2a4c2b2be4f785c305d7b6dd82a7ae24 Mon Sep 17 00:00:00 2001 From: Arfa Momin Date: Wed, 23 Oct 2024 00:37:08 -0700 Subject: [PATCH] [feat] resources rendered and scrolling by buttons --- App.tsx | 7 ++ .../HealingResources/HFHGuide/index.tsx | 9 ++ .../HealingCatalogue/index.tsx | 89 +++++++++++++++++++ .../HealingCatalogue/styles.ts | 76 ++++++++++++++++ .../HopeHealingGuide/index.tsx | 0 .../HealingResources/ThemedHealing/index.tsx | 0 src/screens/HealingResources/index.tsx | 45 ++++------ src/screens/HealingResources/styles.ts | 18 +++- src/supabase/queries/generalQueries.tsx | 13 ++- src/types/types.tsx | 8 ++ 10 files changed, 231 insertions(+), 34 deletions(-) create mode 100644 src/screens/HealingResources/HFHGuide/index.tsx create mode 100644 src/screens/HealingResources/HealingCatalogue/index.tsx create mode 100644 src/screens/HealingResources/HealingCatalogue/styles.ts delete mode 100644 src/screens/HealingResources/HopeHealingGuide/index.tsx delete mode 100644 src/screens/HealingResources/ThemedHealing/index.tsx diff --git a/App.tsx b/App.tsx index 237c3d3..4ed0fd1 100644 --- a/App.tsx +++ b/App.tsx @@ -2,6 +2,8 @@ import * as React from 'react'; import { NavigationContainer } from '@react-navigation/native'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; import HealingResources from '@/screens/HealingResources'; +import HealingCatalogue from '@/screens/HealingResources/HealingCatalogue'; +import HFHGuide from '@/screens/HealingResources/HFHGuide'; import Home from '@/screens/Home'; import LegalRights from '@/screens/LegalRights'; import SeekHelp from '@/screens/SeekHelp'; @@ -16,6 +18,11 @@ export default function App() { + + ); diff --git a/src/screens/HealingResources/HFHGuide/index.tsx b/src/screens/HealingResources/HFHGuide/index.tsx new file mode 100644 index 0000000..b0e7ab5 --- /dev/null +++ b/src/screens/HealingResources/HFHGuide/index.tsx @@ -0,0 +1,9 @@ +import { Text, View } from 'react-native'; + +export default function HFHGuide() { + return ( + + This is the HFH page + + ); +} diff --git a/src/screens/HealingResources/HealingCatalogue/index.tsx b/src/screens/HealingResources/HealingCatalogue/index.tsx new file mode 100644 index 0000000..17b513f --- /dev/null +++ b/src/screens/HealingResources/HealingCatalogue/index.tsx @@ -0,0 +1,89 @@ +import React, { useEffect, useRef, useState } from 'react'; +import { ScrollView, Text, TouchableOpacity, View } from 'react-native'; +import { getHealingResourceData } from '@/supabase/queries/generalQueries'; +import { HealingResource } from '@/types/types'; +import styles from './styles'; + +const themes = ['Breathing', 'Meditation', 'Joy', 'Resilience']; + +export default function HealingCatalogue() { + const [resources, setResources] = useState([]); + const scrollViewRef = useRef(null); + const [headerPositions, setHeaderPositions] = useState([]); + + useEffect(() => { + const fetchResources = async () => { + const data = await getHealingResourceData(); + setResources(data); + }; + fetchResources(); + }, []); + + const groupedResources = themes.reduce( + (acc, theme) => { + acc[theme] = resources.filter(resource => + resource.topics.includes(theme), + ); + return acc; + }, + {} as Record, + ); + + // Scroll to top of theme header + const scrollToTheme = (index: number) => { + const targetY = headerPositions[index] || 0; + const paddingTop = 30; + scrollViewRef.current?.scrollTo({ + y: targetY - paddingTop, + animated: true, + }); + }; + + // Captures the position of headers as being rendered to use for scrolling + const onLayoutHeader = + (index: number) => (event: { nativeEvent: { layout: { y: number } } }) => { + const { y } = event.nativeEvent.layout; + setHeaderPositions(prevPositions => { + const newPositions = [...prevPositions]; + newPositions[index] = y; + return newPositions; + }); + }; + + return ( + + + {themes.map((theme, index) => ( + scrollToTheme(index)} + > + {theme} + + ))} + + + + {themes.map((theme, index) => ( + <> + + {theme} + + + {groupedResources[theme].map((resource, resourcesIndex) => ( + + + + {resource.text_content} + + + ))} + + + ))} + + + + ); +} diff --git a/src/screens/HealingResources/HealingCatalogue/styles.ts b/src/screens/HealingResources/HealingCatalogue/styles.ts new file mode 100644 index 0000000..38f7e50 --- /dev/null +++ b/src/screens/HealingResources/HealingCatalogue/styles.ts @@ -0,0 +1,76 @@ +import { StyleSheet } from 'react-native'; + +export default StyleSheet.create({ + container: { + width: '100%', + height: '100%', + backgroundColor: '#FFFFFF', + flexDirection: 'row', + alignItems: 'center', + }, + themesContainer: { + paddingTop: 30, + height: '100%', + width: '20%', + padding: 10, + flexDirection: 'column', + alignItems: 'center', + rowGap: 10, + }, + themeButton: { + backgroundColor: '#e8e8e8', + flexDirection: 'row', + alignItems: 'center', + justifyContent: 'center', + borderRadius: 10, + width: '90%', + height: 40, + }, + resourcesContainer: { + paddingTop: 30, + width: '100%', + height: '100%', + borderLeftColor: '#e8e8e8', + flexDirection: 'row', + flexWrap: 'wrap', + padding: 10, + rowGap: 10, + columnGap: 10, + borderLeftWidth: 1, + }, + themeHeader: { + justifyContent: 'center', + alignItems: 'flex-start', + width: '100%', + borderRadius: 50, + backgroundColor: '#F3F3F3', + borderColor: '#D9D9D9', + borderWidth: 1.5, + height: 50, + }, + themeHeaderText: { + fontSize: 20, + marginLeft: 15, + }, + cardsContainer: { + width: '100%', + flexDirection: 'row', + flexWrap: 'wrap', + justifyContent: 'flex-start', + }, + resourceContainer: { + flexDirection: 'column', + margin: '1.1%', + width: '31%', + }, + resourceCard: { + height: 250, + borderRadius: 10, + backgroundColor: '#D9D9D9', + }, + resourceText: { + fontSize: 16, + margin: 10, + color: '#7839dj', + }, +}); diff --git a/src/screens/HealingResources/HopeHealingGuide/index.tsx b/src/screens/HealingResources/HopeHealingGuide/index.tsx deleted file mode 100644 index e69de29..0000000 diff --git a/src/screens/HealingResources/ThemedHealing/index.tsx b/src/screens/HealingResources/ThemedHealing/index.tsx deleted file mode 100644 index e69de29..0000000 diff --git a/src/screens/HealingResources/index.tsx b/src/screens/HealingResources/index.tsx index 3a52e61..a8a128d 100644 --- a/src/screens/HealingResources/index.tsx +++ b/src/screens/HealingResources/index.tsx @@ -1,34 +1,21 @@ -import React, { useEffect, useState } from 'react'; -import { Button, View } from 'react-native'; -import { getHealingResourceData } from '@/supabase/queries/generalQueries'; -import { Resource } from '@/types/types'; - -export default function HealingResources() { - const [, setSummaries] = useState([]); - - useEffect(() => { - fetchData(); - }, []); - - const fetchData = async () => { - try { - const data = await getHealingResourceData(); - setSummaries(data); - } catch (error) { - console.error('Error fetching data:', error); - } - }; +import { Text, TouchableOpacity, View } from 'react-native'; +import styles from './styles'; +export default function HealingResources({ navigation }: { navigation: any }) { return ( - -