Skip to content

Commit

Permalink
fetch sessions based on configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
Bahugunajii committed Nov 25, 2024
1 parent 3856c95 commit 33ead2e
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,27 +80,37 @@ export default function Home() {
const fetchUserSessions = async () => {
try {
const [liveSessionData, quizSessionData] = await Promise.all([
group !== 'AllIndiaStudents' ? fetchUserSession(userDbId!) : Promise.resolve([]),
fetchUserSession(userDbId!, true)
groupConfig.showLiveClasses ? fetchUserSession(userDbId!) : Promise.resolve([]),
groupConfig.showTests || groupConfig.showPracticeTests || groupConfig.showHomework
? fetchUserSession(userDbId!, true)
: Promise.resolve([])
]);

const quizData = await Promise.all(quizSessionData.map(async (quiz: Session) => {
const sessionOccurrenceData = await getSessionOccurrences(quiz.session_id);
if (!sessionOccurrenceData) return null;
return sessionOccurrenceData;
}));
const flattenedQuizData = quizData.flat();
const quizSessions = flattenedQuizData.filter(flattenedSessionsData => flattenedSessionsData.session.platform === 'quiz');
setQuizzes(quizSessions);
if (groupConfig.showTests || groupConfig.showPracticeTests || groupConfig.showHomework) {
const quizData = await Promise.all(quizSessionData.map(async (quiz: Session) => {
const sessionOccurrenceData = await getSessionOccurrences(quiz.session_id);
if (!sessionOccurrenceData) return null;
return sessionOccurrenceData;
}));

const flattenedQuizData = quizData.flat();
const quizSessions = flattenedQuizData.filter(flattenedSessionsData =>
flattenedSessionsData.session.platform === 'quiz'
);
setQuizzes(quizSessions);
}

if (group !== 'AllIndiaStudents') {
if (groupConfig.showLiveClasses && liveSessionData.length > 0) {
const sessionsData = await Promise.all(liveSessionData.map(async (liveSession: Session) => {
const sessionOccurrenceData = await getSessionOccurrences(liveSession.session_id);
if (!sessionOccurrenceData) return null;
return sessionOccurrenceData;
}));

const flattenedSessionsData = sessionsData.flat();
const liveSessions = flattenedSessionsData.filter(flattenedSessionsData => flattenedSessionsData.session.platform === 'meet');
const liveSessions = flattenedSessionsData.filter(flattenedSessionsData =>
flattenedSessionsData.session.platform === 'meet'
);
setLiveClasses(liveSessions);
}

Expand Down

0 comments on commit 33ead2e

Please sign in to comment.