Skip to content

Commit

Permalink
Merge branch 'main' into hotfix/view-pdf-android
Browse files Browse the repository at this point in the history
  • Loading branch information
miky41195 committed Feb 7, 2025
2 parents b72a945 + 65adfe4 commit 31e132a
Show file tree
Hide file tree
Showing 19 changed files with 224 additions and 102 deletions.
10 changes: 10 additions & 0 deletions android/app/src/main/java/it/polito/students/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.facebook.react.ReactActivity
import com.facebook.react.ReactActivityDelegate
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled
import com.facebook.react.defaults.DefaultReactActivityDelegate
import android.os.Bundle

class MainActivity : ReactActivity() {

Expand All @@ -19,4 +20,13 @@ class MainActivity : ReactActivity() {
*/
override fun createReactActivityDelegate(): ReactActivityDelegate =
DefaultReactActivityDelegate(this, mainComponentName, fabricEnabled)


/**
* react-native-screens override
* https://github.com/software-mansion/react-native-screens?tab=readme-ov-file#android
*/
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(null);
}
}
7 changes: 6 additions & 1 deletion assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@
"averageLabel": "Average grade for admission to the Final Examination",
"finalAverageLabelDescription":{
"description": "It is the average grade, weighted according to the credits relating to each exam with a grade*, adjusted for the {{-excludedCreditsNumber}} worst credits",
"formula": "sum (grade * credits) / sum of credits,\nexcluding the {{-excludedCreditsNumber}} worst credits"
"formula": "(sum (grade * credits) / sum of credits) * (110/30) ,\nexcluding the {{-excludedCreditsNumber}} worst credits"
},
"laude": "*Honours does not count toward the calculation",
"masterAdmissionAverage": "Master admission average grade",
Expand All @@ -777,6 +777,11 @@
"title": "Career",
"weightedAverageLabelDescription":{
"description":"This is the average, weighted according to the credits relating to each exam with a grade*",
"formula": "(sum (grade * credits) / sum of credits) * (110/30)"
},
"weightedAverage": "Weighted average of grades",
"weightedAverageDescription":{
"description":"It is the average grade, weighted according to the credits relating to each exam with a grade*, expressed in thirtieths.",
"formula": "sum (grade * credits) / sum of credits"
},
"yourCareer": "Your career"
Expand Down
7 changes: 6 additions & 1 deletion assets/translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@
"averageLabel": "Media di ammissione all’esame di laurea",
"finalAverageLabelDescription":{
"description": "E’ la media, pesata in funzione dei crediti relativi ad ogni esame con voto*, depurata dei {{-excludedCreditsNumber}} peggiori crediti",
"formula": "somma (voto * crediti) / somma crediti,\nescludendo i peggiori {{-excludedCreditsNumber}} crediti"
"formula": "(somma (voto * crediti) / somma crediti) * (110/30),\nescludendo i peggiori {{-excludedCreditsNumber}} crediti"
},
"laude": "*Le lodi non concorrono al calcolo",
"masterAdmissionAverage": "Media di ammissione al II liv",
Expand All @@ -804,6 +804,11 @@
"title": "Carriera",
"weightedAverageLabelDescription":{
"description":"E’ la media, pesata in funzione dei crediti relativi ad ogni esame con voto*",
"formula": "(somma (voto * crediti) / somma crediti) * (110/30)"
},
"weightedAverage": "Media pesata dei voti",
"weightedAverageDescription":{
"description":"E’ la media, pesata in funzione dei crediti relativi ad ogni esame con voto*, espressa in trentesimi",
"formula": "somma (voto * crediti) / somma crediti"
},
"yourCareer": "La tua carriera"
Expand Down
16 changes: 5 additions & 11 deletions ios/students.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
2B8C6611CD99474EB542989F /* Montserrat-Regular.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = "Montserrat-Regular.ttf"; path = "../assets/fonts/Montserrat/Montserrat-Regular.ttf"; sourceTree = "<group>"; };
2BFB747F5587852157976D00 /* Pods-students.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-students.release.xcconfig"; path = "Target Support Files/Pods-students/Pods-students.release.xcconfig"; sourceTree = "<group>"; };
357F7B84A61240A55B98C650 /* Pods-students-studentsTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-students-studentsTests.debug.xcconfig"; path = "Target Support Files/Pods-students-studentsTests/Pods-students-studentsTests.debug.xcconfig"; sourceTree = "<group>"; };
3ADB1A47BEB74AAA9FE28FB1 /* OFL.txt */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = OFL.txt; path = ../assets/fonts/Montserrat/OFL.txt; sourceTree = "<group>"; };
3ADB1A47BEB74AAA9FE28FB1 /* OFL.txt */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = OFL.txt; path = ../assets/fonts/Montserrat/OFL.txt; sourceTree = "<group>"; };
424C348DF9254E8C89FEA6CA /* Montserrat-ExtraBold.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = "Montserrat-ExtraBold.ttf"; path = "../assets/fonts/Montserrat/Montserrat-ExtraBold.ttf"; sourceTree = "<group>"; };
4D12524BABDE4FD7BA5DBD6E /* Montserrat-BoldItalic.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = "Montserrat-BoldItalic.ttf"; path = "../assets/fonts/Montserrat/Montserrat-BoldItalic.ttf"; sourceTree = "<group>"; };
55241F502937B71E0009DF9A /* hermes.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = hermes.xcframework; path = "Pods/hermes-engine/destroot/Library/Frameworks/universal/hermes.xcframework"; sourceTree = "<group>"; };
Expand All @@ -88,7 +88,7 @@
96125A242AD6B04500CF037A /* students.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; name = students.entitlements; path = students/students.entitlements; sourceTree = "<group>"; };
ACC8FDE515D5BD1D8D01BAF8 /* libPods-students-students dev.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-students-students dev.a"; sourceTree = BUILT_PRODUCTS_DIR; };
B44D6C2229F17BF2001BA0DC /* students dev.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "students dev.app"; sourceTree = BUILT_PRODUCTS_DIR; };
B44D6C2329F17BF2001BA0DC /* DevInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = students/DevInfo.plist; sourceTree = "<group>"; };
B44D6C2329F17BF2001BA0DC /* students/DevInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = students/DevInfo.plist; sourceTree = "<group>"; };
B7D759302BF2478B00178B49 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
B813406DDE44447AB8717E6E /* Montserrat-SemiBold.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = "Montserrat-SemiBold.ttf"; path = "../assets/fonts/Montserrat/Montserrat-SemiBold.ttf"; sourceTree = "<group>"; };
BADEE9E139127DB51296F263 /* libPods-students-studentsTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-students-studentsTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -151,7 +151,7 @@
isa = PBXGroup;
children = (
96125A242AD6B04500CF037A /* students.entitlements */,
B44D6C2329F17BF2001BA0DC /* DevInfo.plist */,
B44D6C2329F17BF2001BA0DC /* students/DevInfo.plist */,
13B07FAF1A68108700A75B9A /* AppDelegate.h */,
13B07FB01A68108700A75B9A /* AppDelegate.mm */,
13B07FB51A68108700A75B9A /* Images.xcassets */,
Expand Down Expand Up @@ -911,10 +911,7 @@
"-DFOLLY_MOBILE=1",
"-DFOLLY_USE_LIBCPP=1",
);
OTHER_LDFLAGS = (
"$(inherited)",
" ",
);
OTHER_LDFLAGS = "$(inherited) ";
PRODUCT_NAME = "PoliTO Students";
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
Expand Down Expand Up @@ -991,10 +988,7 @@
"-DFOLLY_MOBILE=1",
"-DFOLLY_USE_LIBCPP=1",
);
OTHER_LDFLAGS = (
"$(inherited)",
" ",
);
OTHER_LDFLAGS = "$(inherited) ";
PRODUCT_NAME = "PoliTO Students";
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
Expand Down
4 changes: 2 additions & 2 deletions ios/students/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<!-- Do not change NSAllowsArbitraryLoads to true, or you will risk app rejection! -->
<key>NSAllowsArbitraryLoads</key>
<false/>
<key>NSAllowsLocalNetworking</key>
Expand All @@ -39,7 +38,7 @@
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Access to current position to check-in bookings</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Access to current position to check-in bookings</string>
<string>Access to current position to check-in bookings</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Scan documents and pick images for assignments and ticket attachments</string>
<key>UIAppFonts</key>
Expand All @@ -59,6 +58,7 @@
<array>
<string>fetch</string>
<string>remote-notification</string>
<string>audio</string>
</array>
<key>UIFileSharingEnabled</key>
<true/>
Expand Down
22 changes: 19 additions & 3 deletions lib/ui/components/ModalContent.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PropsWithChildren } from 'react';
import { PropsWithChildren, useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import { StyleSheet, View } from 'react-native';
import { ScrollView, StyleSheet, View } from 'react-native';

import { faTimes } from '@fortawesome/free-solid-svg-icons';
import { HeaderAccessory } from '@lib/ui/components/HeaderAccessory';
Expand All @@ -12,16 +12,26 @@ import { Theme } from '@lib/ui/types/Theme';
type Props = {
title: string;
close: () => void;
scrollViewRef?: any;
setScrollOffset?: (value: number) => void;
};

export const ModalContent = ({
children,
close,
title,
scrollViewRef,
setScrollOffset,
}: PropsWithChildren<Props>) => {
const styles = useStylesheet(createStyles);
const { t } = useTranslation();

const handleOnScroll = useCallback((event: any) => {
if (setScrollOffset) {
setScrollOffset(event.nativeEvent.contentOffset.y);
}
}, []);

return (
<View style={styles.container}>
<HeaderAccessory
Expand All @@ -39,7 +49,13 @@ export const ModalContent = ({
adjustSpacing="left"
/>
</HeaderAccessory>
<View>{children}</View>
<ScrollView
onScroll={handleOnScroll}
scrollEventThrottle={120}
ref={scrollViewRef}
>
{children}
</ScrollView>
</View>
);
};
Expand Down
30 changes: 17 additions & 13 deletions src/core/components/BottomModal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PropsWithChildren, useRef } from 'react';
import { ScrollView, View } from 'react-native';
import { PropsWithChildren, useCallback } from 'react';
import { View } from 'react-native';
import Modal from 'react-native-modal';

import { SCREEN_HEIGHT, SCREEN_WIDTH } from '@gorhom/bottom-sheet';
Expand All @@ -8,29 +8,30 @@ export type BottomModalProps = PropsWithChildren<{
visible: boolean;
onClose?: () => void;
dismissable?: boolean;
scrollOffset?: number;
scrollViewRef?: any;
}>;

export const BottomModal = ({
children,
visible,
onClose,
dismissable,
scrollOffset,
scrollViewRef,
}: BottomModalProps) => {
const handleCloseModal = () => {
dismissable && onClose?.();
};

const scrollViewRef = useRef<ScrollView>(null);

const handleScrollTo = (position: {
x?: number;
y?: number;
animated?: boolean;
}) => {
if (scrollViewRef.current) {
scrollViewRef.current.scrollTo(position);
}
};
const handleScrollTo = useCallback(
(p: any) => {
if (scrollViewRef && scrollViewRef.current) {
scrollViewRef.current.scrollTo(p);
}
},
[scrollViewRef],
);

return (
<Modal
Expand All @@ -51,9 +52,12 @@ export const BottomModal = ({
supportedOrientations={['landscape', 'portrait']}
onBackdropPress={handleCloseModal}
scrollTo={handleScrollTo}
propagateSwipe
useNativeDriver={false}
useNativeDriverForBackdrop
onSwipeComplete={handleCloseModal}
scrollOffset={scrollOffset}
scrollOffsetMax={100}
>
<View>{children}</View>
</Modal>
Expand Down
23 changes: 23 additions & 0 deletions src/core/hooks/useNotifications.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useCallback } from 'react';

import { CourseOverviewPreviousEditionsInner } from '@polito/api-client';
import { Notification } from '@polito/api-client/models/Notification';
import { useNavigation } from '@react-navigation/native';
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
Expand Down Expand Up @@ -160,6 +161,27 @@ export const useNotifications = () => {
[unreadNotifications],
);

const getUnreadsCountPerCourse = useCallback(
(
courseId?: number | null,
prevEditions?: CourseOverviewPreviousEditionsInner[],
) => {
if (courseId === undefined || !prevEditions) return 0;
const courseIds = prevEditions.map(e => e.id);
if (courseId) {
courseIds.push(courseId);
}
return (
courseIds.reduce(
(acc, eid) =>
acc + (getUnreadsCount(['teaching', 'courses', eid]) ?? 0),
0,
) || undefined
);
},
[getUnreadsCount],
);

const navigateToUpdate = useCallback(
(notification?: RemoteMessage) => {
if (!notification || !notification.data?.polito_transazione) {
Expand Down Expand Up @@ -216,5 +238,6 @@ export const useNotifications = () => {
navigateToUpdate,
clearNotificationScope,
getUnreadsCount,
getUnreadsCountPerCourse,
};
};
35 changes: 7 additions & 28 deletions src/core/queries/courseHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
CoursesApi,
UploadCourseAssignmentRequest,
} from '@polito/api-client';
import { MenuAction } from '@react-native-menu/menu';
import {
useMutation,
useQueries,
Expand Down Expand Up @@ -158,41 +157,21 @@ export const useGetCourseEditions = (courseId: number) => {
c =>
c.id === courseId || c.previousEditions.some(e => e.id === courseId),
);
const editions: MenuAction[] = [];
const editions: CourseOverviewPreviousEditionsInner[] = [];
if (!course || !course.previousEditions.length) return editions;
if (course.id) {
editions.push(
{
id: `${course.id}`,
title: course.year,
state: courseId === course?.id ? 'on' : undefined,
},
...course.previousEditions.map(
e =>
({
id: `${e.id}`,
title: e.year,
state: courseId === e.id ? 'on' : undefined,
} as MenuAction),
),
);
editions.push({
id: course.id,
year: course.year,
});
editions.push(...course.previousEditions);
} else {
const prevEditions = course.previousEditions
.filter(e => e.id !== null)
.sort((a, b) => +b.year - +a.year)
.slice(1);
editions.push(
...prevEditions.map(
e =>
({
id: `${e.id}`,
title: e.year,
state: courseId === e.id ? 'on' : undefined,
} as MenuAction),
),
);
editions.push(...prevEditions);
}

return editions;
},
{
Expand Down
2 changes: 0 additions & 2 deletions src/features/courses/components/CourseListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ export const CourseListItem = ({
screen: 'Course',
params: {
id: courseInfo?.id,
courseName: courseInfo?.name,
uniqueShortcode: courseInfo?.uniqueShortcode,
},
}
: undefined
Expand Down
1 change: 0 additions & 1 deletion src/features/courses/navigation/CourseNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export const CourseNavigator = ({ route, navigation }: Props) => {
const titleStyles = useTitlesStyles(theme);

const { id } = route.params;

const coursesQuery = useGetCourses();

useEffect(() => {
Expand Down
Loading

0 comments on commit 31e132a

Please sign in to comment.