diff --git a/frontend/src/gallery/components/AlbumEditModal.jsx b/frontend/src/gallery/components/AlbumEditModal.jsx
index c3c8ecf..8ed0218 100644
--- a/frontend/src/gallery/components/AlbumEditModal.jsx
+++ b/frontend/src/gallery/components/AlbumEditModal.jsx
@@ -8,6 +8,7 @@ export default function AlbumEditModal({ open, onOpenChange, trigger, id, startT
const { getAccessToken } = useAccount()
const [title, setTitle] = useState(startTitle || '')
const [description, setDescription] = useState(startDescription || '')
+ const [thumbnail, setThumbnail] = useState(null)
const { showError } = useNotifier()
const handleEditAlbum = async () => {
const response = await fetch(`${getServerUrl()}/api/albums/editAlbum`, {
@@ -21,6 +22,7 @@ export default function AlbumEditModal({ open, onOpenChange, trigger, id, startT
properties: {
title: title,
description: description,
+ thumbnail: thumbnail,
}
})
})
@@ -37,6 +39,10 @@ export default function AlbumEditModal({ open, onOpenChange, trigger, id, startT
setDescription(startDescription || '')
}
}, [open])
+ const handleFileSelect = (file) => {
+ console.log(file)
+ setThumbnail(file.selectedAlbum.ID + '/' + file.selectedFile.ID)
+ }
return (
@@ -45,7 +51,7 @@ export default function AlbumEditModal({ open, onOpenChange, trigger, id, startT
Description
diff --git a/frontend/src/gallery/components/FilePicker.jsx b/frontend/src/gallery/components/FilePicker.jsx
index 159fcdd..1f966c6 100644
--- a/frontend/src/gallery/components/FilePicker.jsx
+++ b/frontend/src/gallery/components/FilePicker.jsx
@@ -5,12 +5,13 @@ import { useAccount } from '../../contexts/useAccount'
import { getServerUrl } from '../../hooks/getConstants'
import { useNotifier } from '../../contexts/useNotifier'
import { ArrowLeft } from 'lucide-react'
-export default function FilePicker({ currentAlbum }) {
+import AuthImage from '../../components/AuthImage'
+export default function FilePicker({ currentAlbum, onFileSelect }) {
const [selectedFile, setSelectedFile] = useState(null)
const [selectedAlbum, setSelectedAlbum] = useState(currentAlbum)
const [currentPath, setCurrentPath] = useState([])
const [albums, setAlbums] = useState([])
- const [media, setMedia] = useState([])
+ const [media, setMedia] = useState(null)
const [filePickerOpen, setFilePickerOpen] = useState(false)
const { getAccessToken } = useAccount()
const { showError } = useNotifier()
@@ -49,6 +50,24 @@ export default function FilePicker({ currentAlbum }) {
setSelectedAlbum(data)
}
}
+ const getMedia = async () => {
+ const response = await fetch(`${getServerUrl()}/api/media/getAllMediaInAlbum?albumId=${selectedAlbum?.ID}`, {
+ method: 'GET',
+ headers: {
+ 'Authorization': getAccessToken(),
+ },
+ })
+ const data = await response.json()
+ if (data.error) {
+ showError(data.error)
+ } else {
+ if (data.media.length === 0) {
+ setMedia(null)
+ } else {
+ setMedia(data.media)
+ }
+ }
+ }
const reconstructPath = async () => {
if (!selectedAlbum?.ID) {
setCurrentPath(['gallery'])
@@ -99,13 +118,22 @@ export default function FilePicker({ currentAlbum }) {
}
getAlbum()
reconstructPath()
+ getMedia()
}, [selectedAlbum])
return (
-
{
- setFilePickerOpen(true)
- }}>
-
-
{selectedFile?.name || 'No image selected'}
+ <>
+
{
+ setFilePickerOpen(true)
+ }}>
+
+ {selectedFile?.Title ? (
+
+ {currentPath.join(' / ') + ' / ' + selectedFile?.Title}
+
+ ) : (
+
No image selected
+ )}
+
@@ -123,14 +151,23 @@ export default function FilePicker({ currentAlbum }) {
))}
- {media.length === 0 && (
+ {media === null && (
No media found
)}
- {media.length > 0 && (
+ {media && media.length === 0 && (
+
Loading...
+ )}
+ {media && media.length > 0 && (
{media.map((m) => (
-
-
+
{
+ setSelectedFile(m)
+ if (onFileSelect) {
+ onFileSelect({ selectedFile: m, selectedAlbum: selectedAlbum, currentPath: currentPath })
+ }
+ setFilePickerOpen(false)
+ }}>
+
{m.Title}
))}
@@ -138,6 +175,6 @@ export default function FilePicker({ currentAlbum }) {
)}
-
+ >
)
}
\ No newline at end of file