High performance self-hosted photo and video management solution.
TypeScript backup-toolfluttergoogle-photosgoogle-photos-alternativejavascriptmobile-appnestjsnodejsphoto-galleryphotosphotos-managementself-hostedsveltesveltekittypescriptvideos
chore: rework tags sidebar (#25855)
Daniel Dietzler94965f6d6663
diff --git a/web/src/lib/components/asset-viewer/asset-viewer.svelte b/web/src/lib/components/asset-viewer/asset-viewer.svelteindex 6284e207c6..06f4e5a0b2 100644--- a/web/src/lib/components/asset-viewer/asset-viewer.svelte+++ b/web/src/lib/components/asset-viewer/asset-viewer.svelte@@ -14,6 +14,7 @@import { eventManager } from '$lib/managers/event-manager.svelte';import { imageManager } from '$lib/managers/ImageManager.svelte';import { Route } from '$lib/route';+ import { getAssetActions } from '$lib/services/asset.service';import { assetViewingStore } from '$lib/stores/asset-viewing.store';import { ocrManager } from '$lib/stores/ocr.svelte';import { alwaysLoadOriginalVideo } from '$lib/stores/preferences.store';@@ -36,6 +37,7 @@type PersonResponseDto,type StackResponseDto,} from '@immich/sdk';+ import { CommandPaletteDefaultProvider } from '@immich/ui';import { onDestroy, onMount, untrack } from 'svelte';import { t } from 'svelte-i18n';import { fly } from 'svelte/transition';@@ -426,8 +428,11 @@!assetViewerManager.isShowEditor &&ocrManager.hasOcrData,);++ const { Tag } = $derived(getAssetActions($t, asset));</script>+<CommandPaletteDefaultProvider name={$t('assets')} actions={[Tag]} /><OnEvents {onAssetReplace} {onAssetUpdate} /><svelte:document bind:fullscreenElement />diff --git a/web/src/lib/components/asset-viewer/detail-panel-tags.svelte b/web/src/lib/components/asset-viewer/detail-panel-tags.svelteindex cd9b1a40d2..09c4432723 100644--- a/web/src/lib/components/asset-viewer/detail-panel-tags.svelte+++ b/web/src/lib/components/asset-viewer/detail-panel-tags.svelte@@ -1,12 +1,13 @@<script lang="ts">- import { shortcut } from '$lib/actions/shortcut';+ import HeaderActionButton from '$lib/components/HeaderActionButton.svelte';+ import OnEvents from '$lib/components/OnEvents.svelte';import { authManager } from '$lib/managers/auth-manager.svelte';- import AssetTagModal from '$lib/modals/AssetTagModal.svelte';import { Route } from '$lib/route';+ import { getAssetActions } from '$lib/services/asset.service';import { removeTag } from '$lib/utils/asset-utils';import { getAssetInfo, type AssetResponseDto } from '@immich/sdk';- import { Icon, modalManager, Text } from '@immich/ui';- import { mdiClose, mdiPlus } from '@mdi/js';+ import { Badge, IconButton, Link, Text } from '@immich/ui';+ import { mdiClose } from '@mdi/js';import { t } from 'svelte-i18n';interface Props {@@ -18,22 +19,23 @@let tags = $derived(asset.tags || []);- const handleAddTag = async () => {- const success = await modalManager.show(AssetTagModal, { assetIds: [asset.id] });- if (success) {+ const handleRemove = async (tagId: string) => {+ const ids = await removeTag({ tagIds: [tagId], assetIds: [asset.id], showNotification: false });+ if (ids) {asset = await getAssetInfo({ id: asset.id });}};- const handleRemove = async (tagId: string) => {- const ids = await removeTag({ tagIds: [tagId], assetIds: [asset.id], showNotification: false });- if (ids) {+ const onAssetsTag = async (ids: string[]) => {+ if (ids.includes(asset.id)) {asset = await getAssetInfo({ id: asset.id });}};++ const { Tag } = $derived(getAssetActions($t, asset));</script>-<svelte:document use:shortcut={{ shortcut: { key: 't' }, onShortcut: handleAddTag }} />+<OnEvents {onAssetsTag} />{#if isOwner && !authManager.isSharedLink}<section class="px-4 mt-4">@@ -42,36 +44,24 @@</div><section class="flex flex-wrap pt-2 gap-1" data-testid="detail-panel-tags">{#each tags as tag (tag.id)}- <div class="flex group transition-all">- <a- class="inline-block h-min whitespace-nowrap ps-3 pe-1 group-hover:ps-3 py-1 text-center align-baseline leading-none text-gray-100 dark:text-immich-dark-gray bg-primary rounded-s-full hover:bg-immich-primary/80 dark:hover:bg-immich-dark-primary/80 transition-all"+ <Badge size="small" class="items-center px-0" shape="round">+ <Linkhref={Route.tags({ path: tag.value })}+ class="text-light no-underline rounded-full hover:bg-primary-400 px-2">- <p class="text-sm">- {tag.value}- </p>- </a>-- <button- type="button"- class="text-gray-100 dark:text-immich-dark-gray bg-immich-primary/95 dark:bg-immich-dark-primary/95 rounded-e-full place-items-center place-content-center pe-2 ps-1 py-1 hover:bg-immich-primary/80 dark:hover:bg-immich-dark-primary/80 transition-all"- title="Remove tag"+ {tag.value}+ </Link>+ <IconButton+ aria-label={$t('remove_tag')}+ icon={mdiClose}onclick={() => handleRemove(tag.id)}- >- <Icon icon={mdiClose} />- </button>- </div>+ size="tiny"+ class="hover:bg-primary-400"+ shape="round"+ />+ </Badge>{/each}- <button- type="button"- class="rounded-full bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-300 hover:bg-gray-200 dark:hover:bg-gray-700 hover:text-gray-700 dark:hover:text-gray-200 flex place-items-center place-content-center gap-1 px-2 py-1"- title={$t('add_tag')}- onclick={handleAddTag}- >- <span class="text-sm px-1 flex place-items-center place-content-center gap-1"- ><Icon icon={mdiPlus} />{$t('add')}</span- >- </button>+ <HeaderActionButton action={Tag} /></section></section>{/if}diff --git a/web/src/lib/components/timeline/actions/TagAction.svelte b/web/src/lib/components/timeline/actions/TagAction.svelteindex d2235d7c74..dfe24b476b 100644--- a/web/src/lib/components/timeline/actions/TagAction.svelte+++ b/web/src/lib/components/timeline/actions/TagAction.svelte@@ -20,11 +20,8 @@const handleTagAssets = async () => {const assets = [...getOwnedAssets()];- const success = await modalManager.show(AssetTagModal, { assetIds: assets.map(({ id }) => id) });-- if (success) {- clearSelect();- }+ await modalManager.show(AssetTagModal, { assetIds: assets.map(({ id }) => id) });+ clearSelect();};</script>diff --git a/web/src/lib/managers/event-manager.svelte.ts b/web/src/lib/managers/event-manager.svelte.tsindex 4825dbc93b..4093413d1a 100644--- a/web/src/lib/managers/event-manager.svelte.ts+++ b/web/src/lib/managers/event-manager.svelte.ts@@ -37,6 +37,7 @@ export type Events = {AssetsArchive: [string[]];AssetsDelete: [string[]];AssetEditsApplied: [string];+ AssetsTag: [string[]];AlbumAddAssets: [];AlbumUpdate: [AlbumResponseDto];diff --git a/web/src/lib/modals/AssetTagModal.svelte b/web/src/lib/modals/AssetTagModal.svelteindex e541e24b60..00862ce1b1 100644--- a/web/src/lib/modals/AssetTagModal.svelte+++ b/web/src/lib/modals/AssetTagModal.svelte@@ -1,4 +1,5 @@<script lang="ts">+ import { eventManager } from '$lib/managers/event-manager.svelte';import { tagAssets } from '$lib/utils/asset-utils';import { getAllTags, upsertTags, type TagResponseDto } from '@immich/sdk';import { FormModal, Icon } from '@immich/ui';@@ -9,7 +10,7 @@import Combobox, { type ComboBoxOption } from '../components/shared-components/combobox.svelte';interface Props {- onClose: (success?: true) => void;+ onClose: () => void;assetIds: string[];}@@ -30,8 +31,8 @@return;}- await tagAssets({ tagIds: [...selectedIds], assetIds, showNotification: false });- onClose(true);+ const updatedIds = await tagAssets({ tagIds: [...selectedIds], assetIds, showNotification: false });+ eventManager.emit('AssetsTag', updatedIds);};const handleSelect = async (option?: ComboBoxOption) => {diff --git a/web/src/lib/services/asset.service.ts b/web/src/lib/services/asset.service.tsindex f830a3473f..0c1c96ab04 100644--- a/web/src/lib/services/asset.service.ts+++ b/web/src/lib/services/asset.service.ts@@ -2,6 +2,7 @@ import { ProjectionType } from '$lib/constants';import { assetViewerManager } from '$lib/managers/asset-viewer-manager.svelte';import { authManager } from '$lib/managers/auth-manager.svelte';import { eventManager } from '$lib/managers/event-manager.svelte';+import AssetTagModal from '$lib/modals/AssetTagModal.svelte';import SharedLinkCreateModal from '$lib/modals/SharedLinkCreateModal.svelte';import { user as authUser, preferences } from '$lib/stores/user.store';import { getAssetJobName, getSharedLink, sleep } from '$lib/utils';@@ -41,6 +42,7 @@ import {mdiMotionPauseOutline,mdiMotionPlayOutline,mdiShareVariantOutline,+ mdiTagPlusOutline,mdiTune,} from '@mdi/js';import type { MessageFormatter } from 'svelte-i18n';@@ -49,6 +51,7 @@ import { get } from 'svelte/store';export const getAssetActions = ($t: MessageFormatter, asset: AssetResponseDto) => {const sharedLink = getSharedLink();const currentAuthUser = get(authUser);+ const userPreferences = get(preferences);const isOwner = !!(currentAuthUser && currentAuthUser.id === asset.ownerId);const Share: ActionItem = {@@ -155,7 +158,16 @@ export const getAssetActions = ($t: MessageFormatter, asset: AssetResponseDto) =type: $t('assets'),$if: () => asset.hasMetadata,onAction: () => assetViewerManager.toggleDetailPanel(),- shortcuts: [{ key: 'i' }],+ shortcuts: { key: 'i' },+ };++ const Tag: ActionItem = {+ title: $t('add_tag'),+ icon: mdiTagPlusOutline,+ type: $t('assets'),+ $if: () => userPreferences.tags.enabled,+ onAction: () => modalManager.show(AssetTagModal, { assetIds: [asset.id] }),+ shortcuts: { key: 't' },};const Edit: ActionItem = {@@ -212,6 +224,7 @@ export const getAssetActions = ($t: MessageFormatter, asset: AssetResponseDto) =ZoomIn,ZoomOut,Copy,+ Tag,Edit,RefreshFacesJob,RefreshMetadataJob,