diff --git a/inertia/components/explore_card.tsx b/inertia/components/explore_card.tsx new file mode 100644 index 0000000..0030357 --- /dev/null +++ b/inertia/components/explore_card.tsx @@ -0,0 +1,49 @@ +import { Camera } from 'lucide-react' +import type { InferVariants } from '@adonisjs/http-transformers/types' +import type KitTransformer from '#kits/transformers/kit_transformer' + +type KitExplore = InferVariants['forExplore'] + +interface ExploreCardProps { + kit: KitExplore + onSelect: (kit: KitExplore) => void +} + +export function ExploreCard({ kit, onSelect }: ExploreCardProps) { + return ( +
+ + +

+ +

+

@{(kit.handle ?? '').split('.')[0]}

+
+ ) +} diff --git a/inertia/components/explore_masonry_grid.tsx b/inertia/components/explore_masonry_grid.tsx new file mode 100644 index 0000000..38ab886 --- /dev/null +++ b/inertia/components/explore_masonry_grid.tsx @@ -0,0 +1,49 @@ +import { useState, useEffect } from 'react' +import { ExploreCard } from '~/components/explore_card' +import type { InferVariants } from '@adonisjs/http-transformers/types' +import type KitTransformer from '#kits/transformers/kit_transformer' + +type KitExplore = InferVariants['forExplore'] + +interface ExploreMasonryGridProps { + kits: KitExplore[] + onSelect: (kit: KitExplore) => void +} + +function useColumnCount(): number { + const [count, setCount] = useState(1) + + useEffect(() => { + function update() { + if (window.innerWidth >= 1024) setCount(3) + else if (window.innerWidth >= 640) setCount(2) + else setCount(1) + } + update() + window.addEventListener('resize', update) + return () => window.removeEventListener('resize', update) + }, []) + + return count +} + +export function ExploreMasonryGrid({ kits, onSelect }: ExploreMasonryGridProps) { + const numCols = useColumnCount() + + const columns: KitExplore[][] = Array.from({ length: numCols }, () => []) + kits.forEach((kit, i) => { + columns[i % numCols].push(kit) + }) + + return ( +
+ {columns.map((col, colIdx) => ( +
+ {col.map((kit) => ( + + ))} +
+ ))} +
+ ) +} diff --git a/inertia/pages/explore/index.tsx b/inertia/pages/explore/index.tsx index 4b53378..9c0c639 100644 --- a/inertia/pages/explore/index.tsx +++ b/inertia/pages/explore/index.tsx @@ -1,4 +1,4 @@ -import { useState, useEffect, useRef, type CSSProperties } from 'react' +import { useState, useEffect, useRef } from 'react' import BaseLayout from '~/layouts/base' import { usePage, InfiniteScroll, router } from '@inertiajs/react' import { Link } from '@adonisjs/inertia/react' @@ -18,6 +18,7 @@ import type { Scroll } from '@adonisjs/inertia/types' import type { InferVariants } from '@adonisjs/http-transformers/types' import type KitTransformer from '#kits/transformers/kit_transformer' import { KitDetailPanel } from '~/components/kit_detail_panel' +import { ExploreMasonryGrid } from '~/components/explore_masonry_grid' type KitExplore = InferVariants['forExplore'] @@ -26,22 +27,6 @@ type PageProps = InertiaProps<{ q: string }> -const ASPECT = [ - 'aspect-[3/4]', - 'aspect-square', - 'aspect-[4/5]', - 'aspect-[3/4]', - 'aspect-video', - 'aspect-square', -] - -function bgStyle(src: string): CSSProperties { - if (src.startsWith('http') || src.startsWith('/')) { - return { backgroundImage: `url(${src})`, backgroundSize: 'cover', backgroundPosition: 'center' } - } - return { background: src } -} - export default function Explore() { const { kits, q: initialQ, user } = usePage().props @@ -164,51 +149,7 @@ export default function Explore() { )} > -
- {kits.data.map((kit, i) => ( -
- - -

- -

- -

- @{(kit.handle ?? '').split('.')[0]} -

- -
    - {[kit.grade, kit.scale].filter(Boolean).map((tag) => ( -
  • - - {tag} - -
  • - ))} -
-
- ))} -
+ )}