2022-07-15 23:18:17 -05:00
|
|
|
<script context="module" lang="ts">
|
|
|
|
|
export const prerender = false;
|
|
|
|
|
|
|
|
|
|
import PlusBoxOutline from 'svelte-material-icons/PlusBoxOutline.svelte';
|
|
|
|
|
|
2022-07-16 23:52:00 -05:00
|
|
|
import NavigationBar from '$lib/components/shared-components/navigation-bar.svelte';
|
2022-07-15 23:18:17 -05:00
|
|
|
import { ImmichUser } from '$lib/models/immich-user';
|
|
|
|
|
import type { Load } from '@sveltejs/kit';
|
2022-07-16 23:52:00 -05:00
|
|
|
import SideBar from '$lib/components/shared-components/side-bar/side-bar.svelte';
|
2022-07-15 23:18:17 -05:00
|
|
|
import { AlbumResponseDto, api } from '@api';
|
|
|
|
|
|
|
|
|
|
export const load: Load = async ({ session }) => {
|
|
|
|
|
if (!session.user) {
|
|
|
|
|
return {
|
|
|
|
|
status: 302,
|
|
|
|
|
redirect: '/auth/login'
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-22 09:44:22 -05:00
|
|
|
let albums: AlbumResponseDto[] = [];
|
2022-07-15 23:18:17 -05:00
|
|
|
try {
|
|
|
|
|
const { data } = await api.albumApi.getAllAlbums();
|
2022-07-22 09:44:22 -05:00
|
|
|
albums = data;
|
2022-07-15 23:18:17 -05:00
|
|
|
} catch (e) {
|
|
|
|
|
console.log('Error [getAllAlbums] ', e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
status: 200,
|
|
|
|
|
props: {
|
|
|
|
|
user: session.user,
|
2022-07-22 09:44:22 -05:00
|
|
|
albums: albums
|
2022-07-15 23:18:17 -05:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<script lang="ts">
|
2022-07-16 23:52:00 -05:00
|
|
|
import AlbumCard from '$lib/components/album-page/album-card.svelte';
|
2022-07-15 23:18:17 -05:00
|
|
|
import { goto } from '$app/navigation';
|
2022-07-22 09:44:22 -05:00
|
|
|
import { onMount } from 'svelte';
|
2022-07-15 23:18:17 -05:00
|
|
|
|
|
|
|
|
export let user: ImmichUser;
|
2022-07-22 09:44:22 -05:00
|
|
|
export let albums: AlbumResponseDto[];
|
2022-07-15 23:18:17 -05:00
|
|
|
|
2022-07-22 09:44:22 -05:00
|
|
|
onMount(async () => {
|
|
|
|
|
const { data } = await api.albumApi.getAllAlbums();
|
|
|
|
|
albums = data;
|
|
|
|
|
|
|
|
|
|
// Delete album that has no photos and is named 'Untitled'
|
|
|
|
|
for (const album of albums) {
|
|
|
|
|
if (album.albumName === 'Untitled' && album.assets.length === 0) {
|
|
|
|
|
const isDeleted = await deleteAlbum(album);
|
|
|
|
|
|
|
|
|
|
if (isDeleted) {
|
|
|
|
|
albums = albums.filter((a) => a.id !== album.id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const createAlbum = async () => {
|
|
|
|
|
try {
|
|
|
|
|
const { data: newAlbum } = await api.albumApi.createAlbum({
|
|
|
|
|
albumName: 'Untitled'
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
goto('/albums/' + newAlbum.id);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.log('Error [createAlbum] ', e);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const deleteAlbum = async (album: AlbumResponseDto) => {
|
|
|
|
|
try {
|
|
|
|
|
await api.albumApi.deleteAlbum(album.id);
|
|
|
|
|
return true;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.log('Error [deleteAlbum] ', e);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2022-07-15 23:18:17 -05:00
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<svelte:head>
|
|
|
|
|
<title>Albums - Immich</title>
|
|
|
|
|
</svelte:head>
|
|
|
|
|
|
|
|
|
|
<section>
|
|
|
|
|
<NavigationBar {user} on:uploadClicked={() => {}} />
|
|
|
|
|
</section>
|
|
|
|
|
|
2022-07-23 13:08:49 -05:00
|
|
|
<section class="grid grid-cols-[250px_auto] relative pt-[72px] h-screen bg-immich-bg ">
|
2022-07-15 23:18:17 -05:00
|
|
|
<SideBar />
|
|
|
|
|
|
|
|
|
|
<!-- Main Section -->
|
|
|
|
|
|
2022-07-23 13:08:49 -05:00
|
|
|
<section class="overflow-y-auto relative immich-scrollbar">
|
2022-07-15 23:18:17 -05:00
|
|
|
<section id="album-content" class="relative pt-8 pl-4 mb-12 bg-immich-bg">
|
|
|
|
|
<div class="px-4 flex justify-between place-items-center">
|
|
|
|
|
<div>
|
2022-07-16 23:52:00 -05:00
|
|
|
<p class="font-medium">Albums</p>
|
2022-07-15 23:18:17 -05:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div>
|
2022-07-22 09:44:22 -05:00
|
|
|
<button on:click={createAlbum} class="immich-text-button text-sm">
|
2022-07-15 23:18:17 -05:00
|
|
|
<span>
|
|
|
|
|
<PlusBoxOutline size="18" />
|
|
|
|
|
</span>
|
|
|
|
|
<p>Create album</p>
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="my-4">
|
|
|
|
|
<hr />
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!-- Album Card -->
|
|
|
|
|
<div class="flex flex-wrap gap-8">
|
2022-07-22 09:44:22 -05:00
|
|
|
{#each albums as album}
|
|
|
|
|
<a sveltekit:prefetch href={`albums/${album.id}`}>
|
|
|
|
|
<AlbumCard {album} />
|
|
|
|
|
</a>
|
2022-07-15 23:18:17 -05:00
|
|
|
{/each}
|
|
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
</section>
|
|
|
|
|
</section>
|