-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added code modularization for components
- Loading branch information
Showing
6 changed files
with
116 additions
and
131 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
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,50 @@ | ||
import { Link } from "react-router-dom"; | ||
|
||
import { Button } from "@/components/ui/button"; | ||
|
||
interface NavButtonProps { | ||
to: string; | ||
currentPath: string; | ||
children: React.ReactNode; | ||
isExternal?: boolean; | ||
} | ||
|
||
export const NavButton = ({ | ||
to, | ||
currentPath, | ||
children, | ||
isExternal = false, | ||
}: NavButtonProps) => { | ||
const isActive = currentPath.startsWith(to); | ||
|
||
if (isExternal) { | ||
return ( | ||
<Button | ||
asChild | ||
variant="outline" | ||
className="px-2 xl:px-3 py-2 text-sm tracking-wide xl:tracking-widest text-gray-1" | ||
> | ||
<a | ||
href={to} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
className="flex items-center gap-2" | ||
> | ||
{children} | ||
</a> | ||
</Button> | ||
); | ||
} | ||
|
||
return ( | ||
<Button | ||
asChild | ||
variant={isActive ? "ghost" : "outline"} | ||
className={`px-3 py-2 text-gray-1 ${ | ||
isActive ? "underline underline-offset-4 decoration-2" : "" | ||
}`} | ||
> | ||
<Link to={to}>{children}</Link> | ||
</Button> | ||
); | ||
}; |
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,25 @@ | ||
import { paths } from "@/gen/api"; | ||
|
||
type ListingDetails = | ||
paths["/listings/batch"]["get"]["responses"][200]["content"]["application/json"]["listings"][number]; | ||
|
||
export const createListingDetailsMap = (listings: ListingDetails[]) => { | ||
const detailsMap: Record<string, ListingDetails> = {}; | ||
|
||
listings.forEach((listing) => { | ||
const firstImageArtifact = listing.artifacts?.find( | ||
(artifact) => artifact.artifact_type === "image", | ||
); | ||
|
||
if (firstImageArtifact) { | ||
listing.artifacts = [ | ||
firstImageArtifact, | ||
...listing.artifacts.filter((a) => a !== firstImageArtifact), | ||
]; | ||
} | ||
|
||
detailsMap[listing.id] = listing; | ||
}); | ||
|
||
return detailsMap; | ||
}; |