-
Notifications
You must be signed in to change notification settings - Fork 1
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
Feat: libraries #25
base: master
Are you sure you want to change the base?
Feat: libraries #25
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import { Surface, Text, TouchableRipple } from "react-native-paper"; | ||
import type { Library } from "../../types/stores"; | ||
import { GestureResponderEvent, Pressable, Image, StyleSheet, View } from "react-native"; | ||
import { useEffect, useState } from "react"; | ||
import * as WebBrowser from "expo-web-browser"; | ||
|
||
|
||
export const LibraryListItemComponent = ({ library, onPress, showDetails }: { library: Library, onPress: ((event: GestureResponderEvent) => void), showDetails: boolean}) => { | ||
const [imgSize, setImgSize] = useState({ width: 0, height: 1 }); | ||
|
||
useEffect(() => { | ||
Image.getSize(library.image_url, (w, h) => { | ||
setImgSize({ | ||
width: w, | ||
height: h, | ||
}); | ||
}); | ||
}, [library.image_url]); | ||
|
||
return ( | ||
<Surface style={{ ...styles.container }}> | ||
<TouchableRipple rippleColor="rgba(0, 0, 0, .32)" onPress={onPress}> | ||
<> | ||
<Image | ||
style={{ | ||
flex: 1, | ||
aspectRatio: (imgSize.width ?? 1) / (Math.max(imgSize.height, 1) ?? 1), | ||
}} | ||
source={{ uri: library.image_url }} | ||
/> | ||
<View style={styles.textContainer}> | ||
<Text variant="headlineSmall" style={styles.title}> | ||
{library.name_nl} | ||
</Text> | ||
<View style={styles.additionalInfo}> | ||
<View> | ||
<Text style={styles.smallText}>{library.address.join(" ")}</Text> | ||
{ | ||
showDetails ? | ||
<> | ||
<Text style={styles.smallText}>{library.email}</Text> | ||
<Text style={styles.smallText}>{library.telephone}</Text> | ||
</> | ||
: | ||
<></> | ||
} | ||
</View> | ||
</View> | ||
</View> | ||
</> | ||
</TouchableRipple> | ||
{ | ||
showDetails ? | ||
<Pressable style={{...styles.button, backgroundColor: "#ddd"}} onPress={() => WebBrowser.openBrowserAsync(library.link)}> | ||
<Text>Go to site</Text> | ||
</Pressable> | ||
Comment on lines
+54
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also move this to the details screen and replace it with a button from |
||
: | ||
<></> | ||
} | ||
</Surface> | ||
); | ||
}; | ||
const styles = StyleSheet.create({ | ||
container: { | ||
display: "flex", | ||
flexDirection: "column", | ||
marginVertical: 5, | ||
width: "95%", | ||
borderRadius: 15, | ||
overflow: "hidden", | ||
}, | ||
textContainer: { | ||
padding: 15, | ||
color: "#ddd", | ||
}, | ||
title: { | ||
fontWeight: "600", | ||
color: "#000", | ||
}, | ||
additionalInfo: { | ||
marginTop: 5, | ||
display: "flex", | ||
flexDirection: "row", | ||
alignItems: "center", | ||
justifyContent: "space-between", | ||
color: "#ddd", | ||
}, | ||
smallText: { | ||
color: "#000", | ||
fontWeight: "900", | ||
}, | ||
button: { | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
paddingVertical: 12, | ||
paddingHorizontal: 32, | ||
borderRadius: 4, | ||
elevation: 3, | ||
width: 200, | ||
alignSelf: 'center', | ||
marginBottom: 10, | ||
}, | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export const ENDPOINTS = { | ||
HYDRA_V1: "https://hydra.ugent.be/api/1.0/", | ||
HYDRA_V2: "https://hydra.ugent.be/api/2.0/", | ||
LIBRARIES: "https://widgets.lib.ugent.be/" | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { useLibrariesQuery } from "../stores/libraries"; | ||
import { LibraryListItemComponent } from "../components/feed/LibraryListItemComponent"; | ||
import { StyleSheet, ScrollView } from "react-native"; | ||
import { useState } from "react"; | ||
import { Library } from "../types/stores"; | ||
|
||
|
||
const LibrariesView = () => { | ||
const { data: libraryRequest } = useLibrariesQuery(); | ||
const [selectedLibrary, setSelectedLibrary] = useState<Library | null>(null); | ||
|
||
return ( | ||
<ScrollView contentContainerStyle={styles.container}> | ||
{libraryRequest.libraries.map(lib => ( | ||
<LibraryListItemComponent key={lib.link} library={lib} onPress={async () => setSelectedLibrary(lib)} showDetails={lib==selectedLibrary}/> | ||
))} | ||
</ScrollView> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
display: "flex", | ||
alignItems: "center", | ||
}, | ||
}); | ||
|
||
export default LibrariesView; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { LibraryRequest } from "../types/stores"; | ||
import { ENDPOINTS } from "../constant"; | ||
import { useSuspenseQuery } from "@tanstack/react-query"; | ||
import { useFocusNotifyOnChangeProps } from "../lib/hooks/useFocusNotifyOnChangeProps"; | ||
|
||
export const useLibrariesQuery = () => { | ||
const notifyOnChangeProps = useFocusNotifyOnChangeProps(); | ||
|
||
const schamperQuery = useSuspenseQuery<LibraryRequest, Error>({ | ||
queryKey: ["libraries"], | ||
queryFn: async () => { | ||
const res = await fetch(`${ENDPOINTS.LIBRARIES}/library_groups/main.json`); | ||
return res.json(); | ||
}, | ||
notifyOnChangeProps, | ||
}); | ||
return schamperQuery; | ||
Comment on lines
+9
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you move this details + the opening hours to a different screen using react-navigation/stack?