-
Notifications
You must be signed in to change notification settings - Fork 3
[시설물 정보] 백엔드 API 응답값 추가에 따른 코드 변경 #1240
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
Merged
+51
−213
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,180 +1 @@ | ||
| import { cn } from '@bcsdlab/utils'; | ||
| import { useSuspenseQuery } from '@tanstack/react-query'; | ||
| import { coopshopQueries } from 'api/coopshop/queries'; | ||
| import Book from 'components/CampusInfo/svg/book.svg'; | ||
| import Cafe from 'components/CampusInfo/svg/cafe.svg'; | ||
| import Cut from 'components/CampusInfo/svg/cut.svg'; | ||
| import Flatware from 'components/CampusInfo/svg/flatware.svg'; | ||
| import Glasses from 'components/CampusInfo/svg/glasses.svg'; | ||
| import Laundry from 'components/CampusInfo/svg/laundry.svg'; | ||
| import PostOffice from 'components/CampusInfo/svg/post-office.svg'; | ||
| import Print from 'components/CampusInfo/svg/print.svg'; | ||
| import styles from './CampusInfo.module.scss'; | ||
|
|
||
| const CAFETERIA_HEAD_TABLE = { | ||
| row: ['평일', '주말'], | ||
| col: ['아침', '점심', '저녁'], | ||
| }; | ||
|
|
||
| const SHOP_ICON = { | ||
| 서점: <Book />, | ||
| 대즐: <Cafe />, | ||
| 미용실: <Cut />, | ||
| 세탁소: <Laundry />, | ||
| 우체국: <PostOffice />, | ||
| '복지관 참빛관 편의점': <Cafe />, | ||
| 복사실: <Print />, | ||
| 학생식당: <Flatware />, | ||
| 복지관식당: <Flatware />, | ||
| 오락실: <Cafe />, | ||
| 안경원: <Glasses />, | ||
| 우편취급국: <PostOffice />, | ||
| }; | ||
|
|
||
| const formatDateRange = (fromDate: string, toDate: string) => { | ||
| const from = new Date(fromDate); | ||
| const to = new Date(toDate); | ||
|
|
||
| const options: Intl.DateTimeFormatOptions = { | ||
| year: 'numeric', | ||
| month: 'long', | ||
| day: 'numeric', | ||
| }; | ||
|
|
||
| const fromFormatted = from.toLocaleDateString('ko-KR', options); | ||
| let toFormatted = to.toLocaleDateString('ko-KR', options); | ||
|
|
||
| if (from.getFullYear() === to.getFullYear()) { | ||
| const toOptions: Intl.DateTimeFormatOptions = { | ||
| month: 'long', | ||
| day: 'numeric', | ||
| }; | ||
|
|
||
| toFormatted = to.toLocaleDateString('ko-KR', toOptions); | ||
| } | ||
|
|
||
| return `기간 : ${fromFormatted} - ${toFormatted}`; | ||
| }; | ||
|
|
||
| function CampusInfo() { | ||
| const { data: campusInfo } = useSuspenseQuery(coopshopQueries.allShopInfo()); | ||
|
|
||
| const cafeteriaInfo = campusInfo?.coop_shops.find((shop) => shop.name === '학생식당'); | ||
| const filteredCampusInfo = campusInfo?.coop_shops.filter((shop) => shop.name !== '학생식당'); | ||
|
|
||
| const getFormattedShopTime = (open: string, close: string) => { | ||
| if (open === close) { | ||
| return open; | ||
| } | ||
|
|
||
| return `${open} - ${close}`; | ||
| }; | ||
|
|
||
| const getTimeToTypeAndDay = (type: string, day: string) => { | ||
| const target = cafeteriaInfo?.opens?.find((open) => open.day_of_week === day && open.type === type); | ||
|
|
||
| return target ? getFormattedShopTime(target.open_time, target.close_time) : '미운영'; | ||
| }; | ||
|
|
||
| return ( | ||
| <div className={styles.container}> | ||
| <div className={styles['title-container']}> | ||
| <h2 className={styles.title}>{`${campusInfo.semester} 시설물 운영 시간`}</h2> | ||
| <div className={styles.subtitle}>{formatDateRange(campusInfo.from_date, campusInfo.to_date)}</div> | ||
| </div> | ||
| <section className={styles['info-container']}> | ||
| <div className={styles['info-column']}> | ||
| <div className={styles['info-block']}> | ||
| <div className={styles['info-cafeteria']}> | ||
| <div className={styles['info-title-container']}> | ||
| <div className={styles['icon-wrapper']}> | ||
| <Flatware /> | ||
| </div> | ||
| <div className={styles['info-title']}>학생식당</div> | ||
| </div> | ||
| <table className={styles.table}> | ||
| <thead> | ||
| <tr className={styles['table-head__tr']}> | ||
| <th>시간</th> | ||
| {CAFETERIA_HEAD_TABLE.row.map((type) => ( | ||
| <th className={styles['table-head__th']} key={type}> | ||
| {type} | ||
| </th> | ||
| ))} | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| {CAFETERIA_HEAD_TABLE.col.map((type) => ( | ||
| <tr className={styles['table-body__tr']} key={type}> | ||
| <td className={styles['table-body__td']}>{type}</td> | ||
| {CAFETERIA_HEAD_TABLE.row.map((day) => ( | ||
| <td | ||
| className={cn({ | ||
| [styles['table-body__td']]: true, | ||
| [styles.closed]: getTimeToTypeAndDay(type, day) === '미운영', | ||
| })} | ||
| key={`${type}-${day}`} | ||
| > | ||
| {getTimeToTypeAndDay(type, day)} | ||
| </td> | ||
| ))} | ||
| </tr> | ||
| ))} | ||
| </tbody> | ||
| </table> | ||
| </div> | ||
| </div> | ||
|
|
||
| {filteredCampusInfo.slice(0, 2).map(({ id, name, opens }) => ( | ||
| <div className={styles['info-block']} key={id}> | ||
| <div className={styles['icon-wrapper']}>{SHOP_ICON[name as keyof typeof SHOP_ICON]}</div> | ||
| <div className={styles['info-description-container']}> | ||
| <div className={styles['info-title']}>{name}</div> | ||
| {opens.map(({ day_of_week, open_time, close_time }) => ( | ||
| <div | ||
| className={styles['info-description']} | ||
| key={`${id}-${day_of_week}`} | ||
| >{`${day_of_week}: ${getFormattedShopTime(open_time, close_time)}`}</div> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| ))} | ||
| </div> | ||
| <div className={styles['info-column']}> | ||
| {filteredCampusInfo.slice(2, 6).map(({ id, name, opens }) => ( | ||
| <div className={styles['info-block']} key={id}> | ||
| <div className={styles['icon-wrapper']}>{SHOP_ICON[name as keyof typeof SHOP_ICON]}</div> | ||
| <div className={styles['info-description-container']}> | ||
| <div className={styles['info-title']}>{name}</div> | ||
| {opens.map(({ day_of_week, open_time, close_time }) => ( | ||
| <div | ||
| className={styles['info-description']} | ||
| key={`${id}-${day_of_week}`} | ||
| >{`${day_of_week}: ${getFormattedShopTime(open_time, close_time)}`}</div> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| ))} | ||
| </div> | ||
| <div className={styles['info-column']}> | ||
| {filteredCampusInfo.slice(6).map(({ id, name, opens }) => ( | ||
| <div className={styles['info-block']} key={id}> | ||
| <div className={styles['icon-wrapper']}>{SHOP_ICON[name as keyof typeof SHOP_ICON]}</div> | ||
| <div className={styles['info-description-container']}> | ||
| <div className={styles['info-title']}>{name}</div> | ||
| {opens.map(({ day_of_week, open_time, close_time }) => ( | ||
| <div | ||
| className={styles['info-description']} | ||
| key={`${id}-${day_of_week}`} | ||
| >{`${day_of_week}: ${getFormattedShopTime(open_time, close_time)}`}</div> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| ))} | ||
| </div> | ||
| </section> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| export default CampusInfo; | ||
| export { default } from 'components/CampusInfo'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
이미지 로드 실패 시 폴백이 동작하지 않습니다.
Line 44-48은
iconUrl존재 여부만 확인해서 렌더링하기 때문에, URL이 깨졌을 때icon-fallback으로 전환되지 않고 깨진 이미지가 노출됩니다.수정 예시
📝 Committable suggestion
🤖 Prompt for AI Agents