mirror of
https://github.com/immich-app/immich.git
synced 2025-01-07 00:50:23 -05:00
fix(web): bucket by localDateTime
(#12612)
fix(web): local date time for buckets
This commit is contained in:
parent
92811190a8
commit
15f9ff1fcb
3 changed files with 41 additions and 26 deletions
|
@ -219,9 +219,9 @@
|
||||||
<p class="mt-1 truncate font-medium" title={person.name}>{person.name}</p>
|
<p class="mt-1 truncate font-medium" title={person.name}>{person.name}</p>
|
||||||
{#if person.birthDate}
|
{#if person.birthDate}
|
||||||
{@const personBirthDate = DateTime.fromISO(person.birthDate)}
|
{@const personBirthDate = DateTime.fromISO(person.birthDate)}
|
||||||
{@const age = Math.floor(DateTime.fromISO(asset.fileCreatedAt).diff(personBirthDate, 'years').years)}
|
{@const age = Math.floor(DateTime.fromISO(asset.localDateTime).diff(personBirthDate, 'years').years)}
|
||||||
{@const ageInMonths = Math.floor(
|
{@const ageInMonths = Math.floor(
|
||||||
DateTime.fromISO(asset.fileCreatedAt).diff(personBirthDate, 'months').months,
|
DateTime.fromISO(asset.localDateTime).diff(personBirthDate, 'months').months,
|
||||||
)}
|
)}
|
||||||
{#if age >= 0}
|
{#if age >= 0}
|
||||||
<p
|
<p
|
||||||
|
|
|
@ -141,7 +141,10 @@ describe('AssetStore', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('adds assets to new bucket', () => {
|
it('adds assets to new bucket', () => {
|
||||||
const asset = assetFactory.build({ fileCreatedAt: '2024-01-20T12:00:00.000Z' });
|
const asset = assetFactory.build({
|
||||||
|
localDateTime: '2024-01-20T12:00:00.000Z',
|
||||||
|
fileCreatedAt: '2024-01-20T12:00:00.000Z',
|
||||||
|
});
|
||||||
assetStore.addAssets([asset]);
|
assetStore.addAssets([asset]);
|
||||||
|
|
||||||
expect(assetStore.buckets.length).toEqual(1);
|
expect(assetStore.buckets.length).toEqual(1);
|
||||||
|
@ -152,7 +155,10 @@ describe('AssetStore', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('adds assets to existing bucket', () => {
|
it('adds assets to existing bucket', () => {
|
||||||
const [assetOne, assetTwo] = assetFactory.buildList(2, { fileCreatedAt: '2024-01-20T12:00:00.000Z' });
|
const [assetOne, assetTwo] = assetFactory.buildList(2, {
|
||||||
|
localDateTime: '2024-01-20T12:00:00.000Z',
|
||||||
|
fileCreatedAt: '2024-01-20T12:00:00.000Z',
|
||||||
|
});
|
||||||
assetStore.addAssets([assetOne]);
|
assetStore.addAssets([assetOne]);
|
||||||
assetStore.addAssets([assetTwo]);
|
assetStore.addAssets([assetTwo]);
|
||||||
|
|
||||||
|
@ -163,9 +169,18 @@ describe('AssetStore', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('orders assets in buckets by descending date', () => {
|
it('orders assets in buckets by descending date', () => {
|
||||||
const assetOne = assetFactory.build({ fileCreatedAt: '2024-01-20T12:00:00.000Z' });
|
const assetOne = assetFactory.build({
|
||||||
const assetTwo = assetFactory.build({ fileCreatedAt: '2024-01-15T12:00:00.000Z' });
|
fileCreatedAt: '2024-01-20T12:00:00.000Z',
|
||||||
const assetThree = assetFactory.build({ fileCreatedAt: '2024-01-16T12:00:00.000Z' });
|
localDateTime: '2024-01-20T12:00:00.000Z',
|
||||||
|
});
|
||||||
|
const assetTwo = assetFactory.build({
|
||||||
|
fileCreatedAt: '2024-01-15T12:00:00.000Z',
|
||||||
|
localDateTime: '2024-01-15T12:00:00.000Z',
|
||||||
|
});
|
||||||
|
const assetThree = assetFactory.build({
|
||||||
|
fileCreatedAt: '2024-01-16T12:00:00.000Z',
|
||||||
|
localDateTime: '2024-01-16T12:00:00.000Z',
|
||||||
|
});
|
||||||
assetStore.addAssets([assetOne, assetTwo, assetThree]);
|
assetStore.addAssets([assetOne, assetTwo, assetThree]);
|
||||||
|
|
||||||
const bucket = assetStore.getBucketByDate('2024-01-01T00:00:00.000Z');
|
const bucket = assetStore.getBucketByDate('2024-01-01T00:00:00.000Z');
|
||||||
|
@ -177,9 +192,9 @@ describe('AssetStore', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('orders buckets by descending date', () => {
|
it('orders buckets by descending date', () => {
|
||||||
const assetOne = assetFactory.build({ fileCreatedAt: '2024-01-20T12:00:00.000Z' });
|
const assetOne = assetFactory.build({ localDateTime: '2024-01-20T12:00:00.000Z' });
|
||||||
const assetTwo = assetFactory.build({ fileCreatedAt: '2024-04-20T12:00:00.000Z' });
|
const assetTwo = assetFactory.build({ localDateTime: '2024-04-20T12:00:00.000Z' });
|
||||||
const assetThree = assetFactory.build({ fileCreatedAt: '2023-01-20T12:00:00.000Z' });
|
const assetThree = assetFactory.build({ localDateTime: '2023-01-20T12:00:00.000Z' });
|
||||||
assetStore.addAssets([assetOne, assetTwo, assetThree]);
|
assetStore.addAssets([assetOne, assetTwo, assetThree]);
|
||||||
|
|
||||||
expect(assetStore.buckets.length).toEqual(3);
|
expect(assetStore.buckets.length).toEqual(3);
|
||||||
|
@ -239,8 +254,8 @@ describe('AssetStore', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('replaces bucket date when asset date changes', () => {
|
it('replaces bucket date when asset date changes', () => {
|
||||||
const asset = assetFactory.build({ fileCreatedAt: '2024-01-20T12:00:00.000Z' });
|
const asset = assetFactory.build({ localDateTime: '2024-01-20T12:00:00.000Z' });
|
||||||
const updatedAsset = { ...asset, fileCreatedAt: '2024-03-20T12:00:00.000Z' };
|
const updatedAsset = { ...asset, localDateTime: '2024-03-20T12:00:00.000Z' };
|
||||||
|
|
||||||
assetStore.addAssets([asset]);
|
assetStore.addAssets([asset]);
|
||||||
expect(assetStore.buckets.length).toEqual(1);
|
expect(assetStore.buckets.length).toEqual(1);
|
||||||
|
@ -264,7 +279,7 @@ describe('AssetStore', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('ignores invalid IDs', () => {
|
it('ignores invalid IDs', () => {
|
||||||
assetStore.addAssets(assetFactory.buildList(2, { fileCreatedAt: '2024-01-20T12:00:00.000Z' }));
|
assetStore.addAssets(assetFactory.buildList(2, { localDateTime: '2024-01-20T12:00:00.000Z' }));
|
||||||
assetStore.removeAssets(['', 'invalid', '4c7d9acc']);
|
assetStore.removeAssets(['', 'invalid', '4c7d9acc']);
|
||||||
|
|
||||||
expect(assetStore.assets.length).toEqual(2);
|
expect(assetStore.assets.length).toEqual(2);
|
||||||
|
@ -273,7 +288,7 @@ describe('AssetStore', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('removes asset from bucket', () => {
|
it('removes asset from bucket', () => {
|
||||||
const [assetOne, assetTwo] = assetFactory.buildList(2, { fileCreatedAt: '2024-01-20T12:00:00.000Z' });
|
const [assetOne, assetTwo] = assetFactory.buildList(2, { localDateTime: '2024-01-20T12:00:00.000Z' });
|
||||||
assetStore.addAssets([assetOne, assetTwo]);
|
assetStore.addAssets([assetOne, assetTwo]);
|
||||||
assetStore.removeAssets([assetOne.id]);
|
assetStore.removeAssets([assetOne.id]);
|
||||||
|
|
||||||
|
@ -283,7 +298,7 @@ describe('AssetStore', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('removes bucket when empty', () => {
|
it('removes bucket when empty', () => {
|
||||||
const assets = assetFactory.buildList(2, { fileCreatedAt: '2024-01-20T12:00:00.000Z' });
|
const assets = assetFactory.buildList(2, { localDateTime: '2024-01-20T12:00:00.000Z' });
|
||||||
assetStore.addAssets(assets);
|
assetStore.addAssets(assets);
|
||||||
assetStore.removeAssets(assets.map((asset) => asset.id));
|
assetStore.removeAssets(assets.map((asset) => asset.id));
|
||||||
|
|
||||||
|
@ -376,8 +391,8 @@ describe('AssetStore', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns the bucket index', () => {
|
it('returns the bucket index', () => {
|
||||||
const assetOne = assetFactory.build({ fileCreatedAt: '2024-01-20T12:00:00.000Z' });
|
const assetOne = assetFactory.build({ localDateTime: '2024-01-20T12:00:00.000Z' });
|
||||||
const assetTwo = assetFactory.build({ fileCreatedAt: '2024-02-15T12:00:00.000Z' });
|
const assetTwo = assetFactory.build({ localDateTime: '2024-02-15T12:00:00.000Z' });
|
||||||
assetStore.addAssets([assetOne, assetTwo]);
|
assetStore.addAssets([assetOne, assetTwo]);
|
||||||
|
|
||||||
expect(assetStore.getBucketIndexByAssetId(assetTwo.id)).toEqual(0);
|
expect(assetStore.getBucketIndexByAssetId(assetTwo.id)).toEqual(0);
|
||||||
|
@ -385,8 +400,8 @@ describe('AssetStore', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('ignores removed buckets', () => {
|
it('ignores removed buckets', () => {
|
||||||
const assetOne = assetFactory.build({ fileCreatedAt: '2024-01-20T12:00:00.000Z' });
|
const assetOne = assetFactory.build({ localDateTime: '2024-01-20T12:00:00.000Z' });
|
||||||
const assetTwo = assetFactory.build({ fileCreatedAt: '2024-02-15T12:00:00.000Z' });
|
const assetTwo = assetFactory.build({ localDateTime: '2024-02-15T12:00:00.000Z' });
|
||||||
assetStore.addAssets([assetOne, assetTwo]);
|
assetStore.addAssets([assetOne, assetTwo]);
|
||||||
|
|
||||||
assetStore.removeAssets([assetTwo.id]);
|
assetStore.removeAssets([assetTwo.id]);
|
||||||
|
|
|
@ -661,7 +661,7 @@ export class AssetStore {
|
||||||
const updatedBuckets = new Set<AssetBucket>();
|
const updatedBuckets = new Set<AssetBucket>();
|
||||||
|
|
||||||
for (const asset of assets) {
|
for (const asset of assets) {
|
||||||
const timeBucket = DateTime.fromISO(asset.fileCreatedAt).toUTC().startOf('month').toString();
|
const timeBucket = DateTime.fromISO(asset.localDateTime).toUTC().startOf('month').toString();
|
||||||
let bucket = this.getBucketByDate(timeBucket);
|
let bucket = this.getBucketByDate(timeBucket);
|
||||||
|
|
||||||
if (!bucket) {
|
if (!bucket) {
|
||||||
|
@ -791,7 +791,7 @@ export class AssetStore {
|
||||||
if (assets.length === 0) {
|
if (assets.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const assetsToReculculate: AssetResponseDto[] = [];
|
const assetsToRecalculate: AssetResponseDto[] = [];
|
||||||
|
|
||||||
for (const _asset of assets) {
|
for (const _asset of assets) {
|
||||||
const asset = this.assets.find((asset) => asset.id === _asset.id);
|
const asset = this.assets.find((asset) => asset.id === _asset.id);
|
||||||
|
@ -799,17 +799,17 @@ export class AssetStore {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const recalculate = asset.fileCreatedAt !== _asset.fileCreatedAt;
|
const recalculate = asset.localDateTime !== _asset.localDateTime;
|
||||||
Object.assign(asset, _asset);
|
Object.assign(asset, _asset);
|
||||||
|
|
||||||
if (recalculate) {
|
if (recalculate) {
|
||||||
assetsToReculculate.push(asset);
|
assetsToRecalculate.push(asset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.removeAssets(assetsToReculculate.map((asset) => asset.id));
|
this.removeAssets(assetsToRecalculate.map((asset) => asset.id));
|
||||||
this.addAssetsToBuckets(assetsToReculculate);
|
this.addAssetsToBuckets(assetsToRecalculate);
|
||||||
this.emit(assetsToReculculate.length > 0);
|
this.emit(assetsToRecalculate.length > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
removeAssets(ids: string[]) {
|
removeAssets(ids: string[]) {
|
||||||
|
|
Loading…
Reference in a new issue