diff --git a/web/src/lib/components/album-page/album-list.svelte b/web/src/lib/components/album-page/album-list.svelte new file mode 100644 index 000000000..32eebd4cf --- /dev/null +++ b/web/src/lib/components/album-page/album-list.svelte @@ -0,0 +1,452 @@ + + + + +{#if shouldShowEditUserForm} + (shouldShowEditUserForm = false)}> + successModifyAlbum()} + on:cancel={() => (shouldShowEditUserForm = false)} + /> + +{/if} + + +
+ +
+ + +
+
+ {#if sharedAlbum} + goto(AppRoute.SHARED_LINKS)}> +
+ + +
+
+ {/if} + { + return { + title: option.title, + icon: option.sortDesc ? mdiArrowDownThin : mdiArrowUpThin, + }; + }} + on:select={(event) => { + for (const key in sortByOptions) { + if (sortByOptions[key].title === event.detail.title) { + sortByOptions[key].sortDesc = !sortByOptions[key].sortDesc; + $albumViewSettings.sortBy = sortByOptions[key].title; + } + } + }} + /> + + handleChangeListMode()}> +
+ {#if $albumViewSettings.view === AlbumViewMode.List} + + + {:else} + + + {/if} +
+
+
+ {#if partners && partners.length > 0} +
+
+

Partners

+
+ +
+ {#each partners as partner (partner.id)} + + +
+

+ {partner.name} +

+

+ {partner.email} +

+
+
+ {/each} +
+
+ +
+ {/if} + {#if $albums.length !== 0} + + {#if sharedAlbum} +
+

Albums

+
+ {/if} + {#if $albumViewSettings.view === AlbumViewMode.Cover} +
+ {#each $albums as album (album.id)} + + showAlbumContextMenu(e.detail, album)} {user} /> + + {/each} +
+ {:else if $albumViewSettings.view === AlbumViewMode.List} + + + + {#each Object.keys(sortByOptions) as key (key)} + + {/each} + + + + + {#each $albums as album (album.id)} + goto(`albums/${album.id}`)} + on:keydown={(event) => event.key === 'Enter' && goto(`albums/${album.id}`)} + tabindex="0" + > + + + + + + + + + {/each} + +
{album.albumName} + {album.assetCount} + {album.assetCount > 1 ? `items` : `item`} +
+ {/if} + + + {:else if sharedAlbum} + + {:else} + + {/if} +
+ + +{#if $isShowContextMenu} + + setAlbumToDelete()}> + + +

Delete album

+
+
+
+{/if} + +{#if albumToDelete} + (albumToDelete = null)} + > + +

Are you sure you want to delete the album {albumToDelete.albumName}?

+

If this album is shared, other users will not be able to access it anymore.

+
+
+{/if} diff --git a/web/src/lib/components/album-page/albums.bloc.ts b/web/src/lib/components/album-page/albums.bloc.ts new file mode 100644 index 000000000..35a630f42 --- /dev/null +++ b/web/src/lib/components/album-page/albums.bloc.ts @@ -0,0 +1,88 @@ +import type { OnShowContextMenuDetail } from '$lib/components/album-page/album-card'; +import { notificationController, NotificationType } from '$lib/components/shared-components/notification/notification'; +import { AlbumResponseDto, api } from '@api'; +import { derived, get, writable } from 'svelte/store'; + +type AlbumsProps = { albums: AlbumResponseDto[] }; + +export const useAlbums = (props: AlbumsProps) => { + const albums = writable([...props.albums]); + const contextMenuPosition = writable({ x: 0, y: 0 }); + const contextMenuTargetAlbum = writable(); + const isShowContextMenu = derived(contextMenuTargetAlbum, ($selectedAlbum) => !!$selectedAlbum); + + async function loadAlbums(): Promise { + try { + const { data } = await api.albumApi.getAllAlbums(); + albums.set(data); + + // Delete album that has no photos and is named '' + for (const album of data) { + if (album.albumName === '' && album.assetCount === 0) { + setTimeout(async () => { + await deleteAlbum(album); + }, 500); + } + } + } catch { + notificationController.show({ + message: 'Error loading albums', + type: NotificationType.Error, + }); + } + } + + async function createAlbum(): Promise { + try { + const { data: newAlbum } = await api.albumApi.createAlbum({ + createAlbumDto: { + albumName: '', + }, + }); + + return newAlbum; + } catch { + notificationController.show({ + message: 'Error creating album', + type: NotificationType.Error, + }); + } + } + + async function deleteAlbum(albumToDelete: AlbumResponseDto): Promise { + await api.albumApi.deleteAlbum({ id: albumToDelete.id }); + albums.set( + get(albums).filter(({ id }) => { + return id !== albumToDelete.id; + }), + ); + } + + async function showAlbumContextMenu( + contextMenuDetail: OnShowContextMenuDetail, + album: AlbumResponseDto, + ): Promise { + contextMenuTargetAlbum.set(album); + + contextMenuPosition.set({ + x: contextMenuDetail.x, + y: contextMenuDetail.y, + }); + } + + function closeAlbumContextMenu() { + contextMenuTargetAlbum.set(undefined); + } + + return { + albums, + isShowContextMenu, + contextMenuPosition, + contextMenuTargetAlbum, + loadAlbums, + createAlbum, + deleteAlbum, + showAlbumContextMenu, + closeAlbumContextMenu, + }; +}; diff --git a/web/src/lib/components/elements/dropdown.svelte b/web/src/lib/components/elements/dropdown.svelte index 6bf9b55d6..9b6d3e4ff 100644 --- a/web/src/lib/components/elements/dropdown.svelte +++ b/web/src/lib/components/elements/dropdown.svelte @@ -68,7 +68,7 @@ {#if renderedSelectedOption?.icon} {/if} - + diff --git a/web/src/routes/(user)/albums/+page.svelte b/web/src/routes/(user)/albums/+page.svelte index 4f5f0b18d..2efcf890b 100644 --- a/web/src/routes/(user)/albums/+page.svelte +++ b/web/src/routes/(user)/albums/+page.svelte @@ -8,397 +8,13 @@ -{#if shouldShowEditUserForm} - (shouldShowEditUserForm = false)}> - successModifyAlbum()} - on:cancel={() => (shouldShowEditUserForm = false)} - /> - -{/if} - - -
- -
- - Create album -
-
- - { - return { - title: option.title, - icon: option.sortDesc ? mdiArrowDownThin : mdiArrowUpThin, - }; - }} - on:select={(event) => { - for (const key in sortByOptions) { - if (sortByOptions[key].title === event.detail.title) { - sortByOptions[key].sortDesc = !sortByOptions[key].sortDesc; - $albumViewSettings.sortBy = sortByOptions[key].title; - } - } - }} - /> - - handleChangeListMode()}> -
- {#if $albumViewSettings.view === AlbumViewMode.List} - - - {:else} - - - {/if} -
-
-
- {#if $albums.length !== 0} - - {#if $albumViewSettings.view === AlbumViewMode.Cover} -
- {#each $albums as album (album.id)} - - showAlbumContextMenu(e.detail, album)} - user={data.user} - /> - - {/each} -
- {:else if $albumViewSettings.view === AlbumViewMode.List} - - - - {#each Object.keys(sortByOptions) as key (key)} - - {/each} - - - - - {#each $albums as album (album.id)} - goto(`albums/${album.id}`)} - on:keydown={(event) => event.key === 'Enter' && goto(`albums/${album.id}`)} - tabindex="0" - > - - - - - - - - - {/each} - -
{album.albumName} - {album.assetCount} - {album.assetCount > 1 ? `items` : `item`} -
- {/if} - - - {:else} - - {/if} -
- - -{#if $isShowContextMenu} - - setAlbumToDelete()}> - - -

Delete album

-
-
-
-{/if} - -{#if albumToDelete} - (albumToDelete = null)} - > - -

Are you sure you want to delete the album {albumToDelete.albumName}?

-

If this album is shared, other users will not be able to access it anymore.

-
-
-{/if} + diff --git a/web/src/routes/(user)/sharing/+page.svelte b/web/src/routes/(user)/sharing/+page.svelte index 982e4c3c5..84e39afb7 100644 --- a/web/src/routes/(user)/sharing/+page.svelte +++ b/web/src/routes/(user)/sharing/+page.svelte @@ -1,115 +1,14 @@ - -
- -
- - Create shared album -
-
- - goto(AppRoute.SHARED_LINKS)}> -
- - Shared links -
-
-
- -
- {#if data.partners.length > 0} -
-
-

Partners

-
- -
- {#each data.partners as partner (partner.id)} - - -
-

- {partner.name} -

-

- {partner.email} -

-
-
- {/each} -
-
- -
- {/if} - -
-
-

Albums

-
- -
- -
- {#each data.sharedAlbums as album (album.id)} - - - - {/each} -
- - - {#if data.sharedAlbums.length === 0} - - {/if} -
-
-
-
+