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

Feat: libraries #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"@react-navigation/devtools": "^6.0.20",
"@react-navigation/drawer": "^6.6.6",
"@react-navigation/native": "^6.1.9",
"@react-navigation/stack": "^6.3.20",
"@tanstack/react-query": "^5.8.3",
"expo": "^49.0.3",
"expo-splash-screen": "~0.20.5",
Expand Down
6 changes: 6 additions & 0 deletions src/components/drawer/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import RestoMenu from "../../routes/resto";
import EventView from "../../routes/events";
import { DrawerEntry } from "../../types/drawer";
import SchamperView from "../../routes/schamper";
import LibrariesView from "../../routes/libraries";
import { SchamperIcon } from "../icons/SchamperIcon";

export const routes: DrawerEntry[] = [
Expand All @@ -26,4 +27,9 @@ export const routes: DrawerEntry[] = [
element: SchamperView,
icon: SchamperIcon,
},
{
name: "Libraries",
element: LibrariesView,
icon: "book",
}
];
104 changes: 104 additions & 0 deletions src/components/feed/LibraryListItemComponent.tsx
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>
</>
:
<></>
}
Comment on lines +38 to +46
Copy link
Member

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?

</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
Copy link
Member

Choose a reason for hiding this comment

The 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 react-native-paper or move it behind an icon in the header of the details screen

:
<></>
}
</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,
},
});

1 change: 1 addition & 0 deletions src/constant.ts
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/"
};
28 changes: 28 additions & 0 deletions src/routes/libraries.tsx
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;
18 changes: 18 additions & 0 deletions src/stores/libraries.ts
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

schamperQuery -> libraryQuery

};
36 changes: 36 additions & 0 deletions src/types/stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,39 @@ export declare type Article = {
// ISO date string
pub_date: string;
};

export declare type LibraryRequest = {
libraries: Library[];
};

export declare type Library = {
name_en: string;
has_hours: boolean;
lat: number;
image_url: string;
telephone: string[];
reading_room: string;
link_nl: string;
created_at: string;
door_number: string;
email: string;
department: string;
contact: string;
pickup_locations: string[];
updated_at: string;
link_en: string;
active: boolean;
email_acquisition: string;
cubee_id: string;
link: string;
sap_id: string;
shipment_library_code: string;
name: string;
faculty: string;
code: string;
thumbnail_url: string;
address: string[];
name_nl: string;
campus: string;
long: number;
};
9 changes: 9 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2075,6 +2075,15 @@
dependencies:
nanoid "^3.1.23"

"@react-navigation/stack@^6.3.20":
version "6.3.20"
resolved "https://registry.yarnpkg.com/@react-navigation/stack/-/stack-6.3.20.tgz#8eec944888f317bb1ba1ff30e7f513806bea16c2"
integrity sha512-vE6mgZzOgoa5Uy7ayT97Cj+ZIK7DK+JBYVuKUViILlWZy6IWK7HFDuqoChSbZ1ajTIfAxj/acVGg1jkbAKsToA==
dependencies:
"@react-navigation/elements" "^1.3.21"
color "^4.2.3"
warn-once "^0.1.0"

"@segment/loosely-validate-event@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@segment/loosely-validate-event/-/loosely-validate-event-2.0.0.tgz#87dfc979e5b4e7b82c5f1d8b722dfd5d77644681"
Expand Down