Skip to content

Commit

Permalink
feat(news): add NewsCard component with carousel
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert27 committed Dec 6, 2024
1 parent 967cd79 commit 7eeea3f
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 12 deletions.
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ android {
applicationId 'app.neuland'
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 230
versionCode 231
versionName "0.11.0"
}
signingConfigs {
Expand Down
2 changes: 1 addition & 1 deletion app.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"android": {
"package": "app.neuland",
"userInterfaceStyle": "automatic",
"versionCode": 230
"versionCode": 231
},
"sdkVersion": "52.0.0",
"experiments": {
Expand Down
Binary file modified bun.lockb
Binary file not shown.
6 changes: 6 additions & 0 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ PODS:
- ExpoModulesCore
- ExpoClipboard (7.0.0):
- ExpoModulesCore
- ExpoCrypto (14.0.1):
- ExpoModulesCore
- ExpoFileSystem (18.0.4):
- ExpoModulesCore
- ExpoFont (13.0.1):
Expand Down Expand Up @@ -2295,6 +2297,7 @@ DEPENDENCIES:
- ExpoBlur (from `../node_modules/expo-blur/ios`)
- ExpoBrightness (from `../node_modules/expo-brightness/ios`)
- ExpoClipboard (from `../node_modules/expo-clipboard/ios`)
- ExpoCrypto (from `../node_modules/expo-crypto/ios`)
- ExpoFileSystem (from `../node_modules/expo-file-system/ios`)
- ExpoFont (from `../node_modules/expo-font/ios`)
- ExpoHaptics (from `../node_modules/expo-haptics/ios`)
Expand Down Expand Up @@ -2438,6 +2441,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/expo-brightness/ios"
ExpoClipboard:
:path: "../node_modules/expo-clipboard/ios"
ExpoCrypto:
:path: "../node_modules/expo-crypto/ios"
ExpoFileSystem:
:path: "../node_modules/expo-file-system/ios"
ExpoFont:
Expand Down Expand Up @@ -2651,6 +2656,7 @@ SPEC CHECKSUMS:
ExpoBlur: 562b3da84d3cd79016c411671eaf71a404266415
ExpoBrightness: ce777f6a365592f745428cb0acc9066b400182e8
ExpoClipboard: 166ca8c13ca1041f5ba619a211f59427ab5da8a7
ExpoCrypto: 8465f71eb3798c194c0a509d4a76e5c429656d83
ExpoFileSystem: dc2679a2b5d4c465ca881129074da95faee943d5
ExpoFont: 7522d869d84ee2ee8093ee997fef5b86f85d856b
ExpoHaptics: e636188d1d5f7ccb79f3c1bfab47aaf5a1768c73
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"expo-build-properties": "~0.13.1",
"expo-clipboard": "~7.0.0",
"expo-constants": "~17.0.3",
"expo-crypto": "~14.0.1",
"expo-haptics": "~14.0.0",
"expo-linear-gradient": "~14.0.1",
"expo-local-authentication": "~15.0.1",
Expand Down Expand Up @@ -80,6 +81,7 @@
"react-native-pager-view": "6.5.1",
"react-native-paper": "5.12.5",
"react-native-reanimated": "~3.16.3",
"react-native-reanimated-carousel": "^3.5.1",
"react-native-safe-area-context": "4.12.0",
"react-native-screens": "~4.1.0",
"react-native-select-dropdown": "^4.0.1",
Expand Down
129 changes: 129 additions & 0 deletions src/components/Cards/NewsCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import API from '@/api/authenticated-api'
import { UserKindContext } from '@/components/contexts'
import { USER_GUEST } from '@/data/constants'
import { type ThiNews } from '@/types/thi-api'
import { useQuery } from '@tanstack/react-query'
import React, { useContext, useLayoutEffect, useRef } from 'react'
import { useTranslation } from 'react-i18next'
import { Dimensions, Image, Linking, Pressable, Text, View } from 'react-native'
import Carousel from 'react-native-reanimated-carousel'
import { createStyleSheet, useStyles } from 'react-native-unistyles'

import BaseCard from './BaseCard'

const NewsCard: React.FC = () => {
const ref = useRef(null)
const { t } = useTranslation('navigation')
const { styles } = useStyles(stylesheet)
const { userKind = USER_GUEST } = useContext(UserKindContext)
const { data } = useQuery({
queryKey: ['thiNews'],
queryFn: async () => await API.getThiNews(),
staleTime: 1000 * 60 * 10, // 10 minutes
gcTime: 1000 * 60 * 60 * 24, // 24 hours
enabled: userKind !== USER_GUEST,
})
const [cardWidth, setCardWidth] = React.useState(
Dimensions.get('window').width - 32
)
useLayoutEffect(() => {
if (ref.current != null) {
// @ts-expect-error unstable_getBoundingClientRect is not in the types
const width = ref.current.unstable_getBoundingClientRect()
.width as number
setCardWidth(width)
}
}, [])

const renderEvent = (event: ThiNews): JSX.Element => {
return (
<Pressable
style={styles.eventContainer}
onPress={() => {
void Linking.openURL(event.href)
}}
>
<Image
style={styles.imageContainer}
source={{
uri: event.img,
}}
/>
<Text style={styles.eventTitle} numberOfLines={3}>
{event.title}
</Text>
</Pressable>
)
}

return (
<View ref={ref}>
<BaseCard title="news" onPressRoute="news">
{data != null && data.length > 0 && (
<Carousel
loop
height={115}
width={cardWidth * 0.87}
style={styles.carousel}
data={data}
snapEnabled={true}
autoPlay={true}
autoPlayInterval={7500}
renderItem={({ index }) => (
<View style={styles.cardsFilled}>
{renderEvent(data[index])}
</View>
)}
></Carousel>
)}
{data != null && data.length > 2 && (
<View style={styles.cardsFilled}>
<Text style={styles.description} numberOfLines={3}>
{t('cards.news.more', {
count: data.length,
})}
</Text>
</View>
)}
</BaseCard>
</View>
)
}

const stylesheet = createStyleSheet((theme) => ({
cardsFilled: { gap: 8, paddingTop: 12 },
carousel: {
alignItems: 'center',
justifyContent: 'center',
marginTop: 4,
width: '100%',
},
description: {
color: theme.colors.labelColor,
fontSize: 14,
fontWeight: '500',
},
eventContainer: {
alignItems: 'center',
backgroundColor: theme.colors.cardButton,
borderRadius: theme.radius.md,
flexDirection: 'row',
gap: 12,
marginHorizontal: 4,
padding: 10,
},
eventTitle: {
color: theme.colors.text,
flexShrink: 1,
fontSize: 15,
fontWeight: '500',
},
imageContainer: {
borderRadius: theme.radius.sm,
height: 80,
resizeMode: 'cover',
width: '35%',
},
}))

export default NewsCard
6 changes: 5 additions & 1 deletion src/components/Map/MapScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,11 @@ const MapScreen = (): JSX.Element => {
}}
style={layerStyles.osmBackground}
>
<Text style={styles.osmAtrribution}>
<Text
style={styles.osmAtrribution}
numberOfLines={1}
ellipsizeMode="tail"
>
{'© OpenStreetMap'}
</Text>
</Pressable>
Expand Down
3 changes: 2 additions & 1 deletion src/components/allCards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
TimetableCard,
} from './Cards'
import LibraryCard from './Cards/LibraryCard'
import NewsCard from './Cards/NewsCard'

export const AllCards: Card[] = [
{
Expand Down Expand Up @@ -62,7 +63,7 @@ export const AllCards: Card[] = [
removable: true,
initial: [USER_STUDENT, USER_EMPLOYEE],
allowed: [USER_STUDENT, USER_EMPLOYEE],
card: () => <BaseCard title="news" onPressRoute="news" />,
card: () => <NewsCard />,
},
{
key: 'lecturers',
Expand Down
22 changes: 14 additions & 8 deletions src/data/licenses.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@
"licenseUrl": "https://github.com/expo/expo",
"parents": "neuland"
},
"[email protected]": {
"licenses": "MIT",
"repository": "https://github.com/expo/expo",
"licenseUrl": "https://github.com/expo/expo",
"parents": "neuland"
},
"[email protected]": {
"licenses": "MIT",
"repository": "https://github.com/expo/expo",
Expand Down Expand Up @@ -191,7 +197,7 @@
"licenseUrl": "https://github.com/expo/expo",
"parents": "neuland"
},
"[email protected].13": {
"[email protected].16": {
"licenses": "MIT",
"repository": "https://github.com/expo/expo",
"licenseUrl": "https://github.com/expo/expo",
Expand All @@ -203,7 +209,7 @@
"licenseUrl": "https://github.com/expo/expo",
"parents": "neuland"
},
"[email protected].15": {
"[email protected].17": {
"licenses": "MIT",
"repository": "https://github.com/expo/expo",
"licenseUrl": "https://github.com/expo/expo",
Expand All @@ -215,12 +221,6 @@
"licenseUrl": "https://github.com/krisk/Fuse/raw/master/LICENSE",
"parents": "neuland"
},
"[email protected]": {
"licenses": "MIT",
"repository": "https://github.com/jasonkuhrt/graphql-request",
"licenseUrl": "https://github.com/jasonkuhrt/graphql-request/raw/master/LICENSE",
"parents": "neuland"
},
"[email protected]": {
"licenses": "MIT",
"repository": "https://github.com/graphql/graphql-js",
Expand Down Expand Up @@ -329,6 +329,12 @@
"licenseUrl": "https://github.com/callstack/react-native-paper/raw/master/LICENSE.md",
"parents": "neuland"
},
"[email protected]": {
"licenses": "MIT",
"repository": "https://github.com/dohooo/react-native-reanimated-carousel",
"licenseUrl": "https://github.com/dohooo/react-native-reanimated-carousel/raw/master/LICENSE",
"parents": "neuland"
},
"[email protected]": {
"licenses": "MIT",
"repository": "https://github.com/software-mansion/react-native-reanimated",
Expand Down
3 changes: 3 additions & 0 deletions src/localization/de/navigation.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
"events": {
"by": "von {{name}}"
},
"news": {
"more": "Lese alle {{count}} Artikel"
},
"calendar": {
"exam": "Prüfung: {{name}}",
"ends": "endet "
Expand Down
3 changes: 3 additions & 0 deletions src/localization/en/navigation.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
"events": {
"by": "by {{name}}"
},
"news": {
"more": "Read all {{count}} articles"
},
"calendar": {
"exam": "Exam: {{name}}",
"ends": "ends "
Expand Down

0 comments on commit 7eeea3f

Please sign in to comment.