-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat(time): TimeTable Modal 추가기능 #215
Changes from 7 commits
a117dc7
d24e643
acdc9c8
1e820de
b6363bf
5bb6f39
17421c2
138d407
acc1341
7ce0d30
3f3d3d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
Copyright (c) 2021 Kil Hyung-jin, with Reserved Font Name Pretendard. | ||
https://github.com/orioncactus/pretendard | ||
|
||
This Font Software is licensed under the SIL Open Font License, Version 1.1. | ||
This license is copied below, and is also available with a FAQ at: | ||
http://scripts.sil.org/OFL | ||
*/ | ||
|
||
@font-face { | ||
font-family: 'Pretendard Variable'; | ||
font-weight: 45 920; | ||
font-style: normal; | ||
font-display: swap; | ||
src: url('/font/PretendardVariable.woff2') format('woff2-variations'); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use client'; | ||
|
||
import { useCallback, useEffect, useRef } from 'react'; | ||
|
||
export default function useInfiniteScroll(callback: () => void) { | ||
const targetRef = useRef<HTMLElement | null>(null); | ||
const observerRef = useRef<IntersectionObserver | null>(null); | ||
|
||
const handleIntersection = useCallback( | ||
([target]: IntersectionObserverEntry[]) => { | ||
if (target.isIntersecting) { | ||
callback(); | ||
} | ||
}, | ||
[callback], | ||
); | ||
|
||
useEffect(() => { | ||
if (observerRef.current) { | ||
observerRef.current.disconnect(); // 기존 옵저버 해제 | ||
} | ||
|
||
observerRef.current = new IntersectionObserver(handleIntersection, { | ||
root: null, | ||
rootMargin: '0px', | ||
threshold: 1.0, | ||
}); | ||
|
||
if (targetRef.current) { | ||
observerRef.current.observe(targetRef.current); | ||
} | ||
|
||
return () => { | ||
observerRef.current?.disconnect(); | ||
}; | ||
}, [handleIntersection]); | ||
|
||
return targetRef; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
'use client'; | ||
|
||
export default function getAPIURL(endPoint: string) { | ||
return new URL(`${process.env.NEXT_PUBLIC_API_URL}/api/${endPoint}`); | ||
return new URL(`${process.env.NEXT_PUBLIC_SERVER_URL}/api/${endPoint}`); | ||
} |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -1,10 +1,19 @@ | ||||
'use client'; | ||||
|
||||
import { Suspense, memo } from 'react'; | ||||
|
||||
import { MODAL_KEY } from '@/shared/constants'; | ||||
import { | ||||
useEditableSearchParams, | ||||
useInfiniteScroll, | ||||
useModalAction, | ||||
} from '@/shared/hooks'; | ||||
import { | ||||
type GetLectureListParams, | ||||
type GetLectureListResponseValue, | ||||
useLectureList, | ||||
} from '@/widgets/time-table'; | ||||
import { useRouter } from 'next/navigation'; | ||||
|
||||
interface TimeTableLectureTableProps { | ||||
selectedValues: GetLectureListParams; | ||||
|
@@ -29,74 +38,117 @@ const LECTURE_TABLE_ROW_HEADER = [ | |||
] as const; | ||||
|
||||
function TimeTableLectureItem({ lecture }: TimeTableLectureTableItemProps) { | ||||
const searchParams = useEditableSearchParams(); | ||||
const router = useRouter(); | ||||
const { close } = useModalAction({ key: MODAL_KEY.timeTable }); | ||||
|
||||
const handleTimeTableLectureItem = (id: number) => { | ||||
const selectedId = searchParams.getAll('id'); | ||||
|
||||
if (!selectedId.includes(String(id))) { | ||||
searchParams.append('id', id.toString()); | ||||
router.push(`/timetable?${searchParams.toString()}`); | ||||
} | ||||
|
||||
close(); | ||||
}; | ||||
|
||||
return ( | ||||
<tr className="divide-x divide-gray-300 text-center"> | ||||
<td>{lecture.campus}</td> | ||||
<td>{lecture.category}</td> | ||||
<td>{lecture.code}</td> | ||||
<td>{lecture.credit}</td> | ||||
<td>{lecture.grade ?? '-'}</td> | ||||
<td>{lecture.major !== 'None' ? lecture.major : '-'}</td> | ||||
<td>{lecture.name}</td> | ||||
<td>{lecture.professor}</td> | ||||
<td>{lecture.semester}</td> | ||||
<td>{lecture.time}</td> | ||||
<td>{lecture.groupName}</td> | ||||
<tr | ||||
className="h-12 cursor-pointer divide-x divide-gray-300 text-[12px] transition-colors hover:bg-gray-100" | ||||
onClick={() => handleTimeTableLectureItem(lecture.id)} | ||||
> | ||||
<td className="shrink-0 whitespace-nowrap p-2">{lecture.campus}</td> | ||||
<td className="shrink-0 whitespace-nowrap p-2">{lecture.category}</td> | ||||
<td className="shrink-0 whitespace-nowrap p-2">{lecture.code}</td> | ||||
<td className="shrink-0 whitespace-nowrap p-2">{lecture.credit}</td> | ||||
<td className="shrink-0 whitespace-nowrap p-2">{lecture.grade ?? '-'}</td> | ||||
<td className="shrink-0 whitespace-nowrap p-2"> | ||||
{lecture.major !== 'None' ? lecture.major : '-'} | ||||
</td> | ||||
<td className="shrink-0 whitespace-nowrap p-2">{lecture.name}</td> | ||||
<td className="shrink-0 whitespace-nowrap p-2">{lecture.professor}</td> | ||||
<td className="shrink-0 whitespace-nowrap p-2">{lecture.semester}</td> | ||||
<td className="shrink-0 whitespace-nowrap p-2">{lecture.time}</td> | ||||
<td className="shrink-0 whitespace-nowrap p-2">{lecture.groupName}</td> | ||||
</tr> | ||||
); | ||||
} | ||||
|
||||
function TimeTableLectureContent({ | ||||
selectedValues, | ||||
}: TimeTableLectureTableProps) { | ||||
const { data } = useLectureList({ | ||||
const { data, hasNextPage, fetchNextPage } = useLectureList({ | ||||
campus: selectedValues.campus, | ||||
type: selectedValues.type, | ||||
grade: selectedValues.grade, | ||||
day: selectedValues.day, | ||||
time: selectedValues.time, | ||||
major: selectedValues.major, | ||||
lectureName: selectedValues.lectureName, | ||||
cursor: 0, | ||||
limit: 10, | ||||
limit: 12, | ||||
}); | ||||
const scrollRef = useInfiniteScroll(() => { | ||||
if (hasNextPage) { | ||||
fetchNextPage(); | ||||
} | ||||
}); | ||||
const lectureList = data.data.values; | ||||
|
||||
return ( | ||||
<> | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
{lectureList.length ? ( | ||||
<> | ||||
{...lectureList.map((lecture) => ( | ||||
<TimeTableLectureItem | ||||
key={`lecture-${lecture.id}`} | ||||
lecture={lecture} | ||||
<tbody className="size-full divide-y divide-gray-300"> | ||||
{data && ( | ||||
<> | ||||
{data.length ? ( | ||||
<> | ||||
{...data.map((lecture) => ( | ||||
<TimeTableLectureItem | ||||
key={`lecture-${lecture.id}`} | ||||
lecture={lecture} | ||||
/> | ||||
))} | ||||
</> | ||||
) : ( | ||||
<tr className="h-full"> | ||||
<td | ||||
colSpan={LECTURE_TABLE_ROW_HEADER.length} | ||||
className="h-full text-center" | ||||
> | ||||
검색 결과가 없습니다 | ||||
</td> | ||||
</tr> | ||||
)} | ||||
</> | ||||
)} | ||||
{hasNextPage && ( | ||||
<tr className="block"> | ||||
<td | ||||
ref={(node) => { | ||||
scrollRef.current = node; | ||||
}} | ||||
colSpan={LECTURE_TABLE_ROW_HEADER.length} | ||||
className="h-1" | ||||
/> | ||||
))} | ||||
</> | ||||
) : ( | ||||
<tr> | ||||
<td colSpan={LECTURE_TABLE_ROW_HEADER.length} className="text-center"> | ||||
검색 결과가 없습니다 | ||||
</td> | ||||
</tr> | ||||
)} | ||||
</tr> | ||||
)} | ||||
</tbody> | ||||
</> | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
); | ||||
} | ||||
|
||||
function TimeTableLectureTable({ selectedValues }: TimeTableLectureTableProps) { | ||||
return ( | ||||
<table className="mt-3 w-full table-auto border-collapse border border-gray-400 text-sm"> | ||||
<thead className="w-full border border-gray-400 text-center"> | ||||
<tr className="divide-x divide-gray-400 border border-gray-400 bg-gray-100"> | ||||
{LECTURE_TABLE_ROW_HEADER.map((header) => ( | ||||
<td className="py-2" key={header}> | ||||
{header} | ||||
</td> | ||||
))} | ||||
</tr> | ||||
</thead> | ||||
<tbody className="h-80 w-full divide-y divide-gray-300 overflow-y-scroll"> | ||||
<div className="mt-3 h-96 w-full overflow-y-scroll"> | ||||
<table className="size-full table-auto break-keep border border-gray-400 text-sm"> | ||||
<thead className="sticky top-0 z-20 w-full border border-gray-400 text-center"> | ||||
<tr className="divide-x divide-gray-400 bg-gray-100"> | ||||
{LECTURE_TABLE_ROW_HEADER.map((header) => ( | ||||
<th className="border border-gray-400 py-2" key={header}> | ||||
{header} | ||||
</th> | ||||
))} | ||||
</tr> | ||||
</thead> | ||||
<Suspense | ||||
fallback={ | ||||
<tr> | ||||
|
@@ -111,8 +163,8 @@ function TimeTableLectureTable({ selectedValues }: TimeTableLectureTableProps) { | |||
> | ||||
<TimeTableLectureContent selectedValues={selectedValues} /> | ||||
</Suspense> | ||||
</tbody> | ||||
</table> | ||||
</table> | ||||
</div> | ||||
); | ||||
} | ||||
|
||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -229,7 +229,7 @@ const TimeTableModalMajorInput = memo(function TimeTableModalMajorInput({ | |||||
selectedMajor, | ||||||
handleMajorInputChange, | ||||||
}: TimeTableModalMajorInputProps) { | ||||||
const [inputValue, setInputValue] = useState(''); | ||||||
const [inputValue, setInputValue] = useState<string>(''); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
const [open, setOpen] = useState<boolean>(false); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
const debouncedValue = useDebounce({ | ||||||
value: inputValue, | ||||||
|
@@ -247,7 +247,10 @@ const TimeTableModalMajorInput = memo(function TimeTableModalMajorInput({ | |||||
{...selectedMajor.map((major) => ( | ||||||
<TimeTableModalDropdownButton | ||||||
key={major} | ||||||
onClick={() => handleMajorInputChange(major)} | ||||||
onClick={() => { | ||||||
handleMajorInputChange(major); | ||||||
setInputValue(''); | ||||||
}} | ||||||
value={major} | ||||||
/> | ||||||
))} | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.