From e2ffc9d5a10cb7b7c085ff88051f7c8b1f9d3e20 Mon Sep 17 00:00:00 2001 From: Min Idzelis Date: Wed, 4 Jun 2025 22:27:54 -0400 Subject: [PATCH 1/5] refactor: asset-store (#18938) * refactor: asset-store * Potential fix for code scanning alert no. 152: Prototype-polluting function Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --- .../components/album-page/album-viewer.svelte | 2 +- .../components/asset-viewer/actions/action.ts | 2 +- .../actions/download-action.svelte | 2 +- .../actions/set-visibility-action.svelte | 2 +- .../asset-viewer/asset-viewer.svelte | 2 +- .../asset-viewer/photo-viewer.svelte | 3 +- .../assets/thumbnail/thumbnail.svelte | 2 +- .../memory-page/memory-viewer.svelte | 3 +- .../photos-page/actions/focus-actions.ts | 3 +- .../actions/link-live-photo-action.svelte | 2 +- .../actions/select-all-assets.svelte | 3 +- .../photos-page/asset-date-group.svelte | 13 +- .../components/photos-page/asset-grid.svelte | 12 +- .../asset-select-control-bar.svelte | 2 +- .../individual-shared-viewer.svelte | 2 +- .../gallery-viewer/gallery-viewer.svelte | 3 +- .../scrubber/scrubber.svelte | 3 +- .../timeline-manager/add-context.svelte.ts | 60 + .../timeline-manager/asset-bucket.svelte.ts | 361 ++++ .../asset-date-group.svelte.ts | 162 ++ .../timeline-manager/asset-store.svelte.ts | 934 +++++++++ .../intersecting-asset.svelte.ts | 45 + .../lib/managers/timeline-manager/types.ts | 93 + .../managers/timeline-manager/utils.svelte.ts | 34 + .../lib/stores/asset-interaction.svelte.ts | 2 +- web/src/lib/stores/asset-viewing.store.ts | 2 +- web/src/lib/stores/assets-store.spec.ts | 3 +- web/src/lib/stores/assets-store.svelte.ts | 1674 +---------------- web/src/lib/stores/memory.store.svelte.ts | 2 +- web/src/lib/utils/actions.ts | 3 +- web/src/lib/utils/asset-utils.ts | 10 +- web/src/lib/utils/layout-utils.ts | 2 +- web/src/lib/utils/thumbnail-util.spec.ts | 2 +- web/src/lib/utils/thumbnail-util.ts | 2 +- web/src/lib/utils/timeline-util.ts | 2 +- .../[[assetId=id]]/+page.svelte | 4 +- .../[[assetId=id]]/+page.svelte | 2 +- .../[[assetId=id]]/+page.svelte | 2 +- .../[[assetId=id]]/+page.svelte | 2 +- .../[[assetId=id]]/+page.svelte | 2 +- .../[[assetId=id]]/+page.svelte | 2 +- .../[[assetId=id]]/+page.svelte | 3 +- .../(user)/photos/[[assetId=id]]/+page.svelte | 2 +- .../[[assetId=id]]/+page.svelte | 3 +- .../[[assetId=id]]/+page.svelte | 2 +- .../[[assetId=id]]/+page.svelte | 2 +- web/src/test-data/factories/asset-factory.ts | 2 +- 47 files changed, 1751 insertions(+), 1731 deletions(-) create mode 100644 web/src/lib/managers/timeline-manager/add-context.svelte.ts create mode 100644 web/src/lib/managers/timeline-manager/asset-bucket.svelte.ts create mode 100644 web/src/lib/managers/timeline-manager/asset-date-group.svelte.ts create mode 100644 web/src/lib/managers/timeline-manager/asset-store.svelte.ts create mode 100644 web/src/lib/managers/timeline-manager/intersecting-asset.svelte.ts create mode 100644 web/src/lib/managers/timeline-manager/types.ts create mode 100644 web/src/lib/managers/timeline-manager/utils.svelte.ts diff --git a/web/src/lib/components/album-page/album-viewer.svelte b/web/src/lib/components/album-page/album-viewer.svelte index 59d4b5e6ea..71cd9de932 100644 --- a/web/src/lib/components/album-page/album-viewer.svelte +++ b/web/src/lib/components/album-page/album-viewer.svelte @@ -6,7 +6,7 @@ import AssetSelectControlBar from '$lib/components/photos-page/asset-select-control-bar.svelte'; import { AssetInteraction } from '$lib/stores/asset-interaction.svelte'; import { assetViewingStore } from '$lib/stores/asset-viewing.store'; - import { AssetStore } from '$lib/stores/assets-store.svelte'; + import { AssetStore } from '$lib/managers/timeline-manager/asset-store.svelte'; import { dragAndDropFilesStore } from '$lib/stores/drag-and-drop-files.store'; import { featureFlags } from '$lib/stores/server-config.store'; import { handlePromiseError } from '$lib/utils'; diff --git a/web/src/lib/components/asset-viewer/actions/action.ts b/web/src/lib/components/asset-viewer/actions/action.ts index 0918c86bfe..fd37d253aa 100644 --- a/web/src/lib/components/asset-viewer/actions/action.ts +++ b/web/src/lib/components/asset-viewer/actions/action.ts @@ -1,5 +1,5 @@ import type { AssetAction } from '$lib/constants'; -import type { TimelineAsset } from '$lib/stores/assets-store.svelte'; +import type { TimelineAsset } from '$lib/managers/timeline-manager/types'; import type { AlbumResponseDto } from '@immich/sdk'; type ActionMap = { diff --git a/web/src/lib/components/asset-viewer/actions/download-action.svelte b/web/src/lib/components/asset-viewer/actions/download-action.svelte index 89bf5b72cb..9a2e1a9553 100644 --- a/web/src/lib/components/asset-viewer/actions/download-action.svelte +++ b/web/src/lib/components/asset-viewer/actions/download-action.svelte @@ -2,7 +2,7 @@ import { shortcut } from '$lib/actions/shortcut'; import MenuOption from '$lib/components/shared-components/context-menu/menu-option.svelte'; import { authManager } from '$lib/managers/auth-manager.svelte'; - import type { TimelineAsset } from '$lib/stores/assets-store.svelte'; + import type { TimelineAsset } from '$lib/managers/timeline-manager/types'; import { downloadFile } from '$lib/utils/asset-utils'; import { getAssetInfo } from '@immich/sdk'; import { IconButton } from '@immich/ui'; diff --git a/web/src/lib/components/asset-viewer/actions/set-visibility-action.svelte b/web/src/lib/components/asset-viewer/actions/set-visibility-action.svelte index ab97427524..1b06bf8e21 100644 --- a/web/src/lib/components/asset-viewer/actions/set-visibility-action.svelte +++ b/web/src/lib/components/asset-viewer/actions/set-visibility-action.svelte @@ -3,7 +3,7 @@ import { AssetAction } from '$lib/constants'; import { modalManager } from '$lib/managers/modal-manager.svelte'; - import type { TimelineAsset } from '$lib/stores/assets-store.svelte'; + import type { TimelineAsset } from '$lib/managers/timeline-manager/types'; import { handleError } from '$lib/utils/handle-error'; import { AssetVisibility, updateAssets } from '@immich/sdk'; import { mdiLockOpenVariantOutline, mdiLockOutline } from '@mdi/js'; diff --git a/web/src/lib/components/asset-viewer/asset-viewer.svelte b/web/src/lib/components/asset-viewer/asset-viewer.svelte index eadecfff95..e5d2554e2c 100644 --- a/web/src/lib/components/asset-viewer/asset-viewer.svelte +++ b/web/src/lib/components/asset-viewer/asset-viewer.svelte @@ -10,7 +10,7 @@ import { authManager } from '$lib/managers/auth-manager.svelte'; import { closeEditorCofirm } from '$lib/stores/asset-editor.store'; import { assetViewingStore } from '$lib/stores/asset-viewing.store'; - import type { TimelineAsset } from '$lib/stores/assets-store.svelte'; + import type { TimelineAsset } from '$lib/managers/timeline-manager/types'; import { isShowDetail } from '$lib/stores/preferences.store'; import { SlideshowNavigation, SlideshowState, slideshowStore } from '$lib/stores/slideshow.store'; import { user } from '$lib/stores/user.store'; diff --git a/web/src/lib/components/asset-viewer/photo-viewer.svelte b/web/src/lib/components/asset-viewer/photo-viewer.svelte index 3dffc0e84c..9cb80fb2dd 100644 --- a/web/src/lib/components/asset-viewer/photo-viewer.svelte +++ b/web/src/lib/components/asset-viewer/photo-viewer.svelte @@ -4,7 +4,8 @@ import FaceEditor from '$lib/components/asset-viewer/face-editor/face-editor.svelte'; import BrokenAsset from '$lib/components/assets/broken-asset.svelte'; import { castManager } from '$lib/managers/cast-manager.svelte'; - import { photoViewerImgElement, type TimelineAsset } from '$lib/stores/assets-store.svelte'; + import { photoViewerImgElement } from '$lib/stores/assets-store.svelte'; + import type { TimelineAsset } from '$lib/managers/timeline-manager/types'; import { isFaceEditMode } from '$lib/stores/face-edit.svelte'; import { boundingBoxesArray } from '$lib/stores/people.store'; import { alwaysLoadOriginalFile } from '$lib/stores/preferences.store'; diff --git a/web/src/lib/components/assets/thumbnail/thumbnail.svelte b/web/src/lib/components/assets/thumbnail/thumbnail.svelte index 1f9a29268f..2121531cf5 100644 --- a/web/src/lib/components/assets/thumbnail/thumbnail.svelte +++ b/web/src/lib/components/assets/thumbnail/thumbnail.svelte @@ -18,7 +18,7 @@ import { thumbhash } from '$lib/actions/thumbhash'; import { authManager } from '$lib/managers/auth-manager.svelte'; - import type { TimelineAsset } from '$lib/stores/assets-store.svelte'; + import type { TimelineAsset } from '$lib/managers/timeline-manager/types'; import { mobileDevice } from '$lib/stores/mobile-device.svelte'; import { moveFocus } from '$lib/utils/focus-util'; import { currentUrlReplaceAssetId } from '$lib/utils/navigation'; diff --git a/web/src/lib/components/memory-page/memory-viewer.svelte b/web/src/lib/components/memory-page/memory-viewer.svelte index 92118b4d8c..62e74f5685 100644 --- a/web/src/lib/components/memory-page/memory-viewer.svelte +++ b/web/src/lib/components/memory-page/memory-viewer.svelte @@ -27,7 +27,8 @@ import { authManager } from '$lib/managers/auth-manager.svelte'; import { AssetInteraction } from '$lib/stores/asset-interaction.svelte'; import { assetViewingStore } from '$lib/stores/asset-viewing.store'; - import { type TimelineAsset, type Viewport } from '$lib/stores/assets-store.svelte'; + import type { TimelineAsset } from '$lib/managers/timeline-manager/types'; + import type { Viewport } from '$lib/managers/timeline-manager/types'; import { type MemoryAsset, memoryStore } from '$lib/stores/memory.store.svelte'; import { locale, videoViewerMuted, videoViewerVolume } from '$lib/stores/preferences.store'; import { preferences } from '$lib/stores/user.store'; diff --git a/web/src/lib/components/photos-page/actions/focus-actions.ts b/web/src/lib/components/photos-page/actions/focus-actions.ts index 5085faa0a3..3a75820cd8 100644 --- a/web/src/lib/components/photos-page/actions/focus-actions.ts +++ b/web/src/lib/components/photos-page/actions/focus-actions.ts @@ -1,4 +1,5 @@ -import type { AssetStore, TimelineAsset } from '$lib/stores/assets-store.svelte'; +import { AssetStore } from '$lib/managers/timeline-manager/asset-store.svelte'; +import type { TimelineAsset } from '$lib/managers/timeline-manager/types'; import { moveFocus } from '$lib/utils/focus-util'; import { InvocationTracker } from '$lib/utils/invocationTracker'; import { tick } from 'svelte'; diff --git a/web/src/lib/components/photos-page/actions/link-live-photo-action.svelte b/web/src/lib/components/photos-page/actions/link-live-photo-action.svelte index 1d36c79730..09ca94cb25 100644 --- a/web/src/lib/components/photos-page/actions/link-live-photo-action.svelte +++ b/web/src/lib/components/photos-page/actions/link-live-photo-action.svelte @@ -1,6 +1,6 @@