Skip to content

Commit

Permalink
Merge branch 'main' into feature/course-files-readable-names
Browse files Browse the repository at this point in the history
  • Loading branch information
Bri74 authored Feb 26, 2024
2 parents f2a18aa + c8ae7ff commit 55221a8
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 12 deletions.
2 changes: 2 additions & 0 deletions assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
"follow": "Follow",
"free": "Free",
"grade": "Grade",
"hide": "Hide",
"hour": "Hour",
"hours": "Hour",
"icon": "Icon",
Expand Down Expand Up @@ -220,6 +221,7 @@
"seat": "Seat",
"selectAnOption": "Please select an option",
"services": "Services",
"show": "Show",
"somethingWentWrong": "Something went wrong, try again later",
"startRefresh": "Loading",
"status": "Status",
Expand Down
4 changes: 3 additions & 1 deletion assets/translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
"follow": "Segui",
"free": "Libera",
"grade": "Voto",
"hide": "Nascondi",
"hour": "Orario",
"hours": "Ore",
"icon": "Icona",
Expand Down Expand Up @@ -220,6 +221,7 @@
"seat": "Postazione",
"selectAnOption": "Seleziona una delle opzioni",
"services": "Servizi",
"show": "Mostra",
"somethingWentWrong": "Qualcosa è andato storto, riprova più tardi",
"startRefresh": "Caricamento in corso",
"status": "Stato",
Expand Down Expand Up @@ -738,4 +740,4 @@
"videoPlayer": {
"speedSectionTitle": "Velocità"
}
}
}
3 changes: 3 additions & 0 deletions src/core/contexts/PreferencesContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const editablePreferenceKeys = [
'emailGuideRead',
'placesSearched',
'agendaScreen',
'hideGrades',
] as const;

export type PreferenceKey = (typeof editablePreferenceKeys)[number];
Expand All @@ -33,6 +34,7 @@ export const objectPreferenceKeys = [
'emailGuideRead',
'placesSearched',
'agendaScreen',
'hideGrades',
];

export type CoursesPreferences = {
Expand Down Expand Up @@ -60,6 +62,7 @@ export interface PreferencesContextBase {
layout: 'weekly' | 'daily';
filters: AgendaTypesFilterState;
};
hideGrades?: boolean;
}

export interface PreferencesContextProps extends PreferencesContextBase {
Expand Down
74 changes: 63 additions & 11 deletions src/features/teaching/screens/TeachingScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@ import {
View,
} from 'react-native';

import { faEye, faEyeSlash } from '@fortawesome/free-solid-svg-icons';
import { ActivityIndicator } from '@lib/ui/components/ActivityIndicator';
import { Card } from '@lib/ui/components/Card';
import { Col } from '@lib/ui/components/Col';
import { EmptyState } from '@lib/ui/components/EmptyState';
import { Icon } from '@lib/ui/components/Icon';
import { Metric } from '@lib/ui/components/Metric';
import { OverviewList } from '@lib/ui/components/OverviewList';
import { RefreshControl } from '@lib/ui/components/RefreshControl';
import { Row } from '@lib/ui/components/Row';
import { Section } from '@lib/ui/components/Section';
import { SectionHeader } from '@lib/ui/components/SectionHeader';
import { Text } from '@lib/ui/components/Text';
import { UnreadBadge } from '@lib/ui/components/UnreadBadge';
import { useStylesheet } from '@lib/ui/hooks/useStylesheet';
import { useTheme } from '@lib/ui/hooks/useTheme';
Expand Down Expand Up @@ -47,7 +50,7 @@ export const TeachingScreen = ({ navigation }: Props) => {
const { t } = useTranslation();
const { colors, palettes } = useTheme();
const styles = useStylesheet(createStyles);
const { courses: coursePreferences } = usePreferencesContext();
const { courses: coursePreferences, hideGrades } = usePreferencesContext();
const isOffline = useOfflineDisabled();
const { getUnreadsCount } = useNotifications();
const surveyCategoriesQuery = useGetSurveyCategories();
Expand Down Expand Up @@ -173,7 +176,10 @@ export const TeachingScreen = ({ navigation }: Props) => {
</OverviewList>
</Section>
<Section>
<SectionHeader title={t('common.transcript')} />
<SectionHeader
title={t('common.transcript')}
trailingItem={<HideGrades />}
/>

<View style={GlobalStyles.relative}>
<Card style={styles.transcriptCard}>
Expand All @@ -197,9 +203,11 @@ export const TeachingScreen = ({ navigation }: Props) => {
: t('transcriptMetricsScreen.weightedAverageLabel')
}
value={
studentQuery.data?.averageGradePurged ??
studentQuery.data?.averageGrade ??
'--'
hideGrades
? '--'
: studentQuery.data?.averageGradePurged ??
studentQuery.data?.averageGrade ??
'--'
}
color={colors.title}
/>
Expand All @@ -209,7 +217,9 @@ export const TeachingScreen = ({ navigation }: Props) => {
'transcriptMetricsScreen.estimatedFinalGradePurged',
)}
value={formatFinalGrade(
studentQuery.data?.estimatedFinalGradePurged,
hideGrades
? null
: studentQuery.data?.estimatedFinalGradePurged,
)}
color={colors.title}
/>
Expand All @@ -219,7 +229,9 @@ export const TeachingScreen = ({ navigation }: Props) => {
'transcriptMetricsScreen.estimatedFinalGrade',
)}
value={formatFinalGrade(
studentQuery.data?.estimatedFinalGrade,
hideGrades
? null
: studentQuery.data?.estimatedFinalGrade,
)}
color={colors.title}
/>
Expand All @@ -228,13 +240,19 @@ export const TeachingScreen = ({ navigation }: Props) => {
<ProgressChart
label={
studentQuery.data?.totalCredits
? `${studentQuery.data?.totalAcquiredCredits}/${
studentQuery.data?.totalCredits
}\n${t('common.ects')}`
? `${
hideGrades
? '--'
: studentQuery.data?.totalAcquiredCredits
}/${studentQuery.data?.totalCredits}\n${t(
'common.ects',
)}`
: undefined
}
data={
studentQuery.data && studentQuery.data.totalCredits
hideGrades
? []
: studentQuery.data?.totalCredits
? [
(studentQuery.data?.totalAttendedCredits ?? 0) /
studentQuery.data?.totalCredits,
Expand Down Expand Up @@ -263,6 +281,34 @@ export const TeachingScreen = ({ navigation }: Props) => {
);
};

const HideGrades = () => {
const { t } = useTranslation();
const { colors } = useTheme();
const styles = useStylesheet(createStyles);
const { hideGrades, updatePreference } = usePreferencesContext();

const label = hideGrades ? t('common.show') : t('common.hide');
const icon = hideGrades ? faEye : faEyeSlash;

const onHide = (value: boolean) => updatePreference('hideGrades', value);

return (
<View
style={styles.hideGradesSwitch}
accessibilityLabel={`${label}. ${t(
`common.activeStatus.${hideGrades}`,
)} `}
accessibilityRole="switch"
accessible={true}
>
<Icon icon={icon} color={colors.link} />
<Text variant="link" onPress={() => onHide(!hideGrades)}>
{label}
</Text>
</View>
);
};

const createStyles = ({ spacing }: Theme) =>
StyleSheet.create({
container: {
Expand All @@ -279,4 +325,10 @@ const createStyles = ({ spacing }: Theme) =>
top: 0,
right: 10,
},
hideGradesSwitch: {
display: 'flex',
flexDirection: 'row',
gap: spacing[1],
alignItems: 'center',
},
});

0 comments on commit 55221a8

Please sign in to comment.