import React, { useState } from 'react'
import MasonryGallery from '../gallery/MasonryGallery'
const SORT_OPTIONS = [
{ value: 'latest', label: 'Latest' },
{ value: 'trending', label: 'Trending' },
{ value: 'rising', label: 'Rising' },
{ value: 'views', label: 'Most Viewed' },
{ value: 'favs', label: 'Most Favourited' },
]
function slugify(str) {
return (str || '').toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '')
}
function FeaturedStrip({ featuredArtworks }) {
if (!featuredArtworks?.length) return null
return (
)
}
export default function ProfileGalleryPanel({ artworks, featuredArtworks, username }) {
const [sort, setSort] = useState('latest')
const [items, setItems] = useState(artworks?.data ?? artworks ?? [])
const [nextCursor, setNextCursor] = useState(artworks?.next_cursor ?? null)
const handleSort = async (newSort) => {
setSort(newSort)
setItems([])
try {
const response = await fetch(`/api/profile/${encodeURIComponent(username)}/artworks?sort=${newSort}`, {
headers: { Accept: 'application/json' },
})
if (!response.ok) {
return
}
const data = await response.json()
setItems(data.data ?? data)
setNextCursor(data.next_cursor ?? null)
} catch (_) {}
}
return (
<>
Sort
{SORT_OPTIONS.map((opt) => (
))}
>
)
}