refactor album access logic to handle guest users and improve state initialization in gallery components

This commit is contained in:
wisplite
2025-11-22 23:56:47 -06:00
parent d9bad97a53
commit eb2691af75
4 changed files with 42 additions and 47 deletions
+32 -38
View File
@@ -11,48 +11,42 @@ export default function AlbumList({ currentAlbumName }) {
const [albums, setAlbums] = useState([])
const navigate = useNavigate()
const { showError } = useNotifier()
const getAlbums = async () => {
console.log('Getting albums in parent', currentAlbumName)
if (currentAlbumName === 'gallery') { // Root album
const response = await fetch(`${getServerUrl()}/api/albums/getAlbumsInParent`, {
method: 'POST',
headers: {
'Authorization': getAccessToken(),
},
body: JSON.stringify({
parentId: "",
}),
})
const data = await response.json()
if (data.error) {
setAlbums([])
showError('Failed to get albums')
} else {
setAlbums(data)
}
} else {
const response = await fetch(`${getServerUrl()}/api/albums/getAlbumsInParent`, {
method: 'POST',
headers: {
'Authorization': getAccessToken(),
},
body: JSON.stringify({
parentId: currentAlbumName,
}),
})
const data = await response.json()
if (data.error) {
setAlbums([])
showError('Failed to get albums')
} else {
setAlbums(data)
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')
}
}
}
}
useEffect(() => {
if (!open) {
if (!open && currentAlbumName !== null) {
getAlbums()
}
return () => { ignore = true; }
}, [currentAlbumName, open])
return (
<div className="flex flex-col items-center justify-start h-full w-full bg-[#141414]">