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 (
{album.Title}