Skip to content
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
3 changes: 3 additions & 0 deletions src/lang/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -2396,6 +2396,9 @@
"since": "منذ",
"till": "حتى",
"logout": "تسجيل الخروج",
"sortBy": "Sortieren nach",
"updatedAt": "Zuletzt aktualisiert",
"lectureDate": "Kurstermin",
"forStudents": {
"tabs": {
"handbook": "يدوي",
Expand Down
3 changes: 3 additions & 0 deletions src/lang/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@
"grade": "Klasse",
"since": "seit",
"till": "bis",
"sortBy": "Sortieren nach",
"updatedAt": "Zuletzt aktualisiert",
"lectureDate": "Kurstermin",
"lernfair": {
"languages": {
"albanisch": "Albanisch",
Expand Down
3 changes: 3 additions & 0 deletions src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2400,6 +2400,9 @@
"since": "since",
"till": "to",
"logout": "Log out",
"sortBy": "Sort by",
"updatedAt": "Last Updated",
"lectureDate": "Lecture Date",
"forStudents": {
"tabs": {
"handbook": "Manual",
Expand Down
3 changes: 3 additions & 0 deletions src/lang/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -2400,6 +2400,9 @@
"since": "с",
"till": "до",
"logout": "Выход из системы",
"sortBy": "Sortieren nach",
"updatedAt": "Zuletzt aktualisiert",
"lectureDate": "Kurstermin",
"forStudents": {
"tabs": {
"handbook": "Руководство",
Expand Down
3 changes: 3 additions & 0 deletions src/lang/tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -2400,6 +2400,9 @@
"since": "beri",
"till": "kadar",
"logout": "Oturumu kapat",
"sortBy": "Sortieren nach",
"updatedAt": "Zuletzt aktualisiert",
"lectureDate": "Kurstermin",
"forStudents": {
"tabs": {
"handbook": "Manuel",
Expand Down
3 changes: 3 additions & 0 deletions src/lang/uk.json
Original file line number Diff line number Diff line change
Expand Up @@ -2400,6 +2400,9 @@
"since": "з тих пір, як",
"till": "до тих пір, поки",
"logout": "Вийдіть з системи",
"sortBy": "Sortieren nach",
"updatedAt": "Zuletzt aktualisiert",
"lectureDate": "Kurstermin",
"forStudents": {
"tabs": {
"handbook": "Посібник",
Expand Down
37 changes: 27 additions & 10 deletions src/pages/student/CourseGroups.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import { getTrafficStatus, getTrafficStatusText } from '../../Utility';
import AlertMessage from '../../widgets/AlertMessage';
import AppointmentCard from '../../widgets/AppointmentCard';
import HSection from '../../widgets/HSection';
import { useState } from 'react';

type SubsetSubcourse = Pick<
Subcourse,
'id' | 'course' | 'nextLecture' | 'lectures' | 'maxParticipants' | 'participantsCount' | 'minGrade' | 'maxGrade' | 'isParticipant'
'id' | 'course' | 'nextLecture' | 'lectures' | 'maxParticipants' | 'participantsCount' | 'minGrade' | 'maxGrade' | 'isParticipant' | 'updatedAt'
>;

type GroupProps = {
Expand All @@ -21,6 +22,22 @@ type GroupProps = {
const CourseGroups: React.FC<GroupProps> = ({ currentCourses, draftCourses, pastCourses }) => {
const { t } = useTranslation();
const navigate = useNavigate();
const [sortedCourses, setSortedCourses] = useState({
current: currentCourses,
Copy link
Member

Choose a reason for hiding this comment

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

This does not reflect changes if the outer component passed in different courses. I think it would be better to add a state for the dropdown and do the sort in a memo:

const [sortOrder, setSortOrder] = useState('updated');

const sortedCourses = useMemo(() => {
  // ...
}, [courses, sortOrder]);

draft: draftCourses,
past: pastCourses,
});

function sortBy(section: 'current' | 'draft' | 'past' | undefined, value: 'updatedAt' | 'start') {
if (!section) return;
setSortedCourses((prev) => ({
...prev,
[section]: [...prev[section]!].sort((a, b) => {
const getDate = (course: SubsetSubcourse) => new Date(value === 'updatedAt' ? course.updatedAt : course.nextLecture?.start ?? 0).getTime();
return value === 'updatedAt' ? getDate(b) - getDate(a) : getDate(a) - getDate(b);
}),
}));
}

const renderSubcourse = (subcourse: SubsetSubcourse, index: number, showDate: boolean = true, readonly: boolean = false, inPast: boolean = false) => (
<div>
Expand Down Expand Up @@ -51,25 +68,25 @@ const CourseGroups: React.FC<GroupProps> = ({ currentCourses, draftCourses, past
return (
<Stack space={5}>
<Box>
<HSection scrollable title={t('matching.group.helper.course.tabs.tab1.current')}>
{((currentCourses?.length ?? 0) > 0 &&
currentCourses?.map((subcourse: any, index: number) => {
<HSection scrollable title={t('matching.group.helper.course.tabs.tab1.current')} showSort section={'current'} sortBy={sortBy}>
{((sortedCourses.current?.length ?? 0) > 0 &&
sortedCourses.current?.map((subcourse: any, index: number) => {
return renderSubcourse(subcourse, index);
})) || <AlertMessage content={t('course.empty.nocourses')} />}
</HSection>
</Box>
<Box>
<HSection scrollable title={t('matching.group.helper.course.tabs.tab1.draft')}>
{((draftCourses?.length ?? 0) > 0 &&
draftCourses?.map((subcourse: any, index: number) => {
<HSection scrollable title={t('matching.group.helper.course.tabs.tab1.draft')} showSort section={'draft'} sortBy={sortBy}>
{((sortedCourses.draft?.length ?? 0) > 0 &&
sortedCourses.draft?.map((subcourse: any, index: number) => {
return renderSubcourse(subcourse, index);
})) || <AlertMessage content={t('course.empty.noremissionordraft')} />}
</HSection>
</Box>
<Box>
<HSection scrollable title={t('matching.group.helper.course.tabs.tab1.past')}>
{((pastCourses?.length ?? 0) > 0 &&
pastCourses?.map((subcourse: any, index: number) => {
<HSection scrollable title={t('matching.group.helper.course.tabs.tab1.past')} section={'past'} sortBy={sortBy}>
{((sortedCourses.past?.length ?? 0) > 0 &&
sortedCourses.past?.map((subcourse: any, index: number) => {
return renderSubcourse(subcourse, index, true, false, true);
})) || <AlertMessage content={t('course.empty.nopastcourses')} />}
</HSection>
Expand Down
1 change: 1 addition & 0 deletions src/pages/student/StudentGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const StudentGroup: React.FC = () => {
start
duration
}
updatedAt
course {
courseState
name
Expand Down
22 changes: 19 additions & 3 deletions src/widgets/HSection.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { Box, Heading, Link, Row, Stack, useBreakpointValue, useTheme } from 'native-base';
import { Box, Heading, Link, Row, Select, Stack, useBreakpointValue, useTheme } from 'native-base';
import { ReactNode } from 'react';
import { useTranslation } from 'react-i18next';

type Props = {
title?: string;
section?: 'draft' | 'current' | 'past';
referenceTitle?: string;
showAll?: boolean;
showSort?: boolean;
children: ReactNode | ReactNode[];
onShowAll?: () => any;
sortBy?: (section: 'draft' | 'current' | 'past' | undefined, value: 'updatedAt' | 'start') => any;
smallTitle?: boolean;
isDark?: boolean;
scrollable?: boolean;
Expand All @@ -18,12 +21,15 @@ type Props = {

const HSection: React.FC<Props> = ({
title,
section,
referenceTitle,
isDark = false,
showAll = false,
showSort = false,
scrollable = true,
children,
onShowAll,
sortBy,
marginBottom,
wrap,
smallTitle,
Expand All @@ -45,11 +51,21 @@ const HSection: React.FC<Props> = ({
paddingY={space['0.5']}
>
{title && (
<Heading color={isDark ? 'lightText' : 'primary.900'} flex="1" fontSize={smallTitle ? fontSizes['md'] : fontSizes['xl']}>
<Heading color={isDark ? 'lightText' : 'primary.900'} flex="8" fontSize={smallTitle ? fontSizes['md'] : fontSizes['xl']}>
{title}
</Heading>
)}
{showAll && <Link onPress={onShowAll}>{referenceTitle ? referenceTitle : t('all')}</Link>}
{showAll && (
<Link onPress={onShowAll} flex="1">
{referenceTitle ? referenceTitle : t('all')}
</Link>
)}
{showSort && (
<Select placeholder={t('sortBy')} flex="2" onValueChange={(value) => sortBy && sortBy(section, value as 'updatedAt' | 'start')}>
<Select.Item label={t('updatedAt')} value="updatedAt" />
<Select.Item label={t('lectureDate')} value="start" />
</Select>
)}
</Stack>
<Row
flexWrap={wrap ? 'wrap' : 'nowrap'}
Expand Down