diff --git a/backend/internal/models/album.go b/backend/internal/models/album.go index ee2b844..1449f92 100644 --- a/backend/internal/models/album.go +++ b/backend/internal/models/album.go @@ -15,6 +15,7 @@ type Album struct { // Public albums have a default access level of 0 for all visitors, including guests. // Private albums require a user with access to be logged in to view, or a magic link to be used. ParentID string `gorm:"not null"` // The ID of the parent album, if any. This is an empty string for root albums. + Thumbnail string `gorm:"not null"` // The media ID of the thumbnail for the album. CreatedAt time.Time UpdatedAt time.Time } diff --git a/backend/internal/routes/album.go b/backend/internal/routes/album.go index b0cac09..4374b29 100644 --- a/backend/internal/routes/album.go +++ b/backend/internal/routes/album.go @@ -9,7 +9,7 @@ import ( func RegisterAlbumRoutes(rg *gin.RouterGroup) { album := rg.Group("/albums") - album.GET("/getAlbumsInParent", func(c *gin.Context) { + album.POST("/getAlbumsInParent", func(c *gin.Context) { accessToken := c.GetHeader("Authorization") if accessToken == "" { c.JSON(http.StatusUnauthorized, gin.H{"error": "Unauthorized"}) diff --git a/backend/internal/services/album.go b/backend/internal/services/album.go index 8d9e54a..2cbf016 100644 --- a/backend/internal/services/album.go +++ b/backend/internal/services/album.go @@ -73,6 +73,7 @@ func CreateAlbum(accessToken string, title string, description string, parentID Title: title, Description: description, ParentID: parentID, + Thumbnail: "", } result := db.GetDB().Create(&album) if result.Error != nil { diff --git a/frontend/src/gallery/components/AlbumList.jsx b/frontend/src/gallery/components/AlbumList.jsx index 7bce885..fd29a35 100644 --- a/frontend/src/gallery/components/AlbumList.jsx +++ b/frontend/src/gallery/components/AlbumList.jsx @@ -1,14 +1,49 @@ import { PlusIcon } from 'lucide-react' import AlbumCreateModal from './AlbumCreateModal' -import { useState } from 'react' -export default function AlbumList() { +import { useState, useEffect } from 'react' +import { getServerUrl } from '../../hooks/getConstants' +import { useAccount } from '../../contexts/useAccount' +export default function AlbumList({ currentAlbumName }) { + const { getAccessToken } = useAccount() const [open, setOpen] = useState(false) + const [albums, setAlbums] = useState([]) + 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() + console.log('Albums', data) + setAlbums(data) + } else { + setAlbums([]) + } + } + useEffect(() => { + if (!open) { + getAlbums() + } + }, [currentAlbumName, open]) return (
{album.Title}
+