Skip to content

Commit

Permalink
Refactor chip function to return React Element
Browse files Browse the repository at this point in the history
  • Loading branch information
Taewan-P committed May 3, 2024
1 parent 57bd720 commit 5e988ac
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/app/components/shuttle/Shuttle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import tw from 'twin.macro'

import { openNaverMapApp } from '@/components/shuttle/map'
import {
ChipType,
Season,
Settings,
ShuttleStop,
Expand Down Expand Up @@ -327,16 +328,16 @@ const titleText = (location: string): string => {
}
}

const getColoredElement = (type: string): JSX.Element => {
if (type == 'C') {
return <Chip className="bg-chip-red">{busTypeToText(type)}</Chip>
} else if (type == 'DHJ') {
return <Chip className="bg-chip-purple">{busTypeToText(type)}</Chip>
} else if (type == 'DY') {
return <Chip className="bg-chip-green">{busTypeToText(type)}</Chip>
const ColoredChip = ({ chipType }: ChipType) => {
if (chipType == 'C') {
return <Chip className="bg-chip-red">{busTypeToText(chipType)}</Chip>
} else if (chipType == 'DHJ') {
return <Chip className="bg-chip-purple">{busTypeToText(chipType)}</Chip>
} else if (chipType == 'DY') {
return <Chip className="bg-chip-green">{busTypeToText(chipType)}</Chip>
}

return <Chip className="bg-chip-blue">{busTypeToText(type)}</Chip>
return <Chip className="bg-chip-blue">{busTypeToText(chipType)}</Chip>
}

export const Shuttle = ({ location }: ShuttleStop) => {
Expand Down Expand Up @@ -483,7 +484,7 @@ export const Shuttle = ({ location }: ShuttleStop) => {
return (
<React.Fragment key={idx}>
<SingleTimetable>
{getColoredElement(val.type)}
<ColoredChip chipType={val.type} />
<TimeLeftWrapper
className={`${showActualTime ? 'touched' : ''}`}
>
Expand Down
1 change: 1 addition & 0 deletions src/app/data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export type { StopLocation } from './common/stopLocation'
export type { Changelog } from './modal/changelog'
export type { NoticeInfo } from './notice/noticeInfo'
export type { NoticeType } from './notice/noticeType'
export type { ChipType } from './shuttle/chipType'
export type { OrganizedTimetables } from './shuttle/organizedTimetables'
export type { Period } from './shuttle/period'
export type { Season } from './shuttle/season'
Expand Down
3 changes: 3 additions & 0 deletions src/app/data/shuttle/chipType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type ChipType = {
chipType: string
}

0 comments on commit 5e988ac

Please sign in to comment.