Skip to content

Commit

Permalink
feat: 20분이 지나면 과제 크롤링하도록 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
kangju2000 committed Oct 22, 2023
1 parent c1742bc commit b3f79d0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/components/ActivityItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ const ActivityItem = ({ activity }: Props) => {
<Box>
<Flex align="center" gap="4px">
<ActivityBadge type={activity.type} />
<Text fontSize="14px" fontWeight="600">
<Text fontSize="14px" fontWeight="600" noOfLines={1}>
{activity.title}
</Text>
</Flex>
<Text fontSize="12px" color="gray.500">
<Text fontSize="12px" color="gray.500" noOfLines={1}>
{activity.courseTitle}
</Text>
</Box>
</Flex>
<Box textAlign="end">
<Box textAlign="end" flexShrink="0">
<Text fontSize="14px">{dDay} 마감</Text>
<Text fontSize="12px" color="gray.500">
~{format(new Date(activity.endAt), 'yyyy.MM.dd HH:mm')}
Expand Down
3 changes: 1 addition & 2 deletions src/components/ContentModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ const ContentModal = ({ isOpen, onClose }: Props) => {
isLoading,
} = useGetContents({ enabled: isOpen, local: true })

console.log(courseList, activityList)

return (
<Modal isCentered isOpen={isOpen} onClose={onClose}>
<ModalOverlay />
Expand Down Expand Up @@ -84,6 +82,7 @@ const ContentModal = ({ isOpen, onClose }: Props) => {
}}
cursor="pointer"
onClick={() => setSelectedCourseId(course.id)}
noOfLines={1}
>
{course.title}
</Text>
Expand Down
29 changes: 23 additions & 6 deletions src/hooks/useGetContents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,20 @@ import type { Contents } from '@/types'
import { getActivities, getCourses } from '@/services'
import { allProgress } from '@/utils'

const useGetContents = (
options: { local?: boolean; enabled?: boolean } = { local: false, enabled: true },
) => {
type Options = {
local?: boolean
enabled?: boolean
refreshTime?: number
}

const useGetContents = (options: Options) => {
const _options = {
local: false,
enabled: true,
refreshTime: 1000 * 60 * 20, // 20분
...options,
}

const [isLoading, setIsLoading] = useState(false)
const [pos, setPos] = useState(0)
const [data, setData] = useState<Contents>({
Expand Down Expand Up @@ -58,11 +69,17 @@ const useGetContents = (
}

useEffect(() => {
if (options.enabled) {
if (_options.enabled) {
setIsLoading(true)
options.local ? getLocalData() : getData()
_options.local ? getLocalData() : getData()
}
}, [_options.enabled])

useEffect(() => {
if (_options.refreshTime < new Date().getTime() - new Date(data.updateAt).getTime()) {
refetch()
}
}, [options.enabled])
}, [data])

return { data, pos, isLoading, refetch }
}
Expand Down

0 comments on commit b3f79d0

Please sign in to comment.