-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: extract residents card to a component
- Loading branch information
Showing
4 changed files
with
105 additions
and
91 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { | ||
Card, | ||
CardContent, | ||
CardDescription, | ||
CardHeader, | ||
CardTitle, | ||
} from "@/components/ui/card"; | ||
import type { Resident } from "@/lib/types"; | ||
import { | ||
IconGenderFemale, | ||
IconGenderHermaphrodite, | ||
IconGenderMale, | ||
IconQuestionMark, | ||
IconRobot, | ||
} from "@tabler/icons-react"; | ||
import type { ReactNode } from "react"; | ||
|
||
type Props = { | ||
resident: Resident; | ||
}; | ||
|
||
function getGenderInfo(gender: string | undefined) { | ||
if (!gender) | ||
return { | ||
name: "unknown", | ||
icon: <IconQuestionMark />, | ||
}; | ||
|
||
if (["male", "female", "hermaphrodite"].includes(gender)) { | ||
let icon: ReactNode; | ||
|
||
if (gender === "male") { | ||
icon = <IconGenderMale />; | ||
} else if (gender === "female") { | ||
icon = <IconGenderFemale />; | ||
} else { | ||
icon = <IconGenderHermaphrodite />; | ||
} | ||
|
||
return { | ||
name: gender, | ||
icon, | ||
}; | ||
} | ||
|
||
return { | ||
name: "droid", | ||
icon: <IconRobot />, | ||
}; | ||
} | ||
|
||
export function ResidentCard(props: Props) { | ||
const { resident } = props; | ||
|
||
const genderInfo = getGenderInfo(resident.gender); | ||
|
||
return ( | ||
<Card key={resident.id}> | ||
<CardHeader className="flex flex-row items-center gap-x-4"> | ||
<div>{genderInfo.icon}</div> | ||
<div className="break-all"> | ||
<CardTitle>{resident.name}</CardTitle> | ||
<CardDescription className="capitalize"> | ||
{genderInfo.name} | ||
</CardDescription> | ||
</div> | ||
</CardHeader> | ||
<CardContent> | ||
<div className="flex items-center gap-x-2"> | ||
<p className="font-bold">Eye color:</p> | ||
<p>{resident.eyeColor ?? "-"}</p> | ||
</div> | ||
<div className="flex items-center gap-x-2"> | ||
<p className="font-bold">Hair color:</p> | ||
<p>{resident.hairColor ?? "-"}</p> | ||
</div> | ||
<div className="flex items-center gap-x-2"> | ||
<p className="font-bold">Skin color:</p> | ||
<p>{resident.skinColor ?? "-"}</p> | ||
</div> | ||
<div className="flex items-center gap-x-2"> | ||
<p className="font-bold">Height:</p> | ||
<p>{resident.height ?? "-"}</p> | ||
</div> | ||
<div className="flex items-center gap-x-2"> | ||
<p className="font-bold">Mass:</p> | ||
<p>{resident.mass ?? "-"}</p> | ||
</div> | ||
<div className="flex items-center gap-x-2"> | ||
<p className="font-bold">Birth year</p> | ||
<p>{resident.birthYear ?? "-"}</p> | ||
</div> | ||
</CardContent> | ||
</Card> | ||
); | ||
} |
This file contains 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