mirror of
https://github.com/immich-app/immich.git
synced 2025-05-30 19:54:52 -04:00
fix(web): empty album stored (#9771)
fix(web): delete album when created empty
This commit is contained in:
parent
1323c7ee88
commit
e7dc1f7968
@ -1,7 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import { groupBy, orderBy } from 'lodash-es';
|
import { groupBy, orderBy } from 'lodash-es';
|
||||||
import { addUsersToAlbum, deleteAlbum, type AlbumUserAddDto, type AlbumResponseDto } from '@immich/sdk';
|
import { addUsersToAlbum, deleteAlbum, type AlbumUserAddDto, type AlbumResponseDto, isHttpError } from '@immich/sdk';
|
||||||
import { mdiDeleteOutline, mdiShareVariantOutline, mdiFolderDownloadOutline, mdiRenameOutline } from '@mdi/js';
|
import { mdiDeleteOutline, mdiShareVariantOutline, mdiFolderDownloadOutline, mdiRenameOutline } from '@mdi/js';
|
||||||
import Icon from '$lib/components/elements/icon.svelte';
|
import Icon from '$lib/components/elements/icon.svelte';
|
||||||
import EditAlbumForm from '$lib/components/forms/edit-album-form.svelte';
|
import EditAlbumForm from '$lib/components/forms/edit-album-form.svelte';
|
||||||
@ -267,9 +267,19 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleDeleteAlbum = async (albumToDelete: AlbumResponseDto) => {
|
const handleDeleteAlbum = async (albumToDelete: AlbumResponseDto) => {
|
||||||
|
try {
|
||||||
await deleteAlbum({
|
await deleteAlbum({
|
||||||
id: albumToDelete.id,
|
id: albumToDelete.id,
|
||||||
});
|
});
|
||||||
|
} catch (error) {
|
||||||
|
// In rare cases deleting an album completes after the list of albums has been requested,
|
||||||
|
// leading to a bad request error.
|
||||||
|
// Since the album is already deleted, the error is ignored.
|
||||||
|
const isBadRequest = isHttpError(error) && error.status === 400;
|
||||||
|
if (!isBadRequest) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ownedAlbums = ownedAlbums.filter(({ id }) => id !== albumToDelete.id);
|
ownedAlbums = ownedAlbums.filter(({ id }) => id !== albumToDelete.id);
|
||||||
sharedAlbums = sharedAlbums.filter(({ id }) => id !== albumToDelete.id);
|
sharedAlbums = sharedAlbums.filter(({ id }) => id !== albumToDelete.id);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { afterNavigate, goto } from '$app/navigation';
|
import { afterNavigate, goto, onNavigate } from '$app/navigation';
|
||||||
import AlbumDescription from '$lib/components/album-page/album-description.svelte';
|
import AlbumDescription from '$lib/components/album-page/album-description.svelte';
|
||||||
import AlbumOptions from '$lib/components/album-page/album-options.svelte';
|
import AlbumOptions from '$lib/components/album-page/album-options.svelte';
|
||||||
import AlbumSummary from '$lib/components/album-page/album-summary.svelte';
|
import AlbumSummary from '$lib/components/album-page/album-summary.svelte';
|
||||||
@ -405,6 +405,12 @@
|
|||||||
handleError(error, 'Unable to update album cover');
|
handleError(error, 'Unable to update album cover');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
onNavigate(async () => {
|
||||||
|
if (album.assetCount === 0 && !album.albumName) {
|
||||||
|
await deleteAlbum(album);
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="flex overflow-hidden" bind:clientWidth={globalWidth}>
|
<div class="flex overflow-hidden" bind:clientWidth={globalWidth}>
|
||||||
@ -559,7 +565,7 @@
|
|||||||
{#if viewMode !== ViewMode.SELECT_THUMBNAIL}
|
{#if viewMode !== ViewMode.SELECT_THUMBNAIL}
|
||||||
<!-- ALBUM TITLE -->
|
<!-- ALBUM TITLE -->
|
||||||
<section class="pt-24">
|
<section class="pt-24">
|
||||||
<AlbumTitle id={album.id} albumName={album.albumName} {isOwned} />
|
<AlbumTitle id={album.id} bind:albumName={album.albumName} {isOwned} />
|
||||||
|
|
||||||
{#if album.assetCount > 0}
|
{#if album.assetCount > 0}
|
||||||
<AlbumSummary {album} />
|
<AlbumSummary {album} />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user