Skip to content

Commit e3dbf47

Browse files
committed
fix(web): asset refresh
1 parent 027dab1 commit e3dbf47

File tree

3 files changed

+48
-58
lines changed

3 files changed

+48
-58
lines changed

web/src/lib/components/asset-viewer/detail-panel-tags.svelte

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
2222
const handleAddTag = async () => {
2323
const success = await modalManager.show(AssetTagModal, { assetIds: [asset.id] });
24-
2524
if (success) {
2625
asset = await getAssetInfo({ id: asset.id });
2726
}

web/src/lib/components/asset-viewer/detail-panel.svelte

Lines changed: 38 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,13 @@
1717
import { featureFlags } from '$lib/stores/server-config.store';
1818
import { preferences, user } from '$lib/stores/user.store';
1919
import { getAssetThumbnailUrl, getPeopleThumbnailUrl, handlePromiseError } from '$lib/utils';
20-
import { delay, isFlipped } from '$lib/utils/asset-utils';
20+
import { delay, getDimensions } from '$lib/utils/asset-utils';
2121
import { getByteUnitString } from '$lib/utils/byte-units';
2222
import { handleError } from '$lib/utils/handle-error';
2323
import { getMetadataSearchQuery } from '$lib/utils/metadata-search';
2424
import { fromISODateTime, fromISODateTimeUTC } from '$lib/utils/timeline-util';
2525
import { getParentPath } from '$lib/utils/tree-utils';
26-
import {
27-
AssetMediaSize,
28-
getAssetInfo,
29-
updateAsset,
30-
type AlbumResponseDto,
31-
type AssetResponseDto,
32-
type ExifResponseDto,
33-
} from '@immich/sdk';
26+
import { AssetMediaSize, getAssetInfo, updateAsset, type AlbumResponseDto, type AssetResponseDto } from '@immich/sdk';
3427
import { IconButton } from '@immich/ui';
3528
import {
3629
mdiCalendar,
@@ -61,44 +54,18 @@
6154
6255
let { asset, albums = [], currentAlbum = null, onClose }: Props = $props();
6356
64-
const getDimensions = (exifInfo: ExifResponseDto) => {
65-
const { exifImageWidth: width, exifImageHeight: height } = exifInfo;
66-
if (isFlipped(exifInfo.orientation)) {
67-
return { width: height, height: width };
68-
}
69-
70-
return { width, height };
71-
};
72-
7357
let showAssetPath = $state(false);
7458
let showEditFaces = $state(false);
75-
let previousId: string | undefined = $state();
76-
77-
$effect(() => {
78-
if (!previousId) {
79-
previousId = asset.id;
80-
}
81-
if (asset.id !== previousId) {
82-
showEditFaces = false;
83-
previousId = asset.id;
84-
}
85-
});
86-
8759
let isOwner = $derived($user?.id === asset.ownerId);
88-
89-
const handleNewAsset = async (newAsset: AssetResponseDto) => {
90-
// TODO: check if reloading asset data is necessary
91-
if (newAsset.id && !authManager.isSharedLink) {
92-
const data = await getAssetInfo({ id: asset.id });
93-
people = data?.people || [];
94-
unassignedFaces = data?.unassignedFaces || [];
95-
}
96-
};
97-
98-
$effect(() => {
99-
handlePromiseError(handleNewAsset(asset));
100-
});
101-
60+
let people = $derived(asset.people || []);
61+
let unassignedFaces = $derived(asset.unassignedFaces || []);
62+
let showingHiddenPeople = $state(false);
63+
let timeZone = $derived(asset.exifInfo?.timeZone);
64+
let dateTime = $derived(
65+
timeZone && asset.exifInfo?.dateTimeOriginal
66+
? fromISODateTime(asset.exifInfo.dateTimeOriginal, timeZone)
67+
: fromISODateTimeUTC(asset.localDateTime),
68+
);
10269
let latlng = $derived(
10370
(() => {
10471
const lat = asset.exifInfo?.latitude;
@@ -109,16 +76,17 @@
10976
}
11077
})(),
11178
);
79+
let previousId: string | undefined = $state();
11280
113-
let people = $state(asset.people || []);
114-
let unassignedFaces = $state(asset.unassignedFaces || []);
115-
let showingHiddenPeople = $state(false);
116-
let timeZone = $derived(asset.exifInfo?.timeZone);
117-
let dateTime = $derived(
118-
timeZone && asset.exifInfo?.dateTimeOriginal
119-
? fromISODateTime(asset.exifInfo.dateTimeOriginal, timeZone)
120-
: fromISODateTimeUTC(asset.localDateTime),
121-
);
81+
$effect(() => {
82+
if (!previousId) {
83+
previousId = asset.id;
84+
}
85+
if (asset.id !== previousId) {
86+
showEditFaces = false;
87+
previousId = asset.id;
88+
}
89+
});
12290
12391
const getMegapixel = (width: number, height: number): number | undefined => {
12492
const megapixel = Math.round((height * width) / 1_000_000);
@@ -130,11 +98,24 @@
13098
return undefined;
13199
};
132100
101+
const refreshAsset = async () => {
102+
if (asset && !authManager.isSharedLink) {
103+
asset = await getAssetInfo({ id: asset.id });
104+
}
105+
};
106+
107+
const handleNewAsset = async (newAsset: AssetResponseDto) => {
108+
if (newAsset.id && newAsset.id !== asset.id) {
109+
await refreshAsset();
110+
}
111+
};
112+
113+
$effect(() => {
114+
handlePromiseError(handleNewAsset(asset));
115+
});
116+
133117
const handleRefreshPeople = async () => {
134-
await getAssetInfo({ id: asset.id }).then((data) => {
135-
people = data?.people || [];
136-
unassignedFaces = data?.unassignedFaces || [];
137-
});
118+
await refreshAsset();
138119
showEditFaces = false;
139120
};
140121

web/src/lib/utils/asset-utils.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
type AssetResponseDto,
3535
type AssetTypeEnum,
3636
type DownloadInfoDto,
37+
type ExifResponseDto,
3738
type StackResponseDto,
3839
type UserPreferencesResponseDto,
3940
type UserResponseDto,
@@ -328,6 +329,15 @@ export function isFlipped(orientation?: string | null) {
328329
return value && (isRotated270CW(value) || isRotated90CW(value));
329330
}
330331

332+
export const getDimensions = (exifInfo: ExifResponseDto) => {
333+
const { exifImageWidth: width, exifImageHeight: height } = exifInfo;
334+
if (isFlipped(exifInfo.orientation)) {
335+
return { width: height, height: width };
336+
}
337+
338+
return { width, height };
339+
};
340+
331341
export function getFileSize(asset: AssetResponseDto, maxPrecision = 4): string {
332342
const size = asset.exifInfo?.fileSizeInByte || 0;
333343
return size > 0 ? getByteUnitString(size, undefined, maxPrecision) : 'Invalid Data';

0 commit comments

Comments
 (0)