2023-09-05 01:10:27 +02:00
|
|
|
import 'dart:math' as math;
|
2024-01-05 07:20:55 +02:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
2022-07-07 20:40:54 +02:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2022-02-27 20:45:12 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2023-03-23 03:36:44 +02:00
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart' hide Store;
|
2022-02-27 20:45:12 +02:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2023-11-29 06:17:29 +02:00
|
|
|
import 'package:immich_mobile/extensions/asyncvalue_extensions.dart';
|
2023-11-09 18:19:53 +02:00
|
|
|
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
2023-03-25 05:44:53 +02:00
|
|
|
import 'package:immich_mobile/modules/search/models/curated_content.dart';
|
2023-06-23 17:44:02 +02:00
|
|
|
import 'package:immich_mobile/modules/search/providers/people.provider.dart';
|
2022-02-27 20:45:12 +02:00
|
|
|
import 'package:immich_mobile/modules/search/providers/search_page_state.provider.dart';
|
2023-06-23 17:44:02 +02:00
|
|
|
import 'package:immich_mobile/modules/search/ui/curated_people_row.dart';
|
2023-08-27 07:07:35 +02:00
|
|
|
import 'package:immich_mobile/modules/search/ui/curated_places_row.dart';
|
2023-05-12 16:21:13 +02:00
|
|
|
import 'package:immich_mobile/modules/search/ui/immich_search_bar.dart';
|
2023-06-23 17:44:02 +02:00
|
|
|
import 'package:immich_mobile/modules/search/ui/person_name_edit_form.dart';
|
|
|
|
import 'package:immich_mobile/modules/search/ui/search_row_title.dart';
|
2022-02-27 20:45:12 +02:00
|
|
|
import 'package:immich_mobile/modules/search/ui/search_suggestion_list.dart';
|
2022-03-03 00:44:24 +02:00
|
|
|
import 'package:immich_mobile/routing/router.dart';
|
2023-09-28 05:26:48 +02:00
|
|
|
import 'package:immich_mobile/shared/providers/server_info.provider.dart';
|
2023-11-29 06:17:29 +02:00
|
|
|
import 'package:immich_mobile/shared/ui/scaffold_error_body.dart';
|
2022-02-27 20:45:12 +02:00
|
|
|
|
|
|
|
// ignore: must_be_immutable
|
|
|
|
class SearchPage extends HookConsumerWidget {
|
|
|
|
SearchPage({Key? key}) : super(key: key);
|
|
|
|
|
2022-06-25 20:46:51 +02:00
|
|
|
FocusNode searchFocusNode = FocusNode();
|
2022-02-27 20:45:12 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
|
|
final isSearchEnabled = ref.watch(searchPageStateProvider).isSearchEnabled;
|
2023-06-23 17:44:02 +02:00
|
|
|
final curatedLocation = ref.watch(getCuratedLocationProvider);
|
|
|
|
final curatedPeople = ref.watch(getCuratedPeopleProvider);
|
2023-09-28 05:26:48 +02:00
|
|
|
final isMapEnabled =
|
|
|
|
ref.watch(serverInfoProvider.select((v) => v.serverFeatures.map));
|
2023-11-09 18:19:53 +02:00
|
|
|
double imageSize = math.min(context.width / 3, 150);
|
2023-03-28 17:34:06 +02:00
|
|
|
|
2023-03-25 05:44:53 +02:00
|
|
|
TextStyle categoryTitleStyle = const TextStyle(
|
2023-11-20 16:58:03 +02:00
|
|
|
fontWeight: FontWeight.w500,
|
|
|
|
fontSize: 15.0,
|
2023-03-25 05:44:53 +02:00
|
|
|
);
|
|
|
|
|
2023-11-09 18:19:53 +02:00
|
|
|
Color categoryIconColor = context.isDarkTheme ? Colors.white : Colors.black;
|
2022-08-16 01:53:30 +02:00
|
|
|
|
2022-07-13 14:23:48 +02:00
|
|
|
useEffect(
|
|
|
|
() {
|
|
|
|
searchFocusNode = FocusNode();
|
|
|
|
return () => searchFocusNode.dispose();
|
|
|
|
},
|
|
|
|
[],
|
|
|
|
);
|
2022-02-27 20:45:12 +02:00
|
|
|
|
2022-11-21 14:13:14 +02:00
|
|
|
onSearchSubmitted(String searchTerm) async {
|
2022-03-03 00:44:24 +02:00
|
|
|
searchFocusNode.unfocus();
|
|
|
|
ref.watch(searchPageStateProvider.notifier).disableSearch();
|
|
|
|
|
2024-01-05 07:20:55 +02:00
|
|
|
context.pushRoute(
|
2023-03-28 17:34:06 +02:00
|
|
|
SearchResultRoute(
|
|
|
|
searchTerm: searchTerm,
|
|
|
|
),
|
|
|
|
);
|
2022-03-03 00:44:24 +02:00
|
|
|
}
|
|
|
|
|
2023-06-23 17:44:02 +02:00
|
|
|
showNameEditModel(
|
|
|
|
String personId,
|
|
|
|
String personName,
|
|
|
|
) {
|
|
|
|
return showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return PersonNameEditForm(personId: personId, personName: personName);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
buildPeople() {
|
|
|
|
return SizedBox(
|
2023-08-27 07:07:35 +02:00
|
|
|
height: imageSize,
|
2023-11-29 06:17:29 +02:00
|
|
|
child: curatedPeople.widgetWhen(
|
|
|
|
onError: (error, stack) => const ScaffoldErrorBody(withIcon: false),
|
|
|
|
onData: (people) => CuratedPeopleRow(
|
2023-11-19 18:04:44 +02:00
|
|
|
content: people.take(12).toList(),
|
2023-06-23 17:44:02 +02:00
|
|
|
onTap: (content, index) {
|
2024-01-05 07:20:55 +02:00
|
|
|
context.pushRoute(
|
2023-06-23 17:44:02 +02:00
|
|
|
PersonResultRoute(
|
|
|
|
personId: content.id,
|
|
|
|
personName: content.label,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
onNameTap: (person, index) => {
|
|
|
|
showNameEditModel(person.id, person.label),
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-11-21 14:13:14 +02:00
|
|
|
buildPlaces() {
|
2023-03-23 17:08:14 +02:00
|
|
|
return SizedBox(
|
|
|
|
height: imageSize,
|
2023-11-29 06:17:29 +02:00
|
|
|
child: curatedLocation.widgetWhen(
|
|
|
|
onError: (error, stack) => const ScaffoldErrorBody(withIcon: false),
|
|
|
|
onData: (locations) => CuratedPlacesRow(
|
2023-09-28 05:26:48 +02:00
|
|
|
isMapEnabled: isMapEnabled,
|
2023-03-25 05:44:53 +02:00
|
|
|
content: locations
|
|
|
|
.map(
|
|
|
|
(o) => CuratedContent(
|
|
|
|
id: o.id,
|
|
|
|
label: o.city,
|
2022-03-16 17:19:31 +02:00
|
|
|
),
|
2023-03-25 05:44:53 +02:00
|
|
|
)
|
|
|
|
.toList(),
|
|
|
|
imageSize: imageSize,
|
|
|
|
onTap: (content, index) {
|
2024-01-05 07:20:55 +02:00
|
|
|
context.pushRoute(
|
2023-03-28 17:34:06 +02:00
|
|
|
SearchResultRoute(
|
|
|
|
searchTerm: 'm:${content.label}',
|
|
|
|
),
|
2023-03-23 17:08:14 +02:00
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-02-27 20:45:12 +02:00
|
|
|
return Scaffold(
|
2023-05-12 16:21:13 +02:00
|
|
|
appBar: ImmichSearchBar(
|
2022-03-03 00:44:24 +02:00
|
|
|
searchFocusNode: searchFocusNode,
|
2022-11-21 14:13:14 +02:00
|
|
|
onSubmitted: onSearchSubmitted,
|
2022-03-03 00:44:24 +02:00
|
|
|
),
|
2022-02-27 20:45:12 +02:00
|
|
|
body: GestureDetector(
|
|
|
|
onTap: () {
|
|
|
|
searchFocusNode.unfocus();
|
|
|
|
ref.watch(searchPageStateProvider.notifier).disableSearch();
|
|
|
|
},
|
|
|
|
child: Stack(
|
|
|
|
children: [
|
|
|
|
ListView(
|
2022-03-16 17:19:31 +02:00
|
|
|
children: [
|
2023-06-23 17:44:02 +02:00
|
|
|
SearchRowTitle(
|
|
|
|
title: "search_page_people".tr(),
|
2023-11-09 18:19:53 +02:00
|
|
|
onViewAllPressed: () =>
|
2024-01-05 07:20:55 +02:00
|
|
|
context.pushRoute(const AllPeopleRoute()),
|
2023-06-23 17:44:02 +02:00
|
|
|
),
|
|
|
|
buildPeople(),
|
|
|
|
SearchRowTitle(
|
|
|
|
title: "search_page_places".tr(),
|
2023-11-09 18:19:53 +02:00
|
|
|
onViewAllPressed: () =>
|
2024-01-05 07:20:55 +02:00
|
|
|
context.pushRoute(const CuratedLocationRoute()),
|
2023-06-23 17:44:02 +02:00
|
|
|
top: 0,
|
2022-03-16 17:19:31 +02:00
|
|
|
),
|
2023-08-27 07:07:35 +02:00
|
|
|
const SizedBox(height: 10.0),
|
2022-11-21 14:13:14 +02:00
|
|
|
buildPlaces(),
|
2023-03-25 05:44:53 +02:00
|
|
|
const SizedBox(height: 24.0),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
|
|
child: Text(
|
|
|
|
'search_page_your_activity',
|
2023-11-20 16:58:03 +02:00
|
|
|
style: context.textTheme.bodyLarge?.copyWith(
|
|
|
|
fontWeight: FontWeight.w500,
|
|
|
|
),
|
2023-03-25 05:44:53 +02:00
|
|
|
).tr(),
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
leading: Icon(
|
2023-11-06 17:46:26 +02:00
|
|
|
Icons.favorite_border_rounded,
|
2023-03-25 05:44:53 +02:00
|
|
|
color: categoryIconColor,
|
|
|
|
),
|
|
|
|
title:
|
|
|
|
Text('search_page_favorites', style: categoryTitleStyle)
|
|
|
|
.tr(),
|
2024-01-05 07:20:55 +02:00
|
|
|
onTap: () => context.pushRoute(const FavoritesRoute()),
|
2023-03-25 05:44:53 +02:00
|
|
|
),
|
2023-03-28 17:34:06 +02:00
|
|
|
const CategoryDivider(),
|
2023-03-25 05:44:53 +02:00
|
|
|
ListTile(
|
|
|
|
leading: Icon(
|
|
|
|
Icons.schedule_outlined,
|
|
|
|
color: categoryIconColor,
|
|
|
|
),
|
|
|
|
title: Text(
|
|
|
|
'search_page_recently_added',
|
|
|
|
style: categoryTitleStyle,
|
|
|
|
).tr(),
|
2024-01-05 07:20:55 +02:00
|
|
|
onTap: () => context.pushRoute(const RecentlyAddedRoute()),
|
2023-03-25 05:44:53 +02:00
|
|
|
),
|
|
|
|
const SizedBox(height: 24.0),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
|
|
|
child: Text(
|
|
|
|
'search_page_categories',
|
2023-11-20 16:58:03 +02:00
|
|
|
style: context.textTheme.bodyLarge?.copyWith(
|
|
|
|
fontWeight: FontWeight.w500,
|
|
|
|
),
|
2023-03-25 05:44:53 +02:00
|
|
|
).tr(),
|
|
|
|
),
|
2023-03-28 17:34:06 +02:00
|
|
|
ListTile(
|
2023-11-20 16:58:03 +02:00
|
|
|
title:
|
|
|
|
Text('search_page_screenshots', style: categoryTitleStyle)
|
|
|
|
.tr(),
|
2023-03-28 17:34:06 +02:00
|
|
|
leading: Icon(
|
|
|
|
Icons.screenshot,
|
|
|
|
color: categoryIconColor,
|
|
|
|
),
|
2024-01-05 07:20:55 +02:00
|
|
|
onTap: () => context.pushRoute(
|
2023-03-28 17:34:06 +02:00
|
|
|
SearchResultRoute(
|
|
|
|
searchTerm: 'screenshots',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const CategoryDivider(),
|
|
|
|
ListTile(
|
|
|
|
title: Text('search_page_selfies', style: categoryTitleStyle)
|
|
|
|
.tr(),
|
|
|
|
leading: Icon(
|
|
|
|
Icons.photo_camera_front_outlined,
|
|
|
|
color: categoryIconColor,
|
|
|
|
),
|
2024-01-05 07:20:55 +02:00
|
|
|
onTap: () => context.pushRoute(
|
2023-03-28 17:34:06 +02:00
|
|
|
SearchResultRoute(
|
|
|
|
searchTerm: 'selfies',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const CategoryDivider(),
|
2023-03-25 05:44:53 +02:00
|
|
|
ListTile(
|
|
|
|
title: Text('search_page_videos', style: categoryTitleStyle)
|
|
|
|
.tr(),
|
|
|
|
leading: Icon(
|
|
|
|
Icons.play_circle_outline,
|
|
|
|
color: categoryIconColor,
|
|
|
|
),
|
2024-01-05 07:20:55 +02:00
|
|
|
onTap: () => context.pushRoute(const AllVideosRoute()),
|
2023-03-25 05:44:53 +02:00
|
|
|
),
|
2023-03-28 17:34:06 +02:00
|
|
|
const CategoryDivider(),
|
2023-03-25 05:44:53 +02:00
|
|
|
ListTile(
|
|
|
|
title: Text(
|
|
|
|
'search_page_motion_photos',
|
|
|
|
style: categoryTitleStyle,
|
|
|
|
).tr(),
|
|
|
|
leading: Icon(
|
|
|
|
Icons.motion_photos_on_outlined,
|
|
|
|
color: categoryIconColor,
|
|
|
|
),
|
2024-01-05 07:20:55 +02:00
|
|
|
onTap: () => context.pushRoute(const AllMotionPhotosRoute()),
|
2023-03-25 05:44:53 +02:00
|
|
|
),
|
2022-03-16 17:19:31 +02:00
|
|
|
],
|
2022-02-27 20:45:12 +02:00
|
|
|
),
|
2022-07-01 03:08:49 +02:00
|
|
|
if (isSearchEnabled)
|
2022-11-21 14:13:14 +02:00
|
|
|
SearchSuggestionList(onSubmitted: onSearchSubmitted),
|
2022-02-27 20:45:12 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2023-03-28 17:34:06 +02:00
|
|
|
|
|
|
|
class CategoryDivider extends StatelessWidget {
|
|
|
|
const CategoryDivider({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return const Padding(
|
|
|
|
padding: EdgeInsets.only(
|
2023-11-20 16:58:03 +02:00
|
|
|
left: 56,
|
2023-03-28 17:34:06 +02:00
|
|
|
right: 16,
|
|
|
|
),
|
|
|
|
child: Divider(
|
|
|
|
height: 0,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|