diff --git a/src/components/ActivityItem.tsx b/src/components/ActivityItem.tsx index afc483f..306b33b 100644 --- a/src/components/ActivityItem.tsx +++ b/src/components/ActivityItem.tsx @@ -11,10 +11,12 @@ type Props = { } const ActivityItem = ({ activity }: Props) => { - const dDay = formatDistanceToNowStrict(new Date(activity.endAt), { - addSuffix: true, - locale: ko, - }) + const dDay = + !!activity.endAt && + formatDistanceToNowStrict(new Date(activity.endAt), { + addSuffix: true, + locale: ko, + }) return ( { - {dDay} 마감 + {!!activity.endAt ? `${dDay} 마감` : '마감일 없음'} - ~{format(new Date(activity.endAt), 'yyyy.MM.dd HH:mm')} + {!!activity.endAt && `~${format(new Date(activity.endAt), 'yyyy.MM.dd HH:mm')}`} diff --git a/src/data/dummyData.ts b/src/data/dummyData.ts index 849a935..d1d73f4 100644 --- a/src/data/dummyData.ts +++ b/src/data/dummyData.ts @@ -1,4 +1,4 @@ -import type { ActivityType, Course } from '@/types' +import type { ActivityType, Contents, Course } from '@/types' export const courseData: Course[] = [ { @@ -437,3 +437,246 @@ export const ActivityData: ActivityType[] = [ type: 'assignment', }, ] + +export const contentsData: Contents = { + activityList: [ + { + courseId: '91535', + courseTitle: '지능형 정보 기술', + endAt: '2023-09-15 00:00:00', + hasSubmitted: true, + id: '718775', + sectionTitle: '2주차 [9월08일 - 9월14일]', + startAt: '2023-09-08 00:00:00', + title: '2주차 과제 제출', + type: 'assignment', + }, + { + courseId: '91535', + courseTitle: '지능형 정보 기술', + endAt: '2023-09-22 00:00:00', + hasSubmitted: true, + id: '718782', + sectionTitle: '3주차 [9월15일 - 9월21일]', + startAt: '2023-09-14 00:00:00', + title: '3주차 과제 제출', + type: 'assignment', + }, + { + courseId: '91535', + courseTitle: '지능형 정보 기술', + endAt: '2023-09-29 00:00:00', + hasSubmitted: true, + id: '718789', + sectionTitle: '4주차 [9월22일 - 9월28일]', + startAt: '2023-09-21 00:00:00', + title: '4주차 과제 제출', + type: 'assignment', + }, + { + courseId: '91535', + courseTitle: '지능형 정보 기술', + endAt: '2023-10-13 00:00:00', + hasSubmitted: true, + id: '718805', + sectionTitle: '6주차 [10월06일 - 10월12일]', + startAt: '2023-10-05 00:00:00', + title: '6주차 과제 제출', + type: 'assignment', + }, + { + courseId: '91727', + courseTitle: '취·창업 진로세미나', + endAt: '2023-10-23 10:00:00', + hasSubmitted: true, + id: '745221', + sectionTitle: '7주차 [10월13일 - 10월19일]', + startAt: '2023-10-18 00:00:00', + title: '필수과제1, 2 제출', + type: 'assignment', + }, + { + courseId: '93692', + courseTitle: '웹DB프로그래밍', + endAt: '2023-10-05 00:00:00', + hasSubmitted: true, + id: '735753', + sectionTitle: '3주차 [9월15일 - 9월21일]', + startAt: '2023-10-02 00:00:00', + title: '과제 1', + type: 'assignment', + }, + { + courseId: '93692', + courseTitle: '웹DB프로그래밍', + endAt: '2023-10-12 00:00:00', + hasSubmitted: true, + id: '738570', + sectionTitle: '5주차 [9월29일 - 10월05일]', + startAt: '2023-10-06 00:00:00', + title: '과제 2', + type: 'assignment', + }, + { + courseId: '93692', + courseTitle: '웹DB프로그래밍', + endAt: '2023-10-19 00:00:00', + hasSubmitted: true, + id: '741966', + sectionTitle: '6주차 [10월06일 - 10월12일]', + startAt: '2023-10-12 00:00:00', + title: '과제 3', + type: 'assignment', + }, + { + courseId: '93692', + courseTitle: '웹DB프로그래밍', + endAt: '', + hasSubmitted: false, + id: '746381', + sectionTitle: '7주차 [10월13일 - 10월19일]', + startAt: '2023-10-19 00:00:00', + title: '과제 4', + type: 'assignment', + }, + { + courseId: '93769', + courseTitle: '클라우드 네이티브', + endAt: '2023-10-11 23:59:00', + hasSubmitted: true, + id: '735235', + sectionTitle: '5주차 [9월29일 - 10월05일]', + startAt: '2023-10-04 00:00:00', + title: '5주차 1-4차시 출석 과제', + type: 'assignment', + }, + { + courseId: '93769', + courseTitle: '클라우드 네이티브', + endAt: '2023-10-10 23:59:00', + hasSubmitted: true, + id: '735227', + sectionTitle: '5주차 [9월29일 - 10월05일]', + startAt: '2023-10-04 00:00:00', + timeInfo: '', + title: '5주차 1차시 도커 허브', + type: 'video', + }, + { + courseId: '93769', + courseTitle: '클라우드 네이티브', + endAt: '2023-10-10 23:59:00', + hasSubmitted: true, + id: '735230', + sectionTitle: '5주차 [9월29일 - 10월05일]', + startAt: '2023-10-04 00:00:00', + timeInfo: '', + title: '5주차 2차시 도커 허브', + type: 'video', + }, + { + courseId: '93769', + courseTitle: '클라우드 네이티브', + endAt: '2023-10-10 23:59:00', + hasSubmitted: true, + id: '735232', + sectionTitle: '5주차 [9월29일 - 10월05일]', + startAt: '2023-10-04 00:00:00', + timeInfo: '', + title: '5주차 3차시 도커 컴포즈', + type: 'video', + }, + { + courseId: '93769', + courseTitle: '클라우드 네이티브', + endAt: '2023-10-10 23:59:00', + hasSubmitted: true, + id: '735233', + sectionTitle: '5주차 [9월29일 - 10월05일]', + startAt: '2023-10-04 00:00:00', + timeInfo: '', + title: '5주차 4차시 도커 컴포즈', + type: 'video', + }, + { + courseId: '93771', + courseTitle: '고급웹프로그래밍', + endAt: '2023-10-09 23:59:00', + hasSubmitted: true, + id: '735896', + sectionTitle: '5주차 [9월29일 - 10월05일]', + startAt: '2023-10-03 00:00:00', + title: '5주차_과제', + type: 'assignment', + }, + { + courseId: '93771', + courseTitle: '고급웹프로그래밍', + endAt: '2023-10-23 23:59:00', + hasSubmitted: true, + id: '744330', + sectionTitle: '7주차 [10월13일 - 10월19일]', + startAt: '2023-10-17 00:00:00', + title: '7주차_과제', + type: 'assignment', + }, + { + courseId: '93771', + courseTitle: '고급웹프로그래밍', + endAt: '2023-10-30 23:59:00', + hasSubmitted: false, + id: '747035', + sectionTitle: '8주차 [10월20일 - 10월26일]', + startAt: '2023-10-24 00:00:00', + title: '8주차_과제', + type: 'assignment', + }, + { + courseId: '93771', + courseTitle: '고급웹프로그래밍', + endAt: '2023-10-09 23:59:00', + hasSubmitted: true, + id: '735894', + sectionTitle: '5주차 [9월29일 - 10월05일]', + startAt: '2023-10-03 00:00:00', + timeInfo: '', + title: '5주차_수업1', + type: 'video', + }, + { + courseId: '93771', + courseTitle: '고급웹프로그래밍', + endAt: '2023-10-09 23:59:00', + hasSubmitted: true, + id: '735895', + sectionTitle: '5주차 [9월29일 - 10월05일]', + startAt: '2023-10-03 00:00:00', + timeInfo: '', + title: '5주차_수업2', + type: 'video', + }, + ], + courseList: [ + { + id: '91535', + title: '지능형 정보 기술', + }, + { + id: '91727', + title: '취·창업 진로세미나', + }, + { + id: '93692', + title: '웹DB프로그래밍', + }, + { + id: '93769', + title: '클라우드 네이티브', + }, + { + id: '93771', + title: '고급웹프로그래밍', + }, + ], + updateAt: '2023-10-24T11:24:04.212Z', +} diff --git a/src/services/index.ts b/src/services/index.ts index dff6f94..1b6eec5 100644 --- a/src/services/index.ts +++ b/src/services/index.ts @@ -62,6 +62,10 @@ export const getActivities = async ( return acc }, []) + // if ((courseId = '93769')) { + // console.log(assignmentAtCourseDocument, assignmentSubmittedArray, assignment) + // } + const video = videoAtCourseDocument.reduce((acc, cur) => { const findVideo = videoSubmittedArray.find( v => v.sectionTitle === cur.sectionTitle && v.title === cur.title, @@ -71,6 +75,10 @@ export const getActivities = async ( return acc }, []) + // if (courseId === '91535') { + // console.log(videoAtCourseDocument, videoSubmittedArray, video) + // } + return [...assignment, ...video] } @@ -142,7 +150,7 @@ const getAssignmentAtCourseDocument = ( const getVideoAtCourseDocument = ($: cheerio.CheerioAPI, courseId: string) => { return $('.total_sections .content') .map((i, el) => { - const sectionTitle = $(el).find('.sectionname').text().trim() + const sectionTitle = $(el).find('.sectionname').text().trim().split(' ')[0].match(/\d+/g)[0] return $(el) .find('.activity.vod .activityinstance') @@ -230,14 +238,11 @@ export const getVideoSubmitted = async ( ? '.user_progress_table tbody tr' : '.user_progress tbody tr' - let currentSectionTitle = '' - return $(className) .map((i, el) => { - if ($(el).find('.sectiontitle').length) - currentSectionTitle = $(el).find('.sectiontitle').attr('title') const std = $(el).find('.text-center.hidden-xs.hidden-sm') const title = std.prev().text().trim() + const sectionTitle = $(el).find('tr td').first().text().trim() const requiredTime = std.text().trim() const totalStudyTime = std.next().clone().children().remove().end().text().trim() const hasSubmitted = @@ -246,7 +251,7 @@ export const getVideoSubmitted = async ( return { title, hasSubmitted, - sectionTitle: currentSectionTitle, + sectionTitle, } }) .get() diff --git a/src/utils/filteredActivityList.ts b/src/utils/filteredActivityList.ts index 98f0c75..6fc0d22 100644 --- a/src/utils/filteredActivityList.ts +++ b/src/utils/filteredActivityList.ts @@ -16,9 +16,11 @@ const sortAcitivityList = (activityList: ActivityType[]) => { const activityListByStatus = (activityList: ActivityType[], status: string) => { if (status === '진행중인 과제') { - return activityList.filter( - activity => new Date(activity.endAt).getTime() > new Date().getTime(), - ) + return activityList.filter(activity => { + if (!!activity.endAt) return new Date(activity.endAt).getTime() > new Date().getTime() + + return true + }) } return activityList