Merge remote-tracking branch 'origin/main' into misc_tweaks

This commit is contained in:
Min Idzelis
2025-03-26 00:41:26 +00:00
66 changed files with 510 additions and 345 deletions
@@ -313,6 +313,10 @@
if (onNext) {
asset = await onNext();
} else {
if (currentViewAssetIndex >= assets.length - 1) {
return false;
}
currentViewAssetIndex = currentViewAssetIndex + 1;
asset = currentViewAssetIndex < assets.length ? assets[currentViewAssetIndex] : undefined;
}
@@ -359,6 +363,10 @@
if (onPrevious) {
asset = await onPrevious();
} else {
if (currentViewAssetIndex <= 0) {
return false;
}
currentViewAssetIndex = currentViewAssetIndex - 1;
asset = currentViewAssetIndex >= 0 ? assets[currentViewAssetIndex] : undefined;
}
@@ -461,7 +469,7 @@
style:height={assetLayouts.containerHeight + 'px'}
style:width={assetLayouts.containerWidth - 1 + 'px'}
>
{#each assetLayouts.assetLayout as layout (layout.asset.id)}
{#each assetLayouts.assetLayout as layout, index (layout.asset.id + '-' + index)}
{@const asset = layout.asset}
{#if layout.display}
@@ -164,8 +164,21 @@
};
function getSearchType(): 'smart' | 'metadata' | 'description' {
const t = localStorage.getItem('searchQueryType');
return t === 'smart' || t === 'description' ? t : 'metadata';
const searchType = localStorage.getItem('searchQueryType');
switch (searchType) {
case 'smart': {
return 'smart';
}
case 'metadata': {
return 'metadata';
}
case 'description': {
return 'description';
}
default: {
return 'smart';
}
}
}
function getSearchTypeText(): string {
+65 -19
View File
@@ -9,7 +9,14 @@ import {
} from '$lib/utils/layout-utils';
import { formatDateGroupTitle, fromLocalDateTime } from '$lib/utils/timeline-util';
import { TUNABLES } from '$lib/utils/tunables';
import { getAssetInfo, getTimeBucket, getTimeBuckets, TimeBucketSize, type AssetResponseDto } from '@immich/sdk';
import {
AssetOrder,
getAssetInfo,
getTimeBucket,
getTimeBuckets,
TimeBucketSize,
type AssetResponseDto,
} from '@immich/sdk';
import { clamp, debounce, isEqual, throttle } from 'lodash-es';
import { DateTime } from 'luxon';
import { t } from 'svelte-i18n';
@@ -126,10 +133,15 @@ export class AssetDateGroup {
this.dayOfMonth = dayOfMonth;
}
sortAssets() {
sortAssets(sortOrder: AssetOrder = AssetOrder.Desc) {
this.intersetingAssets.sort((a, b) => {
const aDate = DateTime.fromISO(a.asset!.fileCreatedAt).toUTC();
const bDate = DateTime.fromISO(b.asset!.fileCreatedAt).toUTC();
if (sortOrder === AssetOrder.Asc) {
return aDate.diff(bDate).milliseconds;
}
return bDate.diff(aDate).milliseconds;
});
}
@@ -233,7 +245,7 @@ export class AssetBucket {
#bucketHeight: number = $state(0);
#top: number = $state(0);
#initialCount: number = 0;
#sortOrder: AssetOrder = AssetOrder.Desc;
percent: number = $state(0);
// --- should be private, but is used by AssetStore ---
@@ -250,9 +262,10 @@ export class AssetBucket {
readonly month: number;
readonly year: number;
constructor(store: AssetStore, utcDate: DateTime, initialCount: number) {
constructor(store: AssetStore, utcDate: DateTime, initialCount: number, order: AssetOrder = AssetOrder.Desc) {
this.store = store;
this.#initialCount = initialCount;
this.#sortOrder = order;
const year = utcDate.get('year');
const month = utcDate.get('month');
@@ -319,7 +332,11 @@ export class AssetBucket {
}
sortDateGroups() {
this.dateGroups.sort((a, b) => b.date.diff(a.date).milliseconds);
if (this.#sortOrder === AssetOrder.Asc) {
return this.dateGroups.sort((a, b) => a.date.diff(b.date).milliseconds);
}
return this.dateGroups.sort((a, b) => b.date.diff(a.date).milliseconds);
}
runAssetOperation(ids: Set<string>, operation: AssetOperation) {
@@ -400,10 +417,10 @@ export class AssetBucket {
}
}
for (const group of changedDateGroups) {
group.sortAssets();
group.sortAssets(this.#sortOrder);
}
for (const group of newDateGroups) {
group.sortAssets();
group.sortAssets(this.#sortOrder);
}
if (newDateGroups.size > 0) {
this.sortDateGroups();
@@ -786,7 +803,7 @@ export class AssetStore {
this.buckets = timebuckets.map((bucket) => {
const utcDate = DateTime.fromISO(bucket.timeBucket).toUTC();
return new AssetBucket(this, utcDate, bucket.count);
return new AssetBucket(this, utcDate, bucket.count, this.#options.order);
});
this.albumAssets.clear();
this.#updateViewportGeometry(false);
@@ -1051,7 +1068,7 @@ export class AssetStore {
let bucket = this.getBucketByDate(year, month);
if (!bucket) {
bucket = new AssetBucket(this, utc, 1);
bucket = new AssetBucket(this, utc, 1, this.#options.order);
this.buckets.push(bucket);
}
bucket.addAssets([asset]);
@@ -1063,7 +1080,7 @@ export class AssetStore {
});
for (const dateGroup of updatedDateGroups) {
dateGroup.sortAssets();
dateGroup.sortAssets(this.#options.order);
}
for (const bucket of updatedBuckets) {
bucket.sortDateGroups();
@@ -1213,10 +1230,25 @@ export class AssetStore {
return;
}
for (const group of bucket.dateGroups) {
const index = group.intersetingAssets.findIndex((ia) => ia.id === asset.id);
if (index > 0) {
return group.intersetingAssets[index - 1].asset;
// Find which date group contains this asset
for (let groupIndex = 0; groupIndex < bucket.dateGroups.length; groupIndex++) {
const group = bucket.dateGroups[groupIndex];
const assetIndex = group.intersetingAssets.findIndex((ia) => ia.id === asset.id);
if (assetIndex !== -1) {
// If not the first asset in this group, return the previous one
if (assetIndex > 0) {
return group.intersetingAssets[assetIndex - 1].asset;
}
// If there are previous date groups in this bucket, check the previous one
if (groupIndex > 0) {
const prevGroup = bucket.dateGroups[groupIndex - 1];
return prevGroup.intersetingAssets.at(-1)?.asset;
}
// Otherwise, we need to look in the previous bucket
break;
}
}
@@ -1241,15 +1273,29 @@ export class AssetStore {
return;
}
for (const group of bucket.dateGroups) {
const index = group.intersetingAssets.findIndex((ia) => ia.id === asset.id);
if (index !== -1 && index < group.intersetingAssets.length - 1) {
return group.intersetingAssets[index + 1].asset;
// Find which date group contains this asset
for (let groupIndex = 0; groupIndex < bucket.dateGroups.length; groupIndex++) {
const group = bucket.dateGroups[groupIndex];
const assetIndex = group.intersetingAssets.findIndex((ia) => ia.id === asset.id);
if (assetIndex !== -1) {
// If not the last asset in this group, return the next one
if (assetIndex < group.intersetingAssets.length - 1) {
return group.intersetingAssets[assetIndex + 1].asset;
}
// If there are more date groups in this bucket, check the next one
if (groupIndex < bucket.dateGroups.length - 1) {
return bucket.dateGroups[groupIndex + 1].intersetingAssets[0]?.asset;
}
// Otherwise, we need to look in the next bucket
break;
}
}
let bucketIndex = this.buckets.indexOf(bucket) + 1;
while (bucketIndex < this.buckets.length - 1) {
while (bucketIndex < this.buckets.length) {
bucket = this.buckets[bucketIndex];
await this.loadBucket(bucket.bucketDate);
const next = bucket.dateGroups[0]?.intersetingAssets[0]?.asset;