[mob][photos] Don't remove last cluster of person

This commit is contained in:
laurenspriem 2024-05-27 14:55:52 +05:30
parent 9f361237b1
commit ced1f0bd79

View file

@ -38,12 +38,17 @@ class _PersonClustersPageState extends State<PersonClustersPage> {
.getClusterFilesForPersonID(widget.person.remoteID),
builder: (context, snapshot) {
if (snapshot.hasData) {
final List<int> keys = snapshot.data!.keys.toList();
final clusters = snapshot.data!;
final List<int> keys = clusters.keys.toList();
// Sort the clusters by the number of files in each cluster, largest first
keys.sort(
(b, a) => clusters[a]!.length.compareTo(clusters[b]!.length),
);
return ListView.builder(
itemCount: keys.length,
itemBuilder: (context, index) {
final int clusterID = keys[index];
final List<EnteFile> files = snapshot.data![keys[index]]!;
final List<EnteFile> files = clusters[clusterID]!;
return InkWell(
onTap: () {
Navigator.of(context).push(
@ -93,34 +98,37 @@ class _PersonClustersPageState extends State<PersonClustersPage> {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
"${snapshot.data![keys[index]]!.length} photos",
"${files.length} photos",
style: getEnteTextTheme(context).body,
),
GestureDetector(
onTap: () async {
try {
await PersonService.instance
.removeClusterToPerson(
personID: widget.person.remoteID,
clusterID: clusterID,
);
_logger.info(
"Removed cluster $clusterID from person ${widget.person.remoteID}",
);
Bus.instance.fire(PeopleChangedEvent());
setState(() {});
} catch (e) {
_logger.severe(
"removing cluster from person,",
e,
);
}
},
child: const Icon(
CupertinoIcons.minus_circled,
color: Colors.red,
),
),
(index != 0)
? GestureDetector(
onTap: () async {
try {
await PersonService.instance
.removeClusterToPerson(
personID: widget.person.remoteID,
clusterID: clusterID,
);
_logger.info(
"Removed cluster $clusterID from person ${widget.person.remoteID}",
);
Bus.instance
.fire(PeopleChangedEvent());
setState(() {});
} catch (e) {
_logger.severe(
"removing cluster from person,",
e,
);
}
},
child: const Icon(
CupertinoIcons.minus_circled,
color: Colors.red,
),
)
: const SizedBox.shrink(),
],
),
),