1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2025-01-09 13:26:47 +01:00

Add selection of favorites

This commit is contained in:
Yonggan 2023-06-10 13:51:19 +02:00
parent 05e851ef44
commit 026ffbe133
4 changed files with 70 additions and 64 deletions

View file

@ -24,6 +24,7 @@
import Button from '../elements/buttons/button.svelte';
import CircleIconButton from '../elements/buttons/circle-icon-button.svelte';
import DownloadAction from '../photos-page/actions/download-action.svelte';
import SelectAllAssets from '../photos-page/actions/select-all-assets.svelte';
import RemoveFromAlbum from '../photos-page/actions/remove-from-album.svelte';
import AssetSelectControlBar from '../photos-page/asset-select-control-bar.svelte';
import UserAvatar from '../shared-components/user-avatar.svelte';
@ -341,6 +342,7 @@
assets={multiSelectAsset}
clearSelect={() => (multiSelectAsset = new Set())}
>
<SelectAllAssets/>
<DownloadAction filename={album.albumName} sharedLinkKey={sharedLink?.key} />
{#if isOwned}
<RemoveFromAlbum bind:album />

View file

@ -7,7 +7,7 @@
import {api, AssetResponseDto} from '@api';
import SelectAll from 'svelte-material-icons/SelectAll.svelte';
import TimerSand from 'svelte-material-icons/TimerSand.svelte';
import {OnSelectAll, getAssetControlContext} from '../asset-select-control-bar.svelte';
import {getAssetControlContext} from '../asset-select-control-bar.svelte';
import {
assetInteractionStore,
selectedAssets
@ -18,8 +18,6 @@
import {AssetGridState} from "$lib/models/asset-grid-state";
import {sumBy} from "lodash-es";
export let onSelectAll: OnSelectAll;
let selecting = false;
const handleSelectAll = async () => {

View file

@ -2,7 +2,6 @@
import { createContext } from '$lib/utils/context';
export type OnAssetDelete = (assetId: string) => void;
export type OnSelectAll = (assetId: string) => void;
export type OnAssetArchive = (asset: AssetResponseDto, archived: boolean) => void;
export type OnAssetFavorite = (asset: AssetResponseDto, favorite: boolean) => void;

View file

@ -1,75 +1,82 @@
<script lang="ts">
import UserPageLayout from '$lib/components/layouts/user-page-layout.svelte';
import AddToAlbum from '$lib/components/photos-page/actions/add-to-album.svelte';
import ArchiveAction from '$lib/components/photos-page/actions/archive-action.svelte';
import CreateSharedLink from '$lib/components/photos-page/actions/create-shared-link.svelte';
import DeleteAssets from '$lib/components/photos-page/actions/delete-assets.svelte';
import DownloadAction from '$lib/components/photos-page/actions/download-action.svelte';
import FavoriteAction from '$lib/components/photos-page/actions/favorite-action.svelte';
import AssetSelectContextMenu from '$lib/components/photos-page/asset-select-context-menu.svelte';
import AssetSelectControlBar from '$lib/components/photos-page/asset-select-control-bar.svelte';
import EmptyPlaceholder from '$lib/components/shared-components/empty-placeholder.svelte';
import GalleryViewer from '$lib/components/shared-components/gallery-viewer/gallery-viewer.svelte';
import { handleError } from '$lib/utils/handle-error';
import { api, AssetResponseDto } from '@api';
import { onMount } from 'svelte';
import DotsVertical from 'svelte-material-icons/DotsVertical.svelte';
import Plus from 'svelte-material-icons/Plus.svelte';
import Error from '../../+error.svelte';
import type { PageData } from './$types';
import UserPageLayout from '$lib/components/layouts/user-page-layout.svelte';
import AddToAlbum from '$lib/components/photos-page/actions/add-to-album.svelte';
import ArchiveAction from '$lib/components/photos-page/actions/archive-action.svelte';
import CreateSharedLink from '$lib/components/photos-page/actions/create-shared-link.svelte';
import DeleteAssets from '$lib/components/photos-page/actions/delete-assets.svelte';
import DownloadAction from '$lib/components/photos-page/actions/download-action.svelte';
import FavoriteAction from '$lib/components/photos-page/actions/favorite-action.svelte';
import AssetSelectContextMenu from '$lib/components/photos-page/asset-select-context-menu.svelte';
import AssetSelectControlBar from '$lib/components/photos-page/asset-select-control-bar.svelte';
import EmptyPlaceholder from '$lib/components/shared-components/empty-placeholder.svelte';
import GalleryViewer from '$lib/components/shared-components/gallery-viewer/gallery-viewer.svelte';
import CircleIconButton from '$lib/components/elements/buttons/circle-icon-button.svelte';
import SelectAll from 'svelte-material-icons/SelectAll.svelte';
import TimerSand from 'svelte-material-icons/TimerSand.svelte';
import {handleError} from '$lib/utils/handle-error';
import {api, AssetResponseDto} from '@api';
import {onMount} from 'svelte';
import DotsVertical from 'svelte-material-icons/DotsVertical.svelte';
import Plus from 'svelte-material-icons/Plus.svelte';
import Error from '../../+error.svelte';
import type {PageData} from './$types';
let favorites: AssetResponseDto[] = [];
let selectedAssets: Set<AssetResponseDto> = new Set();
let favorites: AssetResponseDto[] = [];
let selectedAssets: Set<AssetResponseDto> = new Set();
export let data: PageData;
export let data: PageData;
$: isMultiSelectionMode = selectedAssets.size > 0;
$: isAllArchive = Array.from(selectedAssets).every((asset) => asset.isArchived);
$: isMultiSelectionMode = selectedAssets.size > 0;
$: isAllArchive = Array.from(selectedAssets).every((asset) => asset.isArchived);
onMount(async () => {
try {
const {data: assets} = await api.assetApi.getAllAssets({
isFavorite: true,
withoutThumbs: true
});
favorites = assets;
} catch {
handleError(Error, 'Unable to load favorites');
}
});
onMount(async () => {
try {
const { data: assets } = await api.assetApi.getAllAssets({
isFavorite: true,
withoutThumbs: true
});
favorites = assets;
} catch {
handleError(Error, 'Unable to load favorites');
}
});
const handleSelectAll = () => {
selectedAssets = new Set(favorites);
};
const onAssetDelete = (assetId: string) => {
favorites = favorites.filter((a) => a.id !== assetId);
};
const onAssetDelete = (assetId: string) => {
favorites = favorites.filter((a) => a.id !== assetId);
};
</script>
<!-- Multiselection mode app bar -->
{#if isMultiSelectionMode}
<AssetSelectControlBar assets={selectedAssets} clearSelect={() => (selectedAssets = new Set())}>
<FavoriteAction removeFavorite onAssetFavorite={(asset) => onAssetDelete(asset.id)} />
<CreateSharedLink />
<AssetSelectContextMenu icon={Plus} title="Add">
<AddToAlbum />
<AddToAlbum shared />
</AssetSelectContextMenu>
<DeleteAssets {onAssetDelete} />
<AssetSelectContextMenu icon={DotsVertical} title="Menu">
<DownloadAction menuItem />
<ArchiveAction menuItem unarchive={isAllArchive} />
</AssetSelectContextMenu>
</AssetSelectControlBar>
<AssetSelectControlBar assets={selectedAssets} clearSelect={() => (selectedAssets = new Set())}>
<FavoriteAction removeFavorite onAssetFavorite={(asset) => onAssetDelete(asset.id)}/>
<CreateSharedLink/>
<CircleIconButton title="Delete" logo={SelectAll} on:click={handleSelectAll}/>
<AssetSelectContextMenu icon={Plus} title="Add">
<AddToAlbum/>
<AddToAlbum shared/>
</AssetSelectContextMenu>
<DeleteAssets {onAssetDelete}/>
<AssetSelectContextMenu icon={DotsVertical} title="Menu">
<DownloadAction menuItem/>
<ArchiveAction menuItem unarchive={isAllArchive}/>
</AssetSelectContextMenu>
</AssetSelectControlBar>
{/if}
<UserPageLayout user={data.user} hideNavbar={isMultiSelectionMode} title={data.meta.title}>
<section>
<!-- Empty Message -->
{#if favorites.length === 0}
<EmptyPlaceholder
text="Add favorites to quickly find your best pictures and videos"
alt="Empty favorites"
/>
{/if}
<section>
<!-- Empty Message -->
{#if favorites.length === 0}
<EmptyPlaceholder
text="Add favorites to quickly find your best pictures and videos"
alt="Empty favorites"
/>
{/if}
<GalleryViewer assets={favorites} bind:selectedAssets viewFrom="favorites-page" />
</section>
<GalleryViewer assets={favorites} bind:selectedAssets viewFrom="favorites-page"/>
</section>
</UserPageLayout>