Skip to content

Commit

Permalink
fix: 데이터 제대로 매핑하지 못한 문제 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
kangju2000 committed Oct 24, 2023
1 parent 039b801 commit 7adcce7
Show file tree
Hide file tree
Showing 4 changed files with 268 additions and 16 deletions.
14 changes: 8 additions & 6 deletions src/components/ActivityItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Card
Expand Down Expand Up @@ -51,9 +53,9 @@ const ActivityItem = ({ activity }: Props) => {
</Box>
</Flex>
<Box textAlign="end" flexShrink="0">
<Text fontSize="14px">{dDay} 마감</Text>
<Text fontSize="14px">{!!activity.endAt ? `${dDay} 마감` : '마감일 없음'}</Text>
<Text fontSize="12px" _light={{ color: 'gray.500' }} _dark={{ color: 'gray.400' }}>
~{format(new Date(activity.endAt), 'yyyy.MM.dd HH:mm')}
{!!activity.endAt && `~${format(new Date(activity.endAt), 'yyyy.MM.dd HH:mm')}`}
</Text>
</Box>
</CardBody>
Expand Down
245 changes: 244 additions & 1 deletion src/data/dummyData.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ActivityType, Course } from '@/types'
import type { ActivityType, Contents, Course } from '@/types'

export const courseData: Course[] = [
{
Expand Down Expand Up @@ -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',
}
17 changes: 11 additions & 6 deletions src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -71,6 +75,10 @@ export const getActivities = async (
return acc
}, [])

// if (courseId === '91535') {
// console.log(videoAtCourseDocument, videoSubmittedArray, video)
// }

return [...assignment, ...video]
}

Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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 =
Expand All @@ -246,7 +251,7 @@ export const getVideoSubmitted = async (
return {
title,
hasSubmitted,
sectionTitle: currentSectionTitle,
sectionTitle,
}
})
.get()
Expand Down
8 changes: 5 additions & 3 deletions src/utils/filteredActivityList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7adcce7

Please sign in to comment.