diff --git a/app/src/app/(tabs)/browse.tsx b/app/src/app/(tabs)/browse.tsx new file mode 100644 index 0000000..5e8ae34 --- /dev/null +++ b/app/src/app/(tabs)/browse.tsx @@ -0,0 +1,161 @@ +import type { JSX } from "react"; +import { useMemo, useState } from "react"; +import { Pressable, ScrollView, View } from "react-native"; +import { Ionicons } from "@expo/vector-icons"; +import { Chip, SearchField, Switch, Typography, useThemeColor } from "heroui-native"; +import type { Currency, Product } from "@/data/mock"; +import { PRODUCTS } from "@/data/mock"; +import { ListingCard } from "@/components/ListingCard"; + +type CurrencyFilter = "all" | Currency; +type SortMode = "newest" | "priceLow" | "priceHigh"; +type ViewMode = "list" | "grid"; + +export default function BrowseTab(): JSX.Element { + const [search, setSearch] = useState(""); + const [currencyFilter, setCurrencyFilter] = useState("all"); + const [sortMode, setSortMode] = useState("newest"); + const [inStockOnly, setInStockOnly] = useState(true); + const [viewMode, setViewMode] = useState("list"); + const mutedColor = useThemeColor("muted"); + const accentForeground = useThemeColor("accent-foreground"); + + const products = useMemo(() => { + let result = [...PRODUCTS]; + if (inStockOnly) result = result.filter((product) => product.qty > 0); + if (currencyFilter !== "all") result = result.filter((product) => product.cur === currencyFilter); + if (search.trim()) { + const query = search.trim().toLowerCase(); + result = result.filter( + (product) => + product.name.toLowerCase().includes(query) || product.desc.toLowerCase().includes(query), + ); + } + if (sortMode === "priceLow") result.sort((a, b) => a.priceNum - b.priceNum); + else if (sortMode === "priceHigh") result.sort((a, b) => b.priceNum - a.priceNum); + return result; + }, [search, currencyFilter, sortMode, inStockOnly]); + + return ( + + + + + + + + + + + + + Currency + + setCurrencyFilter("all")} + > + All + + setCurrencyFilter("SOL")} + > + SOL + + setCurrencyFilter("USDC")} + > + USDC + + + + Sort + + setSortMode("newest")} + > + Newest + + setSortMode("priceLow")} + > + Price ↑ + + setSortMode("priceHigh")} + > + Price ↓ + + + + + + + + In stock only + + + + setViewMode("list")} + className={`h-7 w-8 items-center justify-center rounded-md ${ + viewMode === "list" ? "bg-accent" : "" + }`} + > + + + setViewMode("grid")} + className={`h-7 w-8 items-center justify-center rounded-md ${ + viewMode === "grid" ? "bg-accent" : "" + }`} + > + + + + + + + + {viewMode === "list" ? ( + + {products.map((product) => ( + + ))} + + ) : ( + + {products.map((product) => ( + + ))} + + )} + + + ); +} diff --git a/app/src/app/(tabs)/explore.tsx b/app/src/app/(tabs)/explore.tsx deleted file mode 100644 index f8b7f1b..0000000 --- a/app/src/app/(tabs)/explore.tsx +++ /dev/null @@ -1,6 +0,0 @@ -import type { JSX } from "react"; -import { View } from "react-native"; - -export default function ExploreTab(): JSX.Element { - return ; -}