Skip to content

Commit

Permalink
Merge branch 'main' of github.com:polito/students-app into feature/pl…
Browse files Browse the repository at this point in the history
…aces-full-text-search
  • Loading branch information
umbopepato committed Dec 6, 2023
2 parents 3091268 + eb8a465 commit a2f0865
Show file tree
Hide file tree
Showing 21 changed files with 2,144 additions and 3,808 deletions.
3 changes: 2 additions & 1 deletion assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@
"virtualClassroom": "Virtual classroom",
"virtualClassroom_plural": "Virtual classrooms",
"visualization": "Visualization",
"year": "year"
"year": "year",
"yesterday": "Yesterday"
},
"contactsScreen": {
"cancelRecentSearch": "Remove",
Expand Down
3 changes: 2 additions & 1 deletion assets/translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@
"virtualClassroom": "Virtual classroom",
"virtualClassroom_plural": "Virtual classroom",
"visualization": "Visualizzazione",
"year": "anno"
"year": "anno",
"yesterday": "Ieri"
},
"contactsScreen": {
"cancelRecentSearch": "Rimuovi",
Expand Down
5,650 changes: 1,920 additions & 3,730 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@miblanchard/react-native-slider": "^2.2.0",
"@openspacelabs/react-native-zoomable-view": "^2.1.5",
"@orama/orama": "^2.0.0-beta.8",
"@polito/api-client": "^1.0.0-ALPHA.50",
"@polito/api-client": "^1.0.0-ALPHA.51",
"@react-native-async-storage/async-storage": "^1.17.11",
"@react-native-clipboard/clipboard": "^1.12.1",
"@react-native-community/blur": "^4.3.0",
Expand Down
4 changes: 1 addition & 3 deletions src/core/components/RootNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const RootNavigator = () => {
const { colors } = useTheme();
const styles = useStylesheet(createStyles);
const { data: student } = useGetStudent();
const { updatePreference } = usePreferencesContext();
const { onboardingStep, updatePreference } = usePreferencesContext();
const navigation = useNavigation<NativeStackNavigationProp<RootParamList>>();
const { getUnreadsCount } = usePushNotifications();
const campus = useGetCurrentCampus();
Expand All @@ -69,8 +69,6 @@ export const RootNavigator = () => {

const { data: messages } = useGetModalMessages();

const { onboardingStep } = usePreferencesContext();

useEffect(() => {
if (onboardingStep && onboardingStep >= 3) return;
navigation.navigate('TeachingTab', {
Expand Down
2 changes: 1 addition & 1 deletion src/core/contexts/PreferencesContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const editablePreferenceKeys = [
'agendaScreen',
] as const;

export type PreferenceKey = typeof editablePreferenceKeys[number];
export type PreferenceKey = (typeof editablePreferenceKeys)[number];

// Specify here complex keys, that require serialization/deserialization
export const objectPreferenceKeys = [
Expand Down
9 changes: 7 additions & 2 deletions src/core/hooks/useHideTabs.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
import { useCallback } from 'react';
import { Platform } from 'react-native';

import { useFocusEffect, useNavigation } from '@react-navigation/native';

import { tabBarStyle } from '../../utils/tab-bar';

export const useHideTabs = (
onFocusIn?: () => void,
onFocusOut?: () => void,
) => {
const navigation = useNavigation();
useFocusEffect(
useCallback(() => {
// Ios tab bar is hidden by default in modal context
if (Platform.OS === 'ios') return;
const parent = navigation.getParent()!;
parent.setOptions({
tabBarVisible: false,
tabBarStyle: { display: 'none' },
});
onFocusIn && onFocusIn();
return () => {
parent.setOptions({
tabBarVisible: true,
tabBarStyle,
});
onFocusOut && onFocusOut();
};
Expand Down
48 changes: 44 additions & 4 deletions src/core/queries/courseHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
CoursesApi,
UploadCourseAssignmentRequest,
} from '@polito/api-client';
import { MenuAction } from '@react-native-menu/menu';
import {
useMutation,
useQueries,
Expand Down Expand Up @@ -58,7 +59,7 @@ const setupCourses = (
const usedColors = Object.values(coursePreferences)
.map(cp => cp.color)
.filter(notNullish);
let colorData: typeof courseColors[0] | undefined;
let colorData: (typeof courseColors)[0] | undefined;
for (const currentColor of courseColors) {
if (!usedColors.includes(currentColor.color)) {
colorData = currentColor;
Expand Down Expand Up @@ -103,18 +104,19 @@ export const useGetCourses = () => {

export const CourseSectionEnum = {
Overview: 'overview',
Editions: 'editions',
Guide: 'guide',
Exams: 'exams',
Notices: 'notices',
Files: 'files',
Assignments: 'assignments',
} as const;
export type CourseSectionEnum =
typeof CourseSectionEnum[keyof typeof CourseSectionEnum];
export type CourseQueryEnum =
(typeof CourseSectionEnum)[keyof typeof CourseSectionEnum];

export const getCourseKey = (
courseId: number,
section: CourseSectionEnum = CourseSectionEnum.Overview,
section: CourseQueryEnum = CourseSectionEnum.Overview,
) => [COURSE_QUERY_PREFIX, courseId, section];

export const useGetCourse = (courseId: number) => {
Expand All @@ -141,6 +143,44 @@ export const useGetCourse = (courseId: number) => {
);
};

export const useGetCourseEditions = (courseId: number) => {
const coursesQuery = useGetCourses();

return useQuery(
getCourseKey(courseId, CourseSectionEnum.Editions),
() => {
const course = coursesQuery.data?.find(
c =>
c.id === courseId || c.previousEditions.some(e => e.id === courseId),
);
const editions: MenuAction[] = [];

if (!course || !course.previousEditions.length) return editions;

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),
),
);

return editions;
},
{
enabled: !!coursesQuery.data,
},
);
};

const courseFilesStaleTime = 60000; // 1 minute

export const useGetCourseFiles = (courseId: number) => {
Expand Down
24 changes: 22 additions & 2 deletions src/core/queries/offeringHooks.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { OfferingApi } from '@polito/api-client';
import { Degree as ApiDegree, OfferingApi } from '@polito/api-client';
import { MenuAction } from '@react-native-menu/menu';
import { useQuery } from '@tanstack/react-query';

import { compact } from 'lodash';

import { Degree } from '../../features/offering/types/Degree';
import { getShortYear } from '../../utils/offerings';
import { pluckData } from '../../utils/queries';

export const OFFERING_QUERY_KEY = ['offering'];
Expand All @@ -20,6 +23,20 @@ export const useGetOffering = () => {
);
};

const mapDegreeToOfferingDegree = (degree: ApiDegree): Degree => ({
...degree,
editions: degree.editions.map(edition => {
const degreeYear = Number(edition);
const previousDegreeYear = degreeYear - 1;

return {
id: edition,
title: `${previousDegreeYear}/${getShortYear(degreeYear)}`,
state: degreeYear === degree.year ? 'on' : undefined,
} as MenuAction;
}),
});

export const useGetOfferingDegree = ({
degreeId,
year,
Expand All @@ -30,7 +47,10 @@ export const useGetOfferingDegree = ({
const offeringClient = useOfferingClient();

return useQuery(compact([DEGREES_QUERY_PREFIX, degreeId, year]), () =>
offeringClient.getOfferingDegree({ degreeId, year }).then(pluckData),
offeringClient
.getOfferingDegree({ degreeId, year })
.then(pluckData)
.then(mapDegreeToOfferingDegree),
);
};

Expand Down
16 changes: 5 additions & 11 deletions src/features/agenda/screens/AgendaScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import { useCallback, useLayoutEffect, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
import {
FlatList,
NativeScrollEvent,
NativeSyntheticEvent,
StyleSheet,
View,
} from 'react-native';
import { FlatList, StyleSheet, View } from 'react-native';
import useStateRef from 'react-usestateref';

import { faCalendarWeek, faRefresh } from '@fortawesome/free-solid-svg-icons';
Expand Down Expand Up @@ -185,9 +179,9 @@ export const AgendaScreen = ({ navigation }: Props) => {
renderItem={({ item }) => (
<WeeklyAgenda agendaWeek={item} setTodayOffset={setTodayOffset} />
)}
ListHeaderComponent={
/* ListHeaderComponent={
isLoading ? <ActivityIndicator size="small" /> : undefined
}
}*/
ListFooterComponent={
<>
{isLoading ? <ActivityIndicator size="small" /> : undefined}
Expand All @@ -197,7 +191,7 @@ export const AgendaScreen = ({ navigation }: Props) => {
ItemSeparatorComponent={() => <View style={styles.separator} />}
scrollEventThrottle={100}
// onContentSizeChange={(contentWidth, contentHeight) => onContentHeightChange(contentHeight)}
onScroll={(event: NativeSyntheticEvent<NativeScrollEvent>) => {
/* onScroll={(event: NativeSyntheticEvent<NativeScrollEvent>) => {
const offsetY = event.nativeEvent.contentOffset.y;
if (!isLoading && offsetY < prevPageThreshold) {
Expand All @@ -207,7 +201,7 @@ export const AgendaScreen = ({ navigation }: Props) => {
return [firstWeek.minus({ week: 1 }), ...prev];
});
}
}}
}}*/
onEndReachedThreshold={0.3}
onEndReached={() => {
if (isLoading) return;
Expand Down
2 changes: 1 addition & 1 deletion src/features/agenda/types/AgendaItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const ALL_AGENDA_TYPES = [
'lecture',
] as const;

export type AgendaItemType = typeof ALL_AGENDA_TYPES[number];
export type AgendaItemType = (typeof ALL_AGENDA_TYPES)[number];

interface BaseAgendaItem {
key: string;
Expand Down
4 changes: 3 additions & 1 deletion src/features/courses/navigation/CourseNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ export const CourseNavigator = ({ route, navigation }: Props) => {

useEffect(() => {
if (!coursesQuery.data) return;
const course = coursesQuery.data.find(c => c.id === id);
const course = coursesQuery.data.find(
c => c.id === id || c.previousEditions.some(e => e.id === id),
);
if (!course) return;

navigation.setOptions({
Expand Down
7 changes: 4 additions & 3 deletions src/features/courses/navigation/CourseSharedScreens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { Assignment } from '../types/Assignment';
import { CourseNavigator } from './CourseNavigator';

export interface CourseSharedScreensParamList extends ParamListBase {
Course: { id: number };
Course: { id: number; animated?: boolean };
Notice: { noticeId: number; courseId: number };
CoursePreferences: { courseId: number; uniqueShortcode: string };
CourseDirectory: {
Expand Down Expand Up @@ -68,15 +68,16 @@ export const CourseSharedScreens = (
name="Course"
component={CourseNavigator}
getId={({ params }) => `${params.id}`}
options={{
options={({ route: { params } }) => ({
headerLargeStyle: {
backgroundColor: colors.headersBackground,
},
headerTransparent: false,
headerLargeTitle: false,
headerShadowVisible: false,
headerBackTitleVisible: false,
}}
animation: params?.animated ?? true ? 'default' : 'none',
})}
/>
<Stack.Screen
name="Notice"
Expand Down
Loading

0 comments on commit a2f0865

Please sign in to comment.