mirror of
https://github.com/immich-app/immich.git
synced 2026-03-08 11:07:25 +03:00
* chore(web): another missing translations * unused removed * more keys * lint fix * test fixed * dynamic translation fix * fixes * people search translation * params fixed * keep filter setting fix * lint fix * $t fixes * Update web/src/lib/i18n/en.json Co-authored-by: Michel Heusschen <59014050+michelheusschen@users.noreply.github.com> * another missing * activity translation * link sharing translations * expiration dropdown fix - didn't work localized * notification title * device logout * search results * reset to default * unsaved change * select from computer * selected * select-2 * select-3 * unmerge * pluralize, force icu message * Update web/src/lib/components/asset-viewer/asset-viewer.svelte Co-authored-by: Michel Heusschen <59014050+michelheusschen@users.noreply.github.com> * review fixes * remove user * plural fixes * ffmpeg settings * fixes * error title * plural fixes * onboarding * change password * more more * console log fix * another * api key desc * map marker * format fix * key fix * asset-utils * utils * misc --------- Co-authored-by: Michel Heusschen <59014050+michelheusschen@users.noreply.github.com>
73 lines
2.2 KiB
Svelte
73 lines
2.2 KiB
Svelte
<script lang="ts">
|
|
import CircleIconButton from '$lib/components/elements/buttons/circle-icon-button.svelte';
|
|
import MenuOption from '$lib/components/shared-components/context-menu/menu-option.svelte';
|
|
import {
|
|
NotificationType,
|
|
notificationController,
|
|
} from '$lib/components/shared-components/notification/notification';
|
|
import type { OnFavorite } from '$lib/utils/actions';
|
|
import { handleError } from '$lib/utils/handle-error';
|
|
import { updateAssets } from '@immich/sdk';
|
|
import { mdiHeartMinusOutline, mdiHeartOutline, mdiTimerSand } from '@mdi/js';
|
|
import { getAssetControlContext } from '../asset-select-control-bar.svelte';
|
|
import { t } from 'svelte-i18n';
|
|
|
|
export let onFavorite: OnFavorite;
|
|
|
|
export let menuItem = false;
|
|
export let removeFavorite: boolean;
|
|
|
|
$: text = removeFavorite ? $t('remove_from_favorites') : $t('to_favorite');
|
|
$: icon = removeFavorite ? mdiHeartMinusOutline : mdiHeartOutline;
|
|
|
|
let loading = false;
|
|
|
|
const { clearSelect, getOwnedAssets } = getAssetControlContext();
|
|
|
|
const handleFavorite = async () => {
|
|
const isFavorite = !removeFavorite;
|
|
loading = true;
|
|
|
|
try {
|
|
const assets = [...getOwnedAssets()].filter((asset) => asset.isFavorite !== isFavorite);
|
|
|
|
const ids = assets.map(({ id }) => id);
|
|
|
|
if (ids.length > 0) {
|
|
await updateAssets({ assetBulkUpdateDto: { ids, isFavorite } });
|
|
}
|
|
|
|
for (const asset of assets) {
|
|
asset.isFavorite = isFavorite;
|
|
}
|
|
|
|
onFavorite(ids, isFavorite);
|
|
|
|
notificationController.show({
|
|
message: isFavorite
|
|
? $t('added_to_favorites_count', { values: { count: ids.length } })
|
|
: $t('removed_from_favorites_count', { values: { count: ids.length } }),
|
|
type: NotificationType.Info,
|
|
});
|
|
|
|
clearSelect();
|
|
} catch (error) {
|
|
handleError(error, $t('errors.unable_to_add_remove_favorites', { values: { favorite: isFavorite } }));
|
|
} finally {
|
|
loading = false;
|
|
}
|
|
};
|
|
</script>
|
|
|
|
{#if menuItem}
|
|
<MenuOption {text} {icon} onClick={handleFavorite} />
|
|
{/if}
|
|
|
|
{#if !menuItem}
|
|
{#if loading}
|
|
<CircleIconButton title={$t('loading')} icon={mdiTimerSand} />
|
|
{:else}
|
|
<CircleIconButton title={text} {icon} on:click={handleFavorite} />
|
|
{/if}
|
|
{/if}
|