mirror of
https://github.com/immich-app/immich.git
synced 2025-06-03 05:34:32 -04:00
feat: add sort order
This commit is contained in:
parent
584a609966
commit
92ab0d4c82
@ -34,6 +34,7 @@ class PlacesCollectionPage extends HookConsumerWidget {
|
|||||||
final formFocus = useFocusNode();
|
final formFocus = useFocusNode();
|
||||||
final ValueNotifier<String?> search = useState(null);
|
final ValueNotifier<String?> search = useState(null);
|
||||||
final filterType = useState(FilterType.name);
|
final filterType = useState(FilterType.name);
|
||||||
|
final isAscending = useState(true); // Add state for sort order
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
@ -80,13 +81,13 @@ class PlacesCollectionPage extends HookConsumerWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (currentLocation != null)
|
Padding(
|
||||||
Padding(
|
padding: const EdgeInsets.symmetric(horizontal: 12.0),
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 12.0),
|
child: Row(
|
||||||
child: Row(
|
spacing: 8.0,
|
||||||
spacing: 8.0,
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
mainAxisAlignment: MainAxisAlignment.end,
|
children: [
|
||||||
children: [
|
if (currentLocation != null) ...[
|
||||||
Text('sort_places_by'.tr()),
|
Text('sort_places_by'.tr()),
|
||||||
Align(
|
Align(
|
||||||
alignment: Alignment.centerLeft,
|
alignment: Alignment.centerLeft,
|
||||||
@ -125,8 +126,17 @@ class PlacesCollectionPage extends HookConsumerWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
IconButton(
|
||||||
|
icon: const Icon(
|
||||||
|
Icons.swap_vert,
|
||||||
|
),
|
||||||
|
onPressed: () {
|
||||||
|
isAscending.value = !isAscending.value;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
places.when(
|
places.when(
|
||||||
data: (places) {
|
data: (places) {
|
||||||
@ -136,26 +146,41 @@ class PlacesCollectionPage extends HookConsumerWidget {
|
|||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
.contains(search.value!.toLowerCase());
|
.contains(search.value!.toLowerCase());
|
||||||
}).toList();
|
}).toList();
|
||||||
} else if (filterType.value == FilterType.distance &&
|
} else {
|
||||||
currentLocation != null) {
|
// Sort based on the selected filter type
|
||||||
// Sort places by distance when filterType is distance and search is null
|
|
||||||
places = List.from(places);
|
places = List.from(places);
|
||||||
places.sort((a, b) {
|
|
||||||
final double distanceA = calculateDistance(
|
|
||||||
currentLocation!.latitude,
|
|
||||||
currentLocation!.longitude,
|
|
||||||
a.latitude,
|
|
||||||
a.longitude,
|
|
||||||
);
|
|
||||||
final double distanceB = calculateDistance(
|
|
||||||
currentLocation!.latitude,
|
|
||||||
currentLocation!.longitude,
|
|
||||||
b.latitude,
|
|
||||||
b.longitude,
|
|
||||||
);
|
|
||||||
|
|
||||||
return distanceA.compareTo(distanceB);
|
if (filterType.value == FilterType.distance &&
|
||||||
});
|
currentLocation != null) {
|
||||||
|
// Sort places by distance
|
||||||
|
places.sort((a, b) {
|
||||||
|
final double distanceA = calculateDistance(
|
||||||
|
currentLocation!.latitude,
|
||||||
|
currentLocation!.longitude,
|
||||||
|
a.latitude,
|
||||||
|
a.longitude,
|
||||||
|
);
|
||||||
|
final double distanceB = calculateDistance(
|
||||||
|
currentLocation!.latitude,
|
||||||
|
currentLocation!.longitude,
|
||||||
|
b.latitude,
|
||||||
|
b.longitude,
|
||||||
|
);
|
||||||
|
|
||||||
|
return isAscending.value
|
||||||
|
? distanceA.compareTo(distanceB)
|
||||||
|
: distanceB.compareTo(distanceA);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Sort places by name
|
||||||
|
places.sort(
|
||||||
|
(a, b) => isAscending.value
|
||||||
|
? a.label.toLowerCase().compareTo(b.label.toLowerCase())
|
||||||
|
: b.label
|
||||||
|
.toLowerCase()
|
||||||
|
.compareTo(a.label.toLowerCase()),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return ListView.builder(
|
return ListView.builder(
|
||||||
shrinkWrap: true,
|
shrinkWrap: true,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user