Skip to content

High performance self-hosted photo and video management solution.

feat(web): use ui lib's context menu for albums page (#31725)

Mees Frensel1aedf1b41ca9
diff --git a/web/src/lib/components/album-page/AlbumCard.svelte b/web/src/lib/components/album-page/AlbumCard.svelte
index f3bc4190aa..58aefab952 100644
--- a/web/src/lib/components/album-page/AlbumCard.svelte
+++ b/web/src/lib/components/album-page/AlbumCard.svelte
@@ -1,57 +1,46 @@
<script lang="ts">
import AlbumCover from '$lib/components/album-page/AlbumCover.svelte';
import { authManager } from '$lib/managers/auth-manager.svelte';
- import { getContextMenuPositionFromEvent, type ContextMenuPosition } from '$lib/utils/context-menu';
import { getShortDateRange } from '$lib/utils/date-time';
import { type AlbumResponseDto } from '@immich/sdk';
- import { IconButton } from '@immich/ui';
- import { mdiDotsVertical } from '@mdi/js';
+ import { ContextMenuButton, type MenuItems } from '@immich/ui';
import { t } from 'svelte-i18n';
- interface Props {
+ type Props = {
album: AlbumResponseDto;
showOwner?: boolean;
showDateRange?: boolean;
showItemCount?: boolean;
preload?: boolean;
- onShowContextMenu?: ((position: ContextMenuPosition) => unknown) | undefined;
- }
+ contextMenuItems?: MenuItems;
+ };
- let {
+ const {
album,
showOwner = false,
showDateRange = false,
showItemCount = false,
preload = false,
- onShowContextMenu,
+ contextMenuItems,
}: Props = $props();
-
- const showAlbumContextMenu = (e: MouseEvent) => {
- e.stopPropagation();
- e.preventDefault();
- onShowContextMenu?.(getContextMenuPositionFromEvent(e));
- };
</script>
<div
class="group relative rounded-2xl border border-transparent p-5 hover:border-gray-200 hover:bg-gray-100 dark:hover:border-gray-800 dark:hover:bg-gray-900"
data-testid="album-card"
>
- {#if onShowContextMenu}
+ {#if contextMenuItems}
<div
id="icon-{album.id}"
class="absolute inset-e-6 top-6 opacity-0 group-hover:opacity-100 focus-within:opacity-100"
data-testid="context-button-parent"
>
- <IconButton
- color="secondary"
- aria-label={$t('show_album_options')}
- icon={mdiDotsVertical}
- shape="round"
+ <ContextMenuButton
+ translations={{ open_menu: $t('show_album_options') }}
+ position="top-left"
variant="filled"
- size="medium"
class="icon-white-drop-shadow"
- onclick={showAlbumContextMenu}
+ items={contextMenuItems}
/>
</div>
{/if}
diff --git a/web/src/lib/components/album-page/AlbumCardGroup.svelte b/web/src/lib/components/album-page/AlbumCardGroup.svelte
index 0a3635ec3a..94710ecd32 100644
--- a/web/src/lib/components/album-page/AlbumCardGroup.svelte
+++ b/web/src/lib/components/album-page/AlbumCardGroup.svelte
@@ -1,48 +1,51 @@
<script lang="ts">
import AlbumCard from '$lib/components/album-page/AlbumCard.svelte';
+ import Portal from '$lib/elements/Portal.svelte';
import { Route } from '$lib/route';
+ import { getAlbumActions } from '$lib/services/album.service';
import { albumViewSettings } from '$lib/stores/preferences.store';
import { type AlbumGroup, isAlbumGroupCollapsed, toggleAlbumGroupCollapsing } from '$lib/utils/album-utils';
- import type { ContextMenuPosition } from '$lib/utils/context-menu';
import type { AlbumResponseDto } from '@immich/sdk';
- import { Icon } from '@immich/ui';
+ import { Icon, menuManager, type ActionItem } from '@immich/ui';
import { mdiChevronRight } from '@mdi/js';
import { t } from 'svelte-i18n';
import { flip } from 'svelte/animate';
import { slide } from 'svelte/transition';
- interface Props {
+ type Props = {
albums: AlbumResponseDto[];
group?: AlbumGroup | undefined;
showOwner?: boolean;
showDateRange?: boolean;
showItemCount?: boolean;
- onShowContextMenu?: ((position: ContextMenuPosition, album: AlbumResponseDto) => unknown) | undefined;
- }
+ };
- let {
+ const {
albums,
group = undefined,
showOwner = false,
showDateRange = false,
showItemCount = false,
- onShowContextMenu = undefined,
}: Props = $props();
let isCollapsed = $derived(!!group && isAlbumGroupCollapsed($albumViewSettings, group.id));
-
- const showContextMenu = (position: ContextMenuPosition, album: AlbumResponseDto) => {
- onShowContextMenu?.(position, album);
- };
-
let iconRotation = $derived(isCollapsed ? 'rotate-0' : 'rotate-90');
+ let contextMenuAnchor: HTMLDivElement | undefined = $state();
- const oncontextmenu = (event: MouseEvent, album: AlbumResponseDto) => {
+ const oncontextmenu = async (event: MouseEvent, items: ActionItem[]) => {
event.preventDefault();
- showContextMenu({ x: event.x, y: event.y }, album);
+ contextMenuAnchor?.setAttribute('style', `left: ${event.x}px; top: ${event.y}px;`);
+ await menuManager.show({
+ target: contextMenuAnchor ?? (event.currentTarget as HTMLElement),
+ items,
+ });
};
</script>
+<Portal>
+ <div bind:this={contextMenuAnchor} class="absolute"></div>
+</Portal>
+
{#if group}
<div class="grid">
<button
@@ -63,11 +66,13 @@
{#if !isCollapsed}
<div class="grid grid-auto-fill-56 gap-y-4" transition:slide={{ duration: 300 }}>
{#each albums as album, index (album.id)}
+ {@const { Edit, Share, Download, Delete } = getAlbumActions($t, album)}
+ {@const items = [Edit, Share, Download, Delete]}
<a
href={Route.viewAlbum(album)}
class="h-fit"
animate:flip={{ duration: 400 }}
- oncontextmenu={(event) => oncontextmenu(event, album)}
+ oncontextmenu={(event) => oncontextmenu(event, items)}
>
<AlbumCard
{album}
@@ -75,7 +80,7 @@
{showDateRange}
{showItemCount}
preload={index < 20}
- onShowContextMenu={onShowContextMenu ? (position) => showContextMenu(position, album) : undefined}
+ contextMenuItems={items}
/>
</a>
{/each}
diff --git a/web/src/lib/components/album-page/AlbumsList.svelte b/web/src/lib/components/album-page/AlbumsList.svelte
index 69ba212c19..a4c6af76ba 100644
--- a/web/src/lib/components/album-page/AlbumsList.svelte
+++ b/web/src/lib/components/album-page/AlbumsList.svelte
@@ -2,12 +2,8 @@
import AlbumCardGroup from '$lib/components/album-page/AlbumCardGroup.svelte';
import AlbumsTable from '$lib/components/album-page/AlbumsTable.svelte';
import OnEvents from '$lib/components/OnEvents.svelte';
- import MenuOption from '$lib/components/shared-components/context-menu/MenuOption.svelte';
- import RightClickContextMenu from '$lib/components/shared-components/context-menu/RightClickContextMenu.svelte';
import { authManager } from '$lib/managers/auth-manager.svelte';
- import AlbumEditModal from '$lib/modals/AlbumEditModal.svelte';
- import AlbumOptionsModal from '$lib/modals/AlbumOptionsModal.svelte';
- import { handleDeleteAlbum, handleDownloadAlbum } from '$lib/services/album.service';
+ import { handleDeleteAlbum } from '$lib/services/album.service';
import {
AlbumFilter,
AlbumGroupBy,
@@ -18,11 +14,8 @@
type AlbumViewSettings,
} from '$lib/stores/preferences.store';
import { getSelectedAlbumGroupOption, sortAlbums, stringToSortOrder, type AlbumGroup } from '$lib/utils/album-utils';
- import type { ContextMenuPosition } from '$lib/utils/context-menu';
import { normalizeSearchString } from '$lib/utils/string-utils';
import { AlbumUserRole, type AlbumResponseDto, type SharedLinkResponseDto } from '@immich/sdk';
- import { modalManager } from '@immich/ui';
- import { mdiDeleteOutline, mdiDownload, mdiRenameOutline, mdiShareVariantOutline } from '@mdi/js';
import { groupBy } from 'lodash-es';
import { onMount, type Snippet } from 'svelte';
import { t } from 'svelte-i18n';
@@ -56,7 +49,7 @@
const groupOptions: AlbumGroupOption = {
/** No grouping */
- [AlbumGroupBy.None]: (order, albums): AlbumGroup[] => {
+ [AlbumGroupBy.None]: (_, albums): AlbumGroup[] => {
return [
{
id: $t('albums'),
@@ -161,68 +154,17 @@
}));
});
- let contextMenuPosition: ContextMenuPosition = $state({ x: 0, y: 0 });
- let selectedAlbum: AlbumResponseDto | undefined = $state();
- let isOpen = $state(false);
-
// TODO get rid of this
$effect(() => {
albumGroupIds = groupedAlbums.map(({ id }) => id);
});
- let showFullContextMenu = $derived(
- allowEdit && selectedAlbum && selectedAlbum.albumUsers[0].user.id === authManager.user.id,
- );
-
onMount(async () => {
if (allowEdit) {
await removeAlbumsIfEmpty();
}
});
- const showAlbumContextMenu = (contextMenuDetail: ContextMenuPosition, album: AlbumResponseDto) => {
- selectedAlbum = album;
- contextMenuPosition = {
- x: contextMenuDetail.x,
- y: contextMenuDetail.y,
- };
- isOpen = true;
- };
-
- const closeAlbumContextMenu = () => {
- isOpen = false;
- };
-
- const handleSelect = async (action: 'edit' | 'share' | 'download' | 'delete') => {
- closeAlbumContextMenu();
-
- if (!selectedAlbum) {
- return;
- }
-
- switch (action) {
- case 'edit': {
- await modalManager.show(AlbumEditModal, { album: selectedAlbum });
- break;
- }
-
- case 'share': {
- await modalManager.show(AlbumOptionsModal, { album: selectedAlbum });
- break;
- }
-
- case 'download': {
- await handleDownloadAlbum(selectedAlbum);
- break;
- }
-
- case 'delete': {
- await handleDeleteAlbum(selectedAlbum);
- break;
- }
- }
- };
-
const removeAlbumsIfEmpty = async () => {
const albumsToRemove = ownedAlbums.filter((album) => album.assetCount === 0 && !album.albumName);
await Promise.allSettled(albumsToRemove.map((album) => handleDeleteAlbum(album, { prompt: false, notify: false })));
@@ -260,42 +202,17 @@
{#if userSettings.view === AlbumViewMode.Cover}
<!-- Album Cards -->
{#if albumGroupOption === AlbumGroupBy.None}
- <AlbumCardGroup
- albums={groupedAlbums[0].albums}
- {showOwner}
- showDateRange
- showItemCount
- onShowContextMenu={showAlbumContextMenu}
- />
+ <AlbumCardGroup albums={groupedAlbums[0].albums} {showOwner} showDateRange showItemCount />
{:else}
{#each groupedAlbums as albumGroup (albumGroup.id)}
- <AlbumCardGroup
- albums={albumGroup.albums}
- group={albumGroup}
- {showOwner}
- showDateRange
- showItemCount
- onShowContextMenu={showAlbumContextMenu}
- />
+ <AlbumCardGroup albums={albumGroup.albums} group={albumGroup} {showOwner} showDateRange showItemCount />
{/each}
{/if}
{:else if userSettings.view === AlbumViewMode.List}
<!-- Album Table -->
- <AlbumsTable {groupedAlbums} {albumGroupOption} onShowContextMenu={showAlbumContextMenu} />
+ <AlbumsTable {groupedAlbums} {albumGroupOption} />
{/if}
{:else}
<!-- Empty Message -->
{@render empty?.()}
{/if}
-
-<!-- Context Menu -->
-<RightClickContextMenu title={$t('album_options')} {...contextMenuPosition} {isOpen} onClose={closeAlbumContextMenu}>
- {#if showFullContextMenu}
- <MenuOption icon={mdiRenameOutline} text={$t('edit_album')} onClick={() => handleSelect('edit')} />
- <MenuOption icon={mdiShareVariantOutline} text={$t('share')} onClick={() => handleSelect('share')} />
- {/if}
- <MenuOption icon={mdiDownload} text={$t('download')} onClick={() => handleSelect('download')} />
- {#if showFullContextMenu}
- <MenuOption icon={mdiDeleteOutline} text={$t('delete')} onClick={() => handleSelect('delete')} />
- {/if}
-</RightClickContextMenu>
diff --git a/web/src/lib/components/album-page/AlbumsTable.svelte b/web/src/lib/components/album-page/AlbumsTable.svelte
index e73b4a170f..5cfec8c4b4 100644
--- a/web/src/lib/components/album-page/AlbumsTable.svelte
+++ b/web/src/lib/components/album-page/AlbumsTable.svelte
@@ -8,20 +8,17 @@
toggleAlbumGroupCollapsing,
type AlbumGroup,
} from '$lib/utils/album-utils';
- import type { ContextMenuPosition } from '$lib/utils/context-menu';
- import type { AlbumResponseDto } from '@immich/sdk';
import { Icon } from '@immich/ui';
import { mdiChevronRight } from '@mdi/js';
import { t } from 'svelte-i18n';
import { slide } from 'svelte/transition';
- interface Props {
+ type Props = {
groupedAlbums: AlbumGroup[];
albumGroupOption?: string;
- onShowContextMenu?: ((position: ContextMenuPosition, album: AlbumResponseDto) => unknown) | undefined;
- }
+ };
- let { groupedAlbums, albumGroupOption = AlbumGroupBy.None, onShowContextMenu }: Props = $props();
+ const { groupedAlbums, albumGroupOption = AlbumGroupBy.None }: Props = $props();
</script>
<table class="mt-2 w-full text-start">
@@ -37,7 +34,7 @@
{#if albumGroupOption === AlbumGroupBy.None}
<tbody class="block w-full overflow-y-auto rounded-md border dark:border-immich-dark-gray dark:text-immich-dark-fg">
{#each groupedAlbums[0].albums as album (album.id)}
- <AlbumTableRow {album} {onShowContextMenu} />
+ <AlbumTableRow {album} />
{/each}
</tbody>
{:else}
@@ -71,7 +68,7 @@
transition:slide={{ duration: 300 }}
>
{#each albumGroup.albums as album (album.id)}
- <AlbumTableRow {album} {onShowContextMenu} />
+ <AlbumTableRow {album} />
{/each}
</tbody>
{/if}
diff --git a/web/src/lib/components/album-page/AlbumsTableRow.svelte b/web/src/lib/components/album-page/AlbumsTableRow.svelte
index cb309c01df..3371bb47a4 100644
--- a/web/src/lib/components/album-page/AlbumsTableRow.svelte
+++ b/web/src/lib/components/album-page/AlbumsTableRow.svelte
@@ -1,36 +1,46 @@
<script lang="ts">
import { goto } from '$app/navigation';
import { dateFormats } from '$lib/constants';
+ import Portal from '$lib/elements/Portal.svelte';
import { authManager } from '$lib/managers/auth-manager.svelte';
import { Route } from '$lib/route';
+ import { getAlbumActions } from '$lib/services/album.service';
import { locale } from '$lib/stores/preferences.store';
- import type { ContextMenuPosition } from '$lib/utils/context-menu';
import { AlbumUserRole, type AlbumResponseDto } from '@immich/sdk';
- import { Icon } from '@immich/ui';
+ import { Icon, menuManager } from '@immich/ui';
import { mdiShareVariantOutline } from '@mdi/js';
import { t } from 'svelte-i18n';
- interface Props {
+ type Props = {
album: AlbumResponseDto;
- onShowContextMenu?: ((position: ContextMenuPosition, album: AlbumResponseDto) => unknown) | undefined;
- }
+ };
- let { album, onShowContextMenu = undefined }: Props = $props();
+ const { album }: Props = $props();
- const showContextMenu = (position: ContextMenuPosition) => {
- onShowContextMenu?.(position, album);
- };
+ let contextMenuAnchor: HTMLDivElement | undefined = $state();
+ const items = $derived.by(() => {
+ const { Edit, Share, Download, Delete } = getAlbumActions($t, album);
+ return [Edit, Share, Download, Delete];
+ });
const dateLocaleString = (dateString: string) => {
return new Date(dateString).toLocaleDateString($locale, dateFormats.album);
};
- const oncontextmenu = (event: MouseEvent) => {
+ const oncontextmenu = async (event: MouseEvent) => {
event.preventDefault();
- showContextMenu({ x: event.x, y: event.y });
+ contextMenuAnchor?.setAttribute('style', `left: ${event.x}px; top: ${event.y}px;`);
+ await menuManager.show({
+ target: contextMenuAnchor ?? (event.currentTarget as HTMLElement),
+ items,
+ });
};
</script>
+<Portal>
+ <div bind:this={contextMenuAnchor} class="absolute"></div>
+</Portal>
+
<tr
class="flex w-full place-items-center border-3 border-transparent p-2 text-center odd:bg-subtle/80 even:bg-subtle/20 hover:cursor-pointer hover:border-immich-primary/75 md:px-5 md:py-2 odd:dark:bg-immich-dark-gray/75 even:dark:bg-immich-dark-gray/50 dark:hover:border-immich-dark-primary/75"
onclick={() => goto(Route.viewAlbum(album))}
diff --git a/web/src/lib/components/album-page/__tests__/AlbumCard.spec.ts b/web/src/lib/components/album-page/__tests__/AlbumCard.spec.ts
index 94f64fb929..f14db2d6c0 100644
--- a/web/src/lib/components/album-page/__tests__/AlbumCard.spec.ts
+++ b/web/src/lib/components/album-page/__tests__/AlbumCard.spec.ts
@@ -1,14 +1,10 @@
import '@testing-library/jest-dom';
import { render, waitFor, type RenderResult } from '@testing-library/svelte';
-import userEvent from '@testing-library/user-event';
import { init, register, waitLocale } from 'svelte-i18n';
import { sdkMock } from '$lib/__mocks__/sdk.mock';
-import { renderWithTooltips } from '$tests/helpers';
import { albumFactory } from '@test-data/factories/album-factory';
import AlbumCard from '../AlbumCard.svelte';
-const onShowContextMenu = vi.fn();
-
describe('AlbumCard component', () => {
let sut: RenderResult<typeof AlbumCard>;
@@ -74,49 +70,14 @@ describe('AlbumCard component', () => {
expect(albumImgElement).toHaveAttribute('src');
expect(albumNameElement).toHaveTextContent('some album name');
- expect(albumDetailsElement).toHaveTextContent('0 item');
+ expect(albumDetailsElement).toHaveTextContent(`${album.assetCount} item`);
});
- it('hides context menu when "onShowContextMenu" is undefined', () => {
+ it('hides context menu when "contextMenuItems" is undefined', () => {
const album = Object.freeze(albumFactory.build({ albumThumbnailAssetId: null }));
sut = render(AlbumCard, { album });
const contextButtonParent = sut.queryByTestId('context-button-parent');
expect(contextButtonParent).not.toBeInTheDocument();
});
-
- describe('with rendered component - no thumbnail', () => {
- const album = Object.freeze(albumFactory.build({ albumThumbnailAssetId: null }));
-
- beforeEach(async () => {
- sut = renderWithTooltips(AlbumCard, { album, onShowContextMenu });
-
- const albumImgElement = sut.getByTestId('album-image');
- await waitFor(() => expect(albumImgElement).toHaveAttribute('src'));
- });
-
- it('dispatches "onShowContextMenu" event on context menu click with mouse coordinates', async () => {
- const contextMenuButton = sut.getByTestId('context-button-parent').firstElementChild!;
- expect(contextMenuButton).toBeDefined();
-
- // Mock getBoundingClientRect to return a bounding rectangle that will result in the expected position
- contextMenuButton.getBoundingClientRect = () => ({
- x: 123,
- y: 456,
- width: 0,
- height: 0,
- top: 0,
- right: 0,
- bottom: 0,
- left: 0,
- toJSON: () => ({}),
- });
-
- const user = userEvent.setup();
- await user.click(contextMenuButton);
-
- expect(onShowContextMenu).toHaveBeenCalledTimes(1);
- expect(onShowContextMenu).toHaveBeenCalledWith(expect.objectContaining({ x: 123, y: 456 }));
- });
- });
});
diff --git a/web/src/lib/components/shared-components/context-menu/RightClickContextMenu.svelte b/web/src/lib/components/shared-components/context-menu/RightClickContextMenu.svelte
deleted file mode 100644
index 16b1df1716..0000000000
--- a/web/src/lib/components/shared-components/context-menu/RightClickContextMenu.svelte
+++ /dev/null
@@ -1,113 +0,0 @@
-<script lang="ts">
- import { contextMenuNavigation } from '$lib/actions/context-menu-navigation';
- import { shortcuts } from '$lib/actions/shortcut';
- import ContextMenu from '$lib/components/shared-components/context-menu/ContextMenu.svelte';
- import { optionClickCallbackStore, selectedIdStore } from '$lib/stores/context-menu.store';
- import { generateId } from '$lib/utils/generate-id';
- import { tick, type Snippet } from 'svelte';
-
- interface Props {
- title: string;
- direction?: 'left' | 'right';
- x?: number;
- y?: number;
- isOpen?: boolean;
- onClose: (() => unknown) | undefined;
- children?: Snippet;
- }
-
- let { title, direction = 'right', x = 0, y = 0, isOpen = false, onClose, children }: Props = $props();
-
- let uniqueKey = $state({});
- let menuContainer: HTMLUListElement | undefined = $state();
- let triggerElement: HTMLElement | undefined = $state(undefined);
-
- const id = generateId();
- const menuId = `context-menu-${id}`;
-
- const reopenContextMenu = async (event: MouseEvent) => {
- const contextMenuEvent = new MouseEvent('contextmenu', {
- bubbles: true,
- cancelable: true,
- // eslint-disable-next-line unicorn/prefer-global-this
- view: window,
- clientX: event.x,
- clientY: event.y,
- });
-
- const elements = document.elementsFromPoint(event.x, event.y);
-
- if (menuContainer && elements.includes(menuContainer)) {
- // User end-clicked on the context menu itself, we keep the context
- // menu as is
- return;
- }
-
- closeContextMenu();
- await tick();
- uniqueKey = {};
-
- // Event will bubble through the DOM tree
- const sectionIndex = elements.indexOf(event.target as Element);
- elements.at(sectionIndex + 1)?.dispatchEvent(contextMenuEvent);
- };
-
- const closeContextMenu = () => {
- triggerElement?.focus();
- onClose?.();
- };
- $effect(() => {
- if (!(isOpen && menuContainer)) {
- return;
- }
-
- triggerElement = document.activeElement as HTMLElement;
- menuContainer.focus();
- $optionClickCallbackStore = closeContextMenu;
- });
-
- const oncontextmenu = async (event: MouseEvent) => {
- event.preventDefault();
- await reopenContextMenu(event);
- };
-</script>
-
-{#key uniqueKey}
- {#if isOpen}
- <div
- use:contextMenuNavigation={{
- closeDropdown: closeContextMenu,
- container: menuContainer,
- isOpen,
- selectedId: $selectedIdStore,
- selectionChanged: (id) => ($selectedIdStore = id),
- }}
- use:shortcuts={[
- {
- shortcut: { key: 'Tab' },
- onShortcut: closeContextMenu,
- },
- {
- shortcut: { key: 'Tab', shift: true },
- onShortcut: closeContextMenu,
- },
- ]}
- >
- <section class="fixed inset-s-0 top-0 flex h-dvh w-dvw" {oncontextmenu} role="presentation">
- <ContextMenu
- {direction}
- {x}
- {y}
- ariaActiveDescendant={$selectedIdStore}
- ariaLabel={title}
- bind:menuElement={menuContainer}
- id={menuId}
- isVisible
- onClose={closeContextMenu}
- >
- {@render children?.()}
- </ContextMenu>
- </section>
- </div>
- {/if}
-{/key}
diff --git a/web/src/lib/services/album.service.ts b/web/src/lib/services/album.service.ts
index 2bc8dc3b47..b5570d35b2 100644
--- a/web/src/lib/services/album.service.ts
+++ b/web/src/lib/services/album.service.ts
@@ -16,13 +16,24 @@ import {
type UserResponseDto,
} from '@immich/sdk';
import { modalManager, toastManager, type ActionItem } from '@immich/ui';
-import { mdiImageOutline, mdiLink, mdiPlus, mdiPlusBoxOutline, mdiShareVariantOutline, mdiUpload } from '@mdi/js';
+import {
+ mdiDownload,
+ mdiImageOutline,
+ mdiLink,
+ mdiPlus,
+ mdiPlusBoxOutline,
+ mdiRenameOutline,
+ mdiShareVariantOutline,
+ mdiTrashCanOutline,
+ mdiUpload,
+} from '@mdi/js';
import { type MessageFormatter } from 'svelte-i18n';
import { goto } from '$app/navigation';
import { authManager } from '$lib/managers/auth-manager.svelte';
import { eventManager } from '$lib/managers/event-manager.svelte';
import type { TimelineAsset } from '$lib/managers/timeline-manager/types';
import AlbumAddUsersModal from '$lib/modals/AlbumAddUsersModal.svelte';
+import AlbumEditModal from '$lib/modals/AlbumEditModal.svelte';
import AlbumOptionsModal from '$lib/modals/AlbumOptionsModal.svelte';
import SharedLinkCreateModal from '$lib/modals/SharedLinkCreateModal.svelte';
import { Route } from '$lib/route';
@@ -45,13 +56,6 @@ export const getAlbumsActions = ($t: MessageFormatter) => {
export const getAlbumActions = ($t: MessageFormatter, album: AlbumResponseDto) => {
const isOwned = album.albumUsers[0].user.id === authManager.user.id;
- const Share: ActionItem = {
- title: $t('share'),
- icon: mdiShareVariantOutline,
- $if: () => isOwned,
- onAction: () => modalManager.show(AlbumOptionsModal, { album }),
- };
-
const AddUsers: ActionItem = {
title: $t('invite_people'),
icon: mdiPlus,
@@ -66,7 +70,34 @@ export const getAlbumActions = ($t: MessageFormatter, album: AlbumResponseDto) =
onAction: () => modalManager.show(SharedLinkCreateModal, { albumId: album.id }),
};
- return { Share, AddUsers, CreateSharedLink };
+ const Delete: ActionItem = {
+ title: $t('delete'),
+ icon: mdiTrashCanOutline,
+ $if: () => isOwned,
+ onAction: () => handleDeleteAlbum(album),
+ };
+
+ const Download: ActionItem = {
+ title: $t('download'),
+ icon: mdiDownload,
+ onAction: () => handleDownloadAlbum(album),
+ };
+
+ const Edit: ActionItem = {
+ title: $t('edit_album'),
+ icon: mdiRenameOutline,
+ $if: () => isOwned,
+ onAction: () => modalManager.show(AlbumEditModal, { album }),
+ };
+
+ const Share: ActionItem = {
+ title: $t('share'),
+ icon: mdiShareVariantOutline,
+ $if: () => isOwned,
+ onAction: () => modalManager.show(AlbumOptionsModal, { album }),
+ };
+
+ return { AddUsers, CreateSharedLink, Delete, Download, Edit, Share };
};
export const getAlbumAssetActions = ($t: MessageFormatter, album: AlbumResponseDto, asset: AssetResponseDto) => {