import { PlusIcon, EllipsisVertical } from 'lucide-react' import AlbumCreateModal from './AlbumCreateModal' import { useState, useEffect } from 'react' import { getServerUrl } from '../../hooks/getConstants' import { useAccount } from '../../contexts/useAccount' import { useNavigate } from 'react-router-dom' import { useNotifier } from '../../contexts/useNotifier' import AlbumEditModal from './AlbumEditModal' export default function AlbumList({ currentAlbumName }) { const { getAccessToken } = useAccount() const [open, setOpen] = useState(false) const [openEdit, setOpenEdit] = useState(false) const [editingAlbum, setEditingAlbum] = useState(null) const [albums, setAlbums] = useState([]) const navigate = useNavigate() const { showError } = useNotifier() useEffect(() => { let ignore = false; const getAlbums = async () => { console.log('Getting albums in parent', currentAlbumName) const parentId = currentAlbumName === 'gallery' ? "" : currentAlbumName; try { const response = await fetch(`${getServerUrl()}/api/albums/getAlbumsInParent`, { method: 'POST', headers: { 'Authorization': getAccessToken(), }, body: JSON.stringify({ parentId: parentId, }), }) const data = await response.json() if (!ignore) { if (data.error) { setAlbums([]) showError('Failed to get albums') } else { setAlbums(data) } } } catch (error) { if (!ignore) { setAlbums([]) showError('Failed to get albums') } } } if (!open && !openEdit && currentAlbumName !== null) { getAlbums() } return () => { ignore = true; } }, [currentAlbumName, open, openEdit]) return (

Albums

setOpen(true)} />
{albums.map((album) => (
{ // Get current path and append the album's title const currentPath = window.location.pathname; // Remove leading and trailing slashes, split to parts const pathParts = currentPath.replace(/^\/|\/$/g, '').split('/'); // Only append if not already the last part (avoid duplicate navigation) if (pathParts[pathParts.length - 1] !== album.Title) { navigate(`${currentPath.replace(/\/$/, '')}/${encodeURIComponent(album.Title)}`); } else { navigate(currentPath); // Or optionally do nothing/navigate to self } }} >

{album.Title}

{ e.stopPropagation() setEditingAlbum(album) setOpenEdit(true) }} />
))}
{editingAlbum && ( )}
) }