1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2024-12-29 15:11:58 +00:00

fix flash bug on tag

This commit is contained in:
Min Idzelis 2024-09-04 22:03:59 +00:00
parent 0a8bd7dc66
commit b3d169379e
No known key found for this signature in database
6 changed files with 78 additions and 52 deletions

View file

@ -78,4 +78,4 @@ borg mount "$REMOTE_HOST:$REMOTE_BACKUP_PATH"/immich-borg /tmp/immich-mountpoint
cd /tmp/immich-mountpoint cd /tmp/immich-mountpoint
``` ```
You can find available snapshots in seperate sub-directories at `/tmp/immich-mountpoint`. Restore the files you need, and unmount the Borg repository using `borg umount /tmp/immich-mountpoint` You can find available snapshots in separate sub-directories at `/tmp/immich-mountpoint`. Restore the files you need, and unmount the Borg repository using `borg umount /tmp/immich-mountpoint`

View file

@ -10,10 +10,10 @@ type TrackedProperties = {
left?: string; left?: string;
}; };
type OnIntersectCallback = (entryOrElement: IntersectionObserverEntry | HTMLElement) => unknown; type OnIntersectCallback = (entryOrElement: IntersectionObserverEntry | HTMLElement) => unknown;
type OnSeperateCallback = (element: HTMLElement) => unknown; type OnSeparateCallback = (element: HTMLElement) => unknown;
type IntersectionObserverActionProperties = { type IntersectionObserverActionProperties = {
key?: string; key?: string;
onSeparate?: OnSeperateCallback; onSeparate?: OnSeparateCallback;
onIntersect?: OnIntersectCallback; onIntersect?: OnIntersectCallback;
root?: Element | Document | null; root?: Element | Document | null;
@ -22,8 +22,6 @@ type IntersectionObserverActionProperties = {
right?: string; right?: string;
bottom?: string; bottom?: string;
left?: string; left?: string;
disabled?: boolean;
}; };
type TaskKey = HTMLElement | string; type TaskKey = HTMLElement | string;
@ -92,11 +90,7 @@ function _intersectionObserver(
element: HTMLElement, element: HTMLElement,
properties: IntersectionObserverActionProperties, properties: IntersectionObserverActionProperties,
) { ) {
if (properties.disabled) { configure(key, element, properties);
properties.onIntersect?.(element);
} else {
configure(key, element, properties);
}
return { return {
update(properties: IntersectionObserverActionProperties) { update(properties: IntersectionObserverActionProperties) {
const config = elementToConfig.get(key); const config = elementToConfig.get(key);
@ -106,20 +100,14 @@ function _intersectionObserver(
if (isEquivalent(config, properties)) { if (isEquivalent(config, properties)) {
return; return;
} }
configure(key, element, properties); configure(key, element, properties);
}, },
destroy: () => { destroy: () => {
if (properties.disabled) { const config = elementToConfig.get(key);
properties.onSeparate?.(element); const { observer } = config || {};
} else { observer?.unobserve(element);
const config = elementToConfig.get(key); elementToConfig.delete(key);
const { observer, onSeparate } = config || {};
observer?.unobserve(element);
elementToConfig.delete(key);
if (onSeparate) {
onSeparate?.(element);
}
}
}, },
}; };
} }
@ -148,5 +136,5 @@ export function intersectionObserver(
}, },
}; };
} }
return _intersectionObserver(element, element, properties); return _intersectionObserver(properties.key || element, element, properties);
} }

View file

@ -804,12 +804,13 @@
class:invisible={showSkeleton} class:invisible={showSkeleton}
style:height={$assetStore.timelineHeight + 'px'} style:height={$assetStore.timelineHeight + 'px'}
> >
{#each $assetStore.buckets as bucket (bucket.bucketDate)} {#each $assetStore.buckets as bucket (bucket.viewId)}
{@const isPremeasure = preMeasure.includes(bucket)} {@const isPremeasure = preMeasure.includes(bucket)}
{@const display = bucket.intersecting || bucket === $assetStore.pendingScrollBucket || isPremeasure} {@const display = bucket.intersecting || bucket === $assetStore.pendingScrollBucket || isPremeasure}
<div <div
id="bucket" id="bucket"
use:intersectionObserver={{ use:intersectionObserver={{
key: bucket.viewId,
onIntersect: () => handleIntersect(bucket), onIntersect: () => handleIntersect(bucket),
onSeparate: () => handleSeparate(bucket), onSeparate: () => handleSeparate(bucket),
top: BUCKET_INTERSECTION_ROOT_TOP, top: BUCKET_INTERSECTION_ROOT_TOP,

View file

@ -2,6 +2,7 @@ import { locale } from '$lib/stores/preferences.store';
import { getKey } from '$lib/utils'; import { getKey } from '$lib/utils';
import { AssetGridTaskManager } from '$lib/utils/asset-store-task-manager'; import { AssetGridTaskManager } from '$lib/utils/asset-store-task-manager';
import { getAssetRatio } from '$lib/utils/asset-utils'; import { getAssetRatio } from '$lib/utils/asset-utils';
import { generateId } from '$lib/utils/generate-id';
import type { AssetGridRouteSearchParams } from '$lib/utils/navigation'; import type { AssetGridRouteSearchParams } from '$lib/utils/navigation';
import { calculateWidth, fromLocalDateTime, splitBucketIntoDateGroups, type DateGroup } from '$lib/utils/timeline-util'; import { calculateWidth, fromLocalDateTime, splitBucketIntoDateGroups, type DateGroup } from '$lib/utils/timeline-util';
import { TimeBucketSize, getAssetInfo, getTimeBucket, getTimeBuckets, type AssetResponseDto } from '@immich/sdk'; import { TimeBucketSize, getAssetInfo, getTimeBucket, getTimeBuckets, type AssetResponseDto } from '@immich/sdk';
@ -12,7 +13,6 @@ import { t } from 'svelte-i18n';
import { get, writable, type Unsubscriber } from 'svelte/store'; import { get, writable, type Unsubscriber } from 'svelte/store';
import { handleError } from '../utils/handle-error'; import { handleError } from '../utils/handle-error';
import { websocketEvents } from './websocket'; import { websocketEvents } from './websocket';
type AssetApiGetTimeBucketsRequest = Parameters<typeof getTimeBuckets>[0]; type AssetApiGetTimeBucketsRequest = Parameters<typeof getTimeBuckets>[0];
export type AssetStoreOptions = Omit<AssetApiGetTimeBucketsRequest, 'size'>; export type AssetStoreOptions = Omit<AssetApiGetTimeBucketsRequest, 'size'>;
@ -70,7 +70,10 @@ export class AssetBucket {
Object.assign(this, props); Object.assign(this, props);
this.init(); this.init();
} }
/** The svelte key for this view model object */
get viewId() {
return this.store.viewId + '-' + this.bucketDate;
}
private init() { private init() {
// create a promise, and store its resolve/reject callbacks. The loadedSignal callback // create a promise, and store its resolve/reject callbacks. The loadedSignal callback
// will be incoked when a bucket is loaded, fulfilling the promise. The canceledSignal // will be incoked when a bucket is loaded, fulfilling the promise. The canceledSignal
@ -205,21 +208,23 @@ export class AssetStore {
private assetToBucket: Record<string, AssetLookup> = {}; private assetToBucket: Record<string, AssetLookup> = {};
private pendingChanges: PendingChange[] = []; private pendingChanges: PendingChange[] = [];
private unsubscribers: Unsubscriber[] = []; private unsubscribers: Unsubscriber[] = [];
private options: AssetApiGetTimeBucketsRequest; private options!: AssetApiGetTimeBucketsRequest;
private viewport: Viewport = { private viewport: Viewport = {
height: 0, height: 0,
width: 0, width: 0,
}; };
private initializedSignal!: () => void; private initializedSignal!: () => void;
private store$ = writable(this); private store$ = writable(this);
/** The svelte key for this view model object */
private viewId = generateId();
lastScrollTime: number = 0; lastScrollTime: number = 0;
subscribe = this.store$.subscribe; subscribe = this.store$.subscribe;
/** /**
* A promise that resolves once the store is initialized. * A promise that resolves once the store is initialized.
*/ */
taskManager = new AssetGridTaskManager(this);
complete!: Promise<void>; complete!: Promise<void>;
taskManager = new AssetGridTaskManager(this);
initialized = false; initialized = false;
timelineHeight = 0; timelineHeight = 0;
buckets: AssetBucket[] = []; buckets: AssetBucket[] = [];
@ -234,13 +239,23 @@ export class AssetStore {
options: AssetStoreOptions, options: AssetStoreOptions,
private albumId?: string, private albumId?: string,
) { ) {
this.setOptions(options);
this.createInitializationSignal();
this.store$.set(this);
}
private setOptions(options: AssetStoreOptions) {
this.options = { ...options, size: TimeBucketSize.Month }; this.options = { ...options, size: TimeBucketSize.Month };
}
private createInitializationSignal() {
// create a promise, and store its resolve callbacks. The initializedSignal callback // create a promise, and store its resolve callbacks. The initializedSignal callback
// will be invoked when a the assetstore is initialized. // will be invoked when a the assetstore is initialized.
this.complete = new Promise((resolve) => { this.complete = new Promise((resolve) => {
this.initializedSignal = resolve; this.initializedSignal = resolve;
}); });
this.store$.set(this); // uncaught rejection go away
this.complete.catch(() => void 0);
} }
private addPendingChanges(...changes: PendingChange[]) { private addPendingChanges(...changes: PendingChange[]) {
@ -273,6 +288,7 @@ export class AssetStore {
for (const unsubscribe of this.unsubscribers) { for (const unsubscribe of this.unsubscribers) {
unsubscribe(); unsubscribe();
} }
this.unsubscribers = [];
} }
private getPendingChangeBatches() { private getPendingChangeBatches() {
@ -360,8 +376,10 @@ export class AssetStore {
if (bucketListener) { if (bucketListener) {
this.addListener(bucketListener); this.addListener(bucketListener);
} }
// uncaught rejection go away await this.initialiazeTimeBuckets();
this.complete.catch(() => void 0); }
async initialiazeTimeBuckets() {
this.timelineHeight = 0; this.timelineHeight = 0;
this.buckets = []; this.buckets = [];
this.assets = []; this.assets = [];
@ -379,6 +397,27 @@ export class AssetStore {
this.initialized = true; this.initialized = true;
} }
async updateOptions(options: AssetStoreOptions) {
if (!this.initialized) {
this.setOptions(options);
return;
}
// TODO: don't call updateObjects frequently after
// init - cancelation of the initialize tasks isn't
// performed right now, and will cause issues if
// multiple updateOptions() calls are interleved.
await this.complete;
this.taskManager.destroy();
this.taskManager = new AssetGridTaskManager(this);
this.initialized = false;
this.viewId = generateId();
this.createInitializationSignal();
this.setOptions(options);
await this.initialiazeTimeBuckets();
this.emit(true);
await this.initialLayout(true);
}
public destroy() { public destroy() {
this.taskManager.destroy(); this.taskManager.destroy();
this.listeners = []; this.listeners = [];
@ -386,22 +425,21 @@ export class AssetStore {
} }
async updateViewport(viewport: Viewport, force?: boolean) { async updateViewport(viewport: Viewport, force?: boolean) {
if (!this.initialized) {
return;
}
if (viewport.height === 0 && viewport.width === 0) { if (viewport.height === 0 && viewport.width === 0) {
return; return;
} }
if (!force && this.viewport.height === viewport.height && this.viewport.width === viewport.width) { if (!force && this.viewport.height === viewport.height && this.viewport.width === viewport.width) {
return; return;
} }
await this.complete;
// changing width invalidates the actual height, and needs to be remeasured, since width changes causes // changing width invalidates the actual height, and needs to be remeasured, since width changes causes
// layout reflows. // layout reflows.
const changedWidth = this.viewport.width != viewport.width; const changedWidth = this.viewport.width != viewport.width;
this.viewport = { ...viewport }; this.viewport = { ...viewport };
await this.initialLayout(changedWidth);
}
private async initialLayout(changedWidth: boolean) {
for (const bucket of this.buckets) { for (const bucket of this.buckets) {
this.updateGeometry(bucket, changedWidth); this.updateGeometry(bucket, changedWidth);
} }
@ -410,7 +448,7 @@ export class AssetStore {
const loaders = []; const loaders = [];
let height = 0; let height = 0;
for (const bucket of this.buckets) { for (const bucket of this.buckets) {
if (height >= viewport.height) { if (height >= this.viewport.height) {
break; break;
} }
height += bucket.bucketHeight; height += bucket.bucketHeight;

View file

@ -315,7 +315,7 @@ class IntersectionTask {
return { task: execTask, cleanup }; return { task: execTask, cleanup };
} }
trackSeperatedTask(componentId: string, task: Task) { trackSeparatedTask(componentId: string, task: Task) {
const execTask = () => { const execTask = () => {
if (this.intersected) { if (this.intersected) {
return; return;
@ -363,7 +363,7 @@ class IntersectionTask {
return; return;
} }
const { task, cleanup } = this.trackSeperatedTask(componentId, separated); const { task, cleanup } = this.trackSeparatedTask(componentId, separated);
this.internalTaskManager.queueSeparateTask({ this.internalTaskManager.queueSeparateTask({
task, task,
cleanup, cleanup,

View file

@ -39,10 +39,16 @@
return Object.fromEntries(tags.map((tag) => [tag.value, tag])); return Object.fromEntries(tags.map((tag) => [tag.value, tag]));
}; };
const assetStore = new AssetStore({});
$: tags = data.tags; $: tags = data.tags;
$: tagsMap = buildMap(tags); $: tagsMap = buildMap(tags);
$: tag = currentPath ? tagsMap[currentPath] : null; $: tag = currentPath ? tagsMap[currentPath] : null;
$: tagId = tag?.id;
$: tree = buildTree(tags.map((tag) => tag.value)); $: tree = buildTree(tags.map((tag) => tag.value));
$: {
void assetStore.updateOptions({ tagId });
}
const handleNavigation = async (tag: string) => { const handleNavigation = async (tag: string) => {
await navigateToView(normalizeTreePath(`${data.path || ''}/${tag}`)); await navigateToView(normalizeTreePath(`${data.path || ''}/${tag}`));
@ -167,20 +173,13 @@
<Breadcrumbs {pathSegments} icon={mdiTagMultiple} title={$t('tags')} {getLink} /> <Breadcrumbs {pathSegments} icon={mdiTagMultiple} title={$t('tags')} {getLink} />
<section class="mt-2 h-full"> <section class="mt-2 h-full">
{#key $page.url.href} {#if tag}
{#if tag} <AssetGrid enableRouting={true} {assetStore} {assetInteractionStore} removeAction={AssetAction.UNARCHIVE}>
<AssetGrid <TreeItemThumbnails items={data.children} icon={mdiTag} onClick={handleNavigation} slot="empty" />
enableRouting={true} </AssetGrid>
assetStore={new AssetStore({ tagId: tag.id })} {:else}
{assetInteractionStore} <TreeItemThumbnails items={Object.keys(tree)} icon={mdiTag} onClick={handleNavigation} />
removeAction={AssetAction.UNARCHIVE} {/if}
>
<TreeItemThumbnails items={data.children} icon={mdiTag} onClick={handleNavigation} slot="empty" />
</AssetGrid>
{:else}
<TreeItemThumbnails items={Object.keys(tree)} icon={mdiTag} onClick={handleNavigation} />
{/if}
{/key}
</section> </section>
</UserPageLayout> </UserPageLayout>