From 17632a07e8641a9cc8d63529bdac08fd9db8a223 Mon Sep 17 00:00:00 2001 From: Prateek Sunal Date: Sat, 26 Jul 2025 15:07:04 +0530 Subject: [PATCH] fix: sort checked first --- .../result/people_section_all_page.dart | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/mobile/apps/photos/lib/ui/viewer/search/result/people_section_all_page.dart b/mobile/apps/photos/lib/ui/viewer/search/result/people_section_all_page.dart index d711bd9ebd..796c3513b2 100644 --- a/mobile/apps/photos/lib/ui/viewer/search/result/people_section_all_page.dart +++ b/mobile/apps/photos/lib/ui/viewer/search/result/people_section_all_page.dart @@ -357,7 +357,7 @@ class _PeopleSectionAllWidgetState extends State { @override void initState() { super.initState(); - sectionData = getResults(); + sectionData = getResults(init: true); final streamsToListenTo = SectionType.face.viewAllUpdateEvents(); for (Stream stream in streamsToListenTo) { @@ -386,7 +386,7 @@ class _PeopleSectionAllWidgetState extends State { } } - Future> getResults() async { + Future> getResults({bool init = false}) async { final allFaces = await SearchService.instance .getAllFace(null, minClusterSize: kMinimumClusterSizeAllFaces); normalFaces.clear(); @@ -410,6 +410,21 @@ class _PeopleSectionAllWidgetState extends State { results.removeWhere( (element) => element.params[kPersonParamID] == null, ); + + if (init) { + // sort widget.selectedPeople first + results.sort((a, b) { + final aIndex = widget.selectedPeople?.personIds + .contains(a.params[kPersonParamID]) ?? + false; + final bIndex = widget.selectedPeople?.personIds + .contains(b.params[kPersonParamID]) ?? + false; + if (aIndex && !bIndex) return -1; + if (!aIndex && bIndex) return 1; + return a.name().compareTo(b.name()); + }); + } } _isLoaded = true; return results;