-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] resources rendered and scrolling by buttons
- Loading branch information
Showing
10 changed files
with
231 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Text, View } from 'react-native'; | ||
|
||
export default function HFHGuide() { | ||
return ( | ||
<View> | ||
<Text> This is the HFH page </Text> | ||
</View> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<HealingResource[]>([]); | ||
const scrollViewRef = useRef<ScrollView | null>(null); | ||
const [headerPositions, setHeaderPositions] = useState<number[]>([]); | ||
|
||
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<string, HealingResource[]>, | ||
); | ||
|
||
// 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 ( | ||
<View style={styles.container}> | ||
<View style={styles.themesContainer}> | ||
{themes.map((theme, index) => ( | ||
<TouchableOpacity | ||
key={index} | ||
style={styles.themeButton} | ||
onPress={() => scrollToTheme(index)} | ||
> | ||
<Text>{theme}</Text> | ||
</TouchableOpacity> | ||
))} | ||
</View> | ||
<ScrollView ref={scrollViewRef}> | ||
<View style={styles.resourcesContainer}> | ||
{themes.map((theme, index) => ( | ||
<> | ||
<View style={styles.themeHeader} onLayout={onLayoutHeader(index)}> | ||
<Text style={styles.themeHeaderText}>{theme}</Text> | ||
</View> | ||
<View style={styles.cardsContainer}> | ||
{groupedResources[theme].map((resource, resourcesIndex) => ( | ||
<View style={styles.resourceContainer} key={resourcesIndex}> | ||
<View style={styles.resourceCard}></View> | ||
<Text style={styles.resourceText}> | ||
{resource.text_content} | ||
</Text> | ||
</View> | ||
))} | ||
</View> | ||
</> | ||
))} | ||
</View> | ||
</ScrollView> | ||
</View> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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', | ||
}, | ||
}); |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Resource[]>([]); | ||
|
||
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 ( | ||
<View> | ||
<Button | ||
title="Hope Healing Guide" | ||
onPress={() => console.log('does this work')} | ||
/> | ||
<Button | ||
title="Theme Healing Resources" | ||
onPress={() => console.log('does this work')} | ||
/> | ||
<View style={styles.container}> | ||
<TouchableOpacity | ||
style={styles.pagebutton} | ||
onPress={() => navigation.navigate('Hope for Healing Guide')} | ||
> | ||
<Text style={styles.buttonText}>Hope for Healing Guide</Text> | ||
</TouchableOpacity> | ||
<TouchableOpacity | ||
style={styles.pagebutton} // Reusing the same style for consistency | ||
onPress={() => navigation.navigate('Themed Healing Resources')} | ||
> | ||
<Text style={styles.buttonText}>Resources Catalogue</Text> | ||
</TouchableOpacity> | ||
</View> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters