summaryrefslogtreecommitdiff
path: root/static/src/albums.js
blob: e10dd543291a267cd291c87ab31f3d2d42c6bfe0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import apiConnector from "./connector.js"

export default async function initAlbums(albumsPageContainer) {
	// TODO empty cells animation

	const albumsContainer = albumsPageContainer.querySelector("#albums-container")
	const albumTemplate = albumsPageContainer.querySelector("#album-template")
	async function createAlbum(res) {
		console.log(res.albumName, res.id, res.startDate, res.endDate, res.assetCount, res.shared)
		const albumClone = albumTemplate.content.cloneNode(true)
		albumClone.querySelector(".album-thumb").src = apiConnector.albumThumbSrc(res.albumThumbnailAssetId)
		albumClone.querySelector(".album-name").textContent = res.albumName
		albumClone.querySelector(".album-assets-count").textContent = res.assetCount.toLocaleString()
		if (!res.shared)
			albumClone.querySelector(".album-shared").remove()

		albumsContainer.appendChild(albumClone)
	}

	const albumsResponse = await apiConnector.fetchAlbums()

	for (const res of albumsResponse)
		createAlbum(res)

	return true
}