Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Com 3870 #694

Merged
merged 8 commits into from
Dec 19, 2024
Merged
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
22 changes: 0 additions & 22 deletions src/components/CourseProfileStickyHeader/index.tsx

This file was deleted.

35 changes: 0 additions & 35 deletions src/components/CourseProfileStickyHeader/styles.ts

This file was deleted.

6 changes: 3 additions & 3 deletions src/components/ELearningCell/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useState } from 'react';
import React, { useEffect, useState } from 'react';
import { View, TouchableOpacity } from 'react-native';
import { ELearningStepType } from '../../types/StepTypes';
import { CourseModeType } from '../../types/CourseTypes';
Expand All @@ -18,7 +18,7 @@ type ELearningCellProps = {
endedActivity?: string,
}

const ELearningCell = ({ step, index, profileId, mode, endedActivity = '' }: ELearningCellProps) => {
const ELearningCell = React.memo(({ step, index, profileId, mode, endedActivity = '' }: ELearningCellProps) => {
const [isOpen, setIsOpen] = useState<boolean>(false);
const onPressChevron = () => { setIsOpen(prevState => !prevState); };
const [iconButtonStyle, setIconButtonStyle] = useState<object>(styles.iconButtonContainer);
Expand Down Expand Up @@ -48,6 +48,6 @@ const ELearningCell = ({ step, index, profileId, mode, endedActivity = '' }: ELe
{isOpen && <ActivityList activities={step.activities} profileId={profileId} mode={mode} />}
</View>
);
};
});

export default ELearningCell;
1 change: 1 addition & 0 deletions src/components/Modal/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default StyleSheet.create({
backgroundColor: WHITE,
borderRadius: BORDER_RADIUS.MD,
width: '90%',
maxHeight: '60%',
padding: PADDING.LG,
},
});
6 changes: 3 additions & 3 deletions src/components/activities/ActivityCell/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useReducer, useEffect } from 'react';
import React, { useReducer, useEffect } from 'react';
import { Text, View, TouchableOpacity } from 'react-native';
import { Ionicons } from '@expo/vector-icons';
import { useNavigation } from '@react-navigation/native';
Expand Down Expand Up @@ -32,7 +32,7 @@ const colorsReducer = (state: ColorStateType, action: ColorActionType): ColorSta
}
};

const ActivityCell = ({ activity, profileId, mode }: ActivityCellProps) => {
const ActivityCell = React.memo(({ activity, profileId, mode }: ActivityCellProps) => {
const setQuestionnaireAnswersList = useSetQuestionnaireAnswersList();
const disabled = !activity.cards.length;
const isCompleted = !!activity.activityHistories?.length;
Expand Down Expand Up @@ -83,6 +83,6 @@ const ActivityCell = ({ activity, profileId, mode }: ActivityCellProps) => {
</Text>
</View>
);
};
});

export default ActivityCell;
3 changes: 2 additions & 1 deletion src/components/activities/ActivityList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const ActivityList = ({ activities, profileId, mode }: ActivityListProps) => {
return (
<FlatList horizontal data={activities} keyExtractor={item => item._id}
renderItem={({ item }) => renderActivityCell(item)} ItemSeparatorComponent={renderSeparator}
contentContainerStyle={styles.cell} showsHorizontalScrollIndicator={false} />
contentContainerStyle={styles.cell} showsHorizontalScrollIndicator={false} initialNumToRender={5}
maxToRenderPerBatch={10} windowSize={5} />
);
};

Expand Down
10 changes: 5 additions & 5 deletions src/components/steps/LiveCell/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useState } from 'react';
import React, { useEffect, useState } from 'react';
import { View, TouchableOpacity } from 'react-native';
import { Feather } from '@expo/vector-icons';
import get from 'lodash/get';
Expand All @@ -19,7 +19,7 @@ type LiveCellProps = {
slots?: SlotType[],
}

const LiveCell = ({ step, index, mode, slots = [] }: LiveCellProps) => {
const LiveCell = React.memo(({ step, index, mode, slots = [] }: LiveCellProps) => {
const [isModalVisible, setIsModalVisible] = useState(false);
const [stepSlots, setStepSlots] = useState<SlotType[]>([]);
const [dates, setDates] = useState<Date[]>([]);
Expand All @@ -41,8 +41,8 @@ const LiveCell = ({ step, index, mode, slots = [] }: LiveCellProps) => {

return (
<>
<LiveCellInfoModal title={modalTitle} stepSlots={stepSlots} visible={isModalVisible}
onRequestClose={closeModal} />
{isModalVisible && (<LiveCellInfoModal title={modalTitle} stepSlots={stepSlots} visible={isModalVisible}
onRequestClose={closeModal} />)}
<TouchableOpacity style={[styles.container, styles.upperContainer]} onPress={openModal}>
<CalendarIcon slots={dates} progress={get(step, 'progress.live')} mode={mode} />
<StepCellTitle index={index} name={step.name} type={step.type} mode={mode} />
Expand All @@ -52,6 +52,6 @@ const LiveCell = ({ step, index, mode, slots = [] }: LiveCellProps) => {
</TouchableOpacity>
</>
);
};
});

export default LiveCell;
1 change: 1 addition & 0 deletions src/core/data/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export const DAY_OF_MONTH = 'd';
export const DAY_OF_WEEK_SHORT = 'ccc';
export const YEAR = 'yyyy';
export const DAY_D_MONTH = 'cccc d LLLL';
export const DAY_D_MONTH_YEAR = 'ccc d LLL yyyy';

// COMPANIDURATION FORMATS
export const LONG_DURATION_H_MM = 'h\'h\' mm\'min\'';
Expand Down
47 changes: 26 additions & 21 deletions src/screens/courses/list/TrainerCourses/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'array-flat-polyfill';
import { useState, useEffect, useCallback, useMemo } from 'react';
import { Text, View, ScrollView, ImageBackground } from 'react-native';
import { Text, View, ImageBackground, FlatList } from 'react-native';
import { useIsFocused, CompositeScreenProps } from '@react-navigation/native';
import { SafeAreaView } from 'react-native-safe-area-context';
import { StackScreenProps } from '@react-navigation/stack';
Expand Down Expand Up @@ -119,28 +119,33 @@ const TrainerCourses = ({ navigation }: TrainerCoursesProps) => {
: []
), [coursesDisplays]);

const renderHeader = () => <>
<Text style={commonStyles.title} testID='header'>Espace intervenant</Text>
{!!nextSteps.length && <View style={styles.nextSteps}>
<CoursesSection items={nextSteps} title="Les prochaines sessions que j'anime"
countStyle={styles.purpleCount} renderItem={renderNextStepsItem} type={EVENT_SECTION} />
</View>
}
</>;

const renderFooter = () => (!!coursesDisplays.length &&
<HomeScreenFooter source={require('../../../../../assets/images/pa_aidant_balade_bleu.webp')} />
);

const renderCourseDisplay = (content: CourseDisplayType) =>
<ImageBackground imageStyle={content.imageStyle} style={styles.sectionContainer}
key={content.title} source={content.source}>
<CoursesSection items={content.courses} title={content.title}
countStyle={content.countStyle} renderItem={renderItem} />
</ImageBackground>;

return (
<SafeAreaView style={commonStyles.container} edges={['top']}>
<ScrollView contentContainerStyle={styles.container} showsVerticalScrollIndicator={false}>
<Text style={commonStyles.title} testID='header'>Espace intervenant</Text>
{!!nextSteps.length &&
<View style={styles.nextSteps}>
<CoursesSection items={nextSteps} title="Les prochaines sessions que j'anime"
countStyle={styles.purpleCount} renderItem={renderNextStepsItem} type={EVENT_SECTION} />
</View>
}
{coursesDisplays.length
? coursesDisplays.map(content => (
<ImageBackground imageStyle={content.imageStyle} style={styles.sectionContainer}
key={content.title} source={content.source}>
<CoursesSection items={content.courses} title={content.title}
countStyle={content.countStyle} renderItem={renderItem} />
</ImageBackground>
))
: <TrainerEmptyState />
}
<HomeScreenFooter source={require('../../../../../assets/images/pa_aidant_balade_bleu.webp')} />
</ScrollView>
<View style={styles.container}>
<FlatList data={coursesDisplays} keyExtractor={item => item.title} ListHeaderComponent={renderHeader}
renderItem={({ item }) => renderCourseDisplay(item)} showsVerticalScrollIndicator={false}
ListEmptyComponent={<TrainerEmptyState />} ListFooterComponent={renderFooter}/>
</View>
</SafeAreaView>
);
};
Expand Down
23 changes: 17 additions & 6 deletions src/screens/courses/profile/AdminCourseProfile/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import { useState, useEffect, useCallback, useMemo } from 'react';
import { View, BackHandler, Text, ScrollView, TouchableOpacity, Image, FlatList } from 'react-native';
import {
View,
BackHandler,
Text,
ScrollView,
TouchableOpacity,
Image,
FlatList,
ActivityIndicator,
} from 'react-native';
import { Feather } from '@expo/vector-icons';
import pick from 'lodash/pick';
import uniqBy from 'lodash/uniqBy';
Expand Down Expand Up @@ -160,13 +169,12 @@ const AdminCourseProfile = ({ route, navigation }: AdminCourseProfileProps) => {
const getCourse = async () => {
try {
const fetchedCourse = await Courses.getCourse(route.params.courseId, OPERATIONS) as BlendedCourseType;
await refreshAttendanceSheets(fetchedCourse._id);
await getQuestionnaireQRCode(fetchedCourse._id);
await Promise.all([refreshAttendanceSheets(fetchedCourse._id), getQuestionnaireQRCode(fetchedCourse._id)]);

if (fetchedCourse.slots.length) setFirstSlot(fetchedCourse.slots[0]);
setCourse(fetchedCourse as BlendedCourseType);
setTitle(getTitle(fetchedCourse));
setIsSingle(SINGLE_COURSES_SUBPROGRAM_IDS.includes(fetchedCourse.subProgram._id));
setCourse(fetchedCourse as BlendedCourseType);
} catch (e: any) {
console.error(e);
setCourse(null);
Expand Down Expand Up @@ -272,7 +280,7 @@ const AdminCourseProfile = ({ route, navigation }: AdminCourseProfileProps) => {

const goToAttendanceSheetUpload = () => navigation.navigate('CreateAttendanceSheet', { isSingle });

return course && has(course, 'subProgram.program') && (
return course && has(course, 'subProgram.program') ? (
<SafeAreaView style={commonStyles.container} edges={['top']}>
<ScrollView showsVerticalScrollIndicator={false}>
<CourseAboutHeader screenTitle="ESPACE INTERVENANT" courseTitle={title} goBack={goBack} />
Expand Down Expand Up @@ -338,7 +346,10 @@ const AdminCourseProfile = ({ route, navigation }: AdminCourseProfileProps) => {
{imagePreview.visible && <ImagePreview source={pick(imagePreview, ['link', 'type'])}
onRequestClose={resetImagePreview} deleteFile={deleteAttendanceSheets} showButton={!course.archivedAt}/>}
</SafeAreaView>
);
)
: <View style={commonStyles.loadingContainer}>
<ActivityIndicator color={GREY[800]} size="small" />
</View>;
};

export default AdminCourseProfile;
Loading
Loading