Please select which services you would like to opt out of.
diff --git a/frontend/src/components/listing/ListingImageFlipper.tsx b/frontend/src/components/listing/ListingImageFlipper.tsx
index 2d5180f0..890c82b8 100644
--- a/frontend/src/components/listing/ListingImageFlipper.tsx
+++ b/frontend/src/components/listing/ListingImageFlipper.tsx
@@ -1,4 +1,4 @@
-import { useState } from "react";
+import { useMemo, useState } from "react";
import { FaChevronLeft, FaChevronRight, FaTimes } from "react-icons/fa";
import placeholder from "@/components/listing/pics/placeholder.jpg";
@@ -15,7 +15,27 @@ const ListingImageFlipper = (props: Props) => {
const { artifacts, name, currentImageIndex, setCurrentImageIndex } = props;
const [isFullScreen, setIsFullScreen] = useState(false);
- if (artifacts.length === 0) {
+ const imageArtifacts = useMemo(
+ () =>
+ artifacts
+ .map((artifact, index) => ({ artifact, originalIndex: index }))
+ .filter(({ artifact }) => artifact.artifact_type === "image")
+ .map(({ artifact, originalIndex }, newIndex) => ({
+ artifact,
+ originalIndex,
+ newIndex,
+ })),
+ [artifacts],
+ );
+
+ const currentImageArrayIndex = useMemo(() => {
+ const found = imageArtifacts.findIndex(
+ ({ originalIndex }) => originalIndex === currentImageIndex,
+ );
+ return found >= 0 ? found : 0;
+ }, [imageArtifacts, currentImageIndex]);
+
+ if (imageArtifacts.length === 0) {
return (
@@ -29,7 +49,18 @@ const ListingImageFlipper = (props: Props) => {
);
}
- const currentArtifact = artifacts[currentImageIndex];
+ const handleNavigate = (direction: "next" | "prev") => {
+ const nextIndex =
+ direction === "next"
+ ? (currentImageArrayIndex + 1) % imageArtifacts.length
+ : currentImageArrayIndex === 0
+ ? imageArtifacts.length - 1
+ : currentImageArrayIndex - 1;
+
+ setCurrentImageIndex(imageArtifacts[nextIndex].originalIndex);
+ };
+
+ const currentArtifact = imageArtifacts[currentImageArrayIndex].artifact;
return (
<>
@@ -41,24 +72,16 @@ const ListingImageFlipper = (props: Props) => {
className="cursor-zoom-in rounded-lg w-[500px]"
/>
{/* Navigation arrows */}
- {artifacts.length > 1 && (
+ {imageArtifacts.length > 1 && (
<>
@@ -66,72 +83,55 @@ const Navbar = () => {
{navItems.map((item) =>
item.isExternal ? (
-
-
- {item.name}
-
-
-
+ {item.name}
+
) : (
-
-
- {item.name}
-
-
+ {item.name}
+
),
)}
{isAuthenticated ? (
<>
-
- Account
-
-
+
- Logout
-
+ Logout
+
>
) : (
<>
-
- Log In
-
-
+
- Sign Up
-
+ Sign Up
+
>
)}
diff --git a/frontend/src/components/nav/Sidebar.tsx b/frontend/src/components/nav/Sidebar.tsx
index 739b9262..80ef79e4 100644
--- a/frontend/src/components/nav/Sidebar.tsx
+++ b/frontend/src/components/nav/Sidebar.tsx
@@ -28,7 +28,7 @@ const SidebarItem = ({
{icon && {icon}}
diff --git a/frontend/src/lib/utils/listingUtils.ts b/frontend/src/lib/utils/listingUtils.ts
new file mode 100644
index 00000000..7913a0e3
--- /dev/null
+++ b/frontend/src/lib/utils/listingUtils.ts
@@ -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 = {};
+
+ 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;
+};