From b49b10141e2f9128bd8e4dc156db69b665f26c85 Mon Sep 17 00:00:00 2001 From: shenlong <139912620+shenlong-tanwen@users.noreply.github.com> Date: Thu, 26 Oct 2023 14:19:06 +0000 Subject: [PATCH] fix(mobile): stack count reset when navigating to library (#4647) Co-authored-by: shalong-tanwen <139912620+shalong-tanwen@users.noreply.github.com> --- cli/src/api/open-api/api.ts | 2 +- .../asset_viewer/views/gallery_viewer.dart | 2 +- .../home/ui/asset_grid/thumbnail_image.dart | 8 ++++---- mobile/lib/shared/models/asset.dart | 14 +++++++++++--- mobile/lib/shared/models/asset.g.dart | Bin 82576 -> 83086 bytes .../openapi/lib/model/asset_response_dto.dart | Bin 12759 -> 12875 bytes server/immich-openapi-specs.json | 1 + .../asset/response-dto/asset-response.dto.ts | 4 ++-- web/src/api/open-api/api.ts | 2 +- 9 files changed, 21 insertions(+), 12 deletions(-) diff --git a/cli/src/api/open-api/api.ts b/cli/src/api/open-api/api.ts index caab7f4b83..688fc7a488 100644 --- a/cli/src/api/open-api/api.ts +++ b/cli/src/api/open-api/api.ts @@ -771,7 +771,7 @@ export interface AssetResponseDto { * @type {number} * @memberof AssetResponseDto */ - 'stackCount': number; + 'stackCount': number | null; /** * * @type {string} diff --git a/mobile/lib/modules/asset_viewer/views/gallery_viewer.dart b/mobile/lib/modules/asset_viewer/views/gallery_viewer.dart index b546aa76da..acb7c6a642 100644 --- a/mobile/lib/modules/asset_viewer/views/gallery_viewer.dart +++ b/mobile/lib/modules/asset_viewer/views/gallery_viewer.dart @@ -83,7 +83,7 @@ class GalleryViewerPage extends HookConsumerWidget { navStack.length > 2 && navStack.elementAt(navStack.length - 2).name == TrashRoute.name; final stackIndex = useState(-1); - final stack = showStack && currentAsset.stackCount > 0 + final stack = showStack && currentAsset.stackChildrenCount > 0 ? ref.watch(assetStackStateProvider(currentAsset)) : []; final stackElements = showStack ? [currentAsset, ...stack] : []; diff --git a/mobile/lib/modules/home/ui/asset_grid/thumbnail_image.dart b/mobile/lib/modules/home/ui/asset_grid/thumbnail_image.dart index c983188873..2dc558a127 100644 --- a/mobile/lib/modules/home/ui/asset_grid/thumbnail_image.dart +++ b/mobile/lib/modules/home/ui/asset_grid/thumbnail_image.dart @@ -104,16 +104,16 @@ class ThumbnailImage extends StatelessWidget { right: 5, child: Row( children: [ - if (asset.stackCount > 1) + if (asset.stackChildrenCount > 1) Text( - "${asset.stackCount}", + "${asset.stackChildrenCount}", style: const TextStyle( color: Colors.white, fontSize: 10, fontWeight: FontWeight.bold, ), ), - if (asset.stackCount > 1) + if (asset.stackChildrenCount > 1) const SizedBox( width: 3, ), @@ -233,7 +233,7 @@ class ThumbnailImage extends StatelessWidget { ), ), if (!asset.isImage) buildVideoIcon(), - if (asset.isImage && asset.stackCount > 0) buildStackIcon(), + if (asset.isImage && asset.stackChildrenCount > 0) buildStackIcon(), ], ), ); diff --git a/mobile/lib/shared/models/asset.dart b/mobile/lib/shared/models/asset.dart index 66f2cc9f37..e1a3f24cd1 100644 --- a/mobile/lib/shared/models/asset.dart +++ b/mobile/lib/shared/models/asset.dart @@ -153,7 +153,10 @@ class Asset { String? stackParentId; - int stackCount; + @ignore + int get stackChildrenCount => stackCount ?? 0; + + int? stackCount; /// `true` if this [Asset] is present on the device @ignore @@ -253,7 +256,11 @@ class Asset { isFavorite != a.isFavorite || isArchived != a.isArchived || isTrashed != a.isTrashed || - stackCount != a.stackCount; + // no local stack count or different count from remote + ((stackCount == null && a.stackCount != null) || + (stackCount != null && + a.stackCount != null && + stackCount != a.stackCount)); } /// Returns a new [Asset] with values from this and merged & updated with [a] @@ -269,6 +276,7 @@ class Asset { width: a.width ?? width, height: a.height ?? height, exifInfo: a.exifInfo?.copyWith(id: id) ?? exifInfo, + stackCount: a.stackCount ?? stackCount, ); } else if (isRemote) { return _copyWith( @@ -299,7 +307,7 @@ class Asset { height: a.height, livePhotoVideoId: a.livePhotoVideoId, stackParentId: a.stackParentId, - stackCount: a.stackCount, + stackCount: a.stackCount ?? stackCount, // isFavorite + isArchived are not set by device-only assets isFavorite: a.isFavorite, isArchived: a.isArchived, diff --git a/mobile/lib/shared/models/asset.g.dart b/mobile/lib/shared/models/asset.g.dart index 4f485dfb024b0656b4c0d2f3bbd7c04990b688aa..f589ba0c6789ee628214785663f2d07f2cfb07c2 100644 GIT binary patch delta 141 zcmbQx%G%e-x7P!cYBKH5J5TpHO!BgUllcm~EL!|{K+iZ=ToNz{Zvi|!MC}JDVN=;tZc^@RU VdCj?&g6aPq8AZ3d*faVt0{~-fKkEPh delta 111 zcmeC{WS!8;x~Iqh$+JeA#)A& diff --git a/server/immich-openapi-specs.json b/server/immich-openapi-specs.json index f9164a265e..58e0e3055a 100644 --- a/server/immich-openapi-specs.json +++ b/server/immich-openapi-specs.json @@ -6009,6 +6009,7 @@ "type": "array" }, "stackCount": { + "nullable": true, "type": "integer" }, "stackParentId": { diff --git a/server/src/domain/asset/response-dto/asset-response.dto.ts b/server/src/domain/asset/response-dto/asset-response.dto.ts index 1c8d5ba34d..0f5e013202 100644 --- a/server/src/domain/asset/response-dto/asset-response.dto.ts +++ b/server/src/domain/asset/response-dto/asset-response.dto.ts @@ -45,7 +45,7 @@ export class AssetResponseDto extends SanitizedAssetResponseDto { stackParentId?: string | null; stack?: AssetResponseDto[]; @ApiProperty({ type: 'integer' }) - stackCount!: number; + stackCount!: number | null; } export type AssetMapOptions = { @@ -102,7 +102,7 @@ export function mapAsset(entity: AssetEntity, options: AssetMapOptions = {}): As checksum: entity.checksum.toString('base64'), stackParentId: entity.stackParentId, stack: withStack ? entity.stack?.map((a) => mapAsset(a, { stripMetadata })) ?? undefined : undefined, - stackCount: entity.stack?.length ?? 0, + stackCount: entity.stack?.length ?? null, isExternal: entity.isExternal, isOffline: entity.isOffline, isReadOnly: entity.isReadOnly, diff --git a/web/src/api/open-api/api.ts b/web/src/api/open-api/api.ts index caab7f4b83..688fc7a488 100644 --- a/web/src/api/open-api/api.ts +++ b/web/src/api/open-api/api.ts @@ -771,7 +771,7 @@ export interface AssetResponseDto { * @type {number} * @memberof AssetResponseDto */ - 'stackCount': number; + 'stackCount': number | null; /** * * @type {string}