78 lines
2.3 KiB
TypeScript
78 lines
2.3 KiB
TypeScript
import { useEffect, useState } from "react";
|
|
import Box from "@mui/material/Box";
|
|
import Container from "@mui/material/Container";
|
|
import TextField from "@mui/material/TextField";
|
|
import Button from "@mui/material/Button";
|
|
import { Catalog } from "@/components/Catalog";
|
|
import { usePlatform } from "@/lib/platform";
|
|
import "./products.css";
|
|
|
|
export default function ProductsPage() {
|
|
const { organization } = usePlatform();
|
|
const [draft, setDraft] = useState("");
|
|
const [search, setSearch] = useState("");
|
|
const [offset, setOffset] = useState(0);
|
|
useEffect(() => {
|
|
setOffset(0);
|
|
setSearch("");
|
|
setDraft("");
|
|
}, [organization]);
|
|
return (
|
|
<Box>
|
|
<section className="products-hero">
|
|
<Container maxWidth="md">
|
|
<h1>Our Collection</h1>
|
|
<p>
|
|
Explore our published candles and find the right variant for your
|
|
everyday rituals.
|
|
</p>
|
|
<div className="section-divider" />
|
|
</Container>
|
|
</section>
|
|
<section className="products-body">
|
|
<Container maxWidth="xl">
|
|
{organization && (
|
|
<form
|
|
className="catalog-search"
|
|
onSubmit={(e) => {
|
|
e.preventDefault();
|
|
setSearch(draft.trim());
|
|
setOffset(0);
|
|
}}
|
|
>
|
|
<TextField
|
|
label="Search candles"
|
|
type="search"
|
|
size="small"
|
|
value={draft}
|
|
inputProps={{ maxLength: 100 }}
|
|
onChange={(e) => setDraft(e.target.value)}
|
|
/>
|
|
<Button type="submit" variant="contained">
|
|
Search
|
|
</Button>
|
|
{search && (
|
|
<Button
|
|
onClick={() => {
|
|
setDraft("");
|
|
setSearch("");
|
|
setOffset(0);
|
|
}}
|
|
>
|
|
Clear
|
|
</Button>
|
|
)}
|
|
</form>
|
|
)}
|
|
<Catalog
|
|
search={search}
|
|
offset={offset}
|
|
onPrevious={() => setOffset((n) => Math.max(0, n - 12))}
|
|
onNext={() => setOffset((n) => n + 12)}
|
|
/>
|
|
</Container>
|
|
</section>
|
|
</Box>
|
|
);
|
|
}
|