2022-03-02 15:44:24 -07:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
2022-07-07 11:40:54 -07:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2022-02-27 11:45:12 -07:00
|
|
|
import 'package:flutter/material.dart';
|
2023-03-22 18:36:44 -07:00
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart' hide Store;
|
2022-02-27 11:45:12 -07:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2023-03-24 20:44:53 -07:00
|
|
|
import 'package:immich_mobile/modules/search/models/curated_content.dart';
|
2022-02-27 11:45:12 -07:00
|
|
|
import 'package:immich_mobile/modules/search/providers/search_page_state.provider.dart';
|
2023-03-24 20:44:53 -07:00
|
|
|
import 'package:immich_mobile/modules/search/ui/curated_row.dart';
|
2023-05-12 07:21:13 -07:00
|
|
|
import 'package:immich_mobile/modules/search/ui/immich_search_bar.dart';
|
2022-02-27 11:45:12 -07:00
|
|
|
import 'package:immich_mobile/modules/search/ui/search_suggestion_list.dart';
|
2022-03-02 15:44:24 -07:00
|
|
|
import 'package:immich_mobile/routing/router.dart';
|
2022-04-23 19:08:45 -07:00
|
|
|
import 'package:immich_mobile/shared/ui/immich_loading_indicator.dart';
|
2022-07-13 05:23:48 -07:00
|
|
|
import 'package:openapi/api.dart';
|
2022-02-27 11:45:12 -07:00
|
|
|
|
|
|
|
// ignore: must_be_immutable
|
|
|
|
class SearchPage extends HookConsumerWidget {
|
|
|
|
SearchPage({Key? key}) : super(key: key);
|
|
|
|
|
2022-06-25 11:46:51 -07:00
|
|
|
FocusNode searchFocusNode = FocusNode();
|
2022-02-27 11:45:12 -07:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
|
|
final isSearchEnabled = ref.watch(searchPageStateProvider).isSearchEnabled;
|
2022-07-13 05:23:48 -07:00
|
|
|
AsyncValue<List<CuratedLocationsResponseDto>> curatedLocation =
|
2022-04-23 19:08:45 -07:00
|
|
|
ref.watch(getCuratedLocationProvider);
|
2022-07-13 05:23:48 -07:00
|
|
|
AsyncValue<List<CuratedObjectsResponseDto>> curatedObjects =
|
2022-04-23 19:08:45 -07:00
|
|
|
ref.watch(getCuratedObjectProvider);
|
2023-03-24 20:44:53 -07:00
|
|
|
var isDarkTheme = Theme.of(context).brightness == Brightness.dark;
|
2022-08-15 16:53:30 -07:00
|
|
|
double imageSize = MediaQuery.of(context).size.width / 3;
|
2023-03-28 08:34:06 -07:00
|
|
|
|
2023-03-24 20:44:53 -07:00
|
|
|
TextStyle categoryTitleStyle = const TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
fontSize: 14.0,
|
|
|
|
);
|
|
|
|
|
|
|
|
Color categoryIconColor = isDarkTheme ? Colors.white : Colors.black;
|
2022-08-15 16:53:30 -07:00
|
|
|
|
2022-07-13 05:23:48 -07:00
|
|
|
useEffect(
|
|
|
|
() {
|
|
|
|
searchFocusNode = FocusNode();
|
|
|
|
return () => searchFocusNode.dispose();
|
|
|
|
},
|
|
|
|
[],
|
|
|
|
);
|
2022-02-27 11:45:12 -07:00
|
|
|
|
2022-11-21 05:13:14 -07:00
|
|
|
onSearchSubmitted(String searchTerm) async {
|
2022-03-02 15:44:24 -07:00
|
|
|
searchFocusNode.unfocus();
|
|
|
|
ref.watch(searchPageStateProvider.notifier).disableSearch();
|
|
|
|
|
2023-03-28 08:34:06 -07:00
|
|
|
AutoRouter.of(context).push(
|
|
|
|
SearchResultRoute(
|
|
|
|
searchTerm: searchTerm,
|
|
|
|
),
|
|
|
|
);
|
2022-03-02 15:44:24 -07:00
|
|
|
}
|
|
|
|
|
2022-11-21 05:13:14 -07:00
|
|
|
buildPlaces() {
|
2023-03-23 08:08:14 -07:00
|
|
|
return SizedBox(
|
|
|
|
height: imageSize,
|
|
|
|
child: curatedLocation.when(
|
|
|
|
loading: () => const Center(child: ImmichLoadingIndicator()),
|
|
|
|
error: (err, stack) => Center(child: Text('Error: $err')),
|
2023-03-24 20:44:53 -07:00
|
|
|
data: (locations) => CuratedRow(
|
|
|
|
content: locations
|
|
|
|
.map(
|
|
|
|
(o) => CuratedContent(
|
|
|
|
id: o.id,
|
|
|
|
label: o.city,
|
2022-03-16 08:19:31 -07:00
|
|
|
),
|
2023-03-24 20:44:53 -07:00
|
|
|
)
|
|
|
|
.toList(),
|
|
|
|
imageSize: imageSize,
|
|
|
|
onTap: (content, index) {
|
|
|
|
AutoRouter.of(context).push(
|
2023-03-28 08:34:06 -07:00
|
|
|
SearchResultRoute(
|
|
|
|
searchTerm: 'm:${content.label}',
|
|
|
|
),
|
2023-03-23 08:08:14 -07:00
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-03-24 20:44:53 -07:00
|
|
|
buildThings() {
|
|
|
|
return SizedBox(
|
|
|
|
height: imageSize,
|
|
|
|
child: curatedObjects.when(
|
|
|
|
loading: () => SizedBox(
|
2023-03-23 08:08:14 -07:00
|
|
|
height: imageSize,
|
2023-03-24 20:44:53 -07:00
|
|
|
child: const Center(child: ImmichLoadingIndicator()),
|
|
|
|
),
|
|
|
|
error: (err, stack) => SizedBox(
|
|
|
|
height: imageSize,
|
|
|
|
child: Center(child: Text('Error: $err')),
|
|
|
|
),
|
|
|
|
data: (objects) => CuratedRow(
|
|
|
|
content: objects
|
|
|
|
.map(
|
|
|
|
(o) => CuratedContent(
|
|
|
|
id: o.id,
|
|
|
|
label: o.object,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.toList(),
|
|
|
|
imageSize: imageSize,
|
|
|
|
onTap: (content, index) {
|
|
|
|
AutoRouter.of(context).push(
|
2023-03-28 08:34:06 -07:00
|
|
|
SearchResultRoute(
|
|
|
|
searchTerm: 'm:${content.label}',
|
|
|
|
),
|
2023-03-24 20:44:53 -07:00
|
|
|
);
|
|
|
|
},
|
2023-03-23 08:08:14 -07:00
|
|
|
),
|
|
|
|
),
|
2022-03-16 08:19:31 -07:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-02-27 11:45:12 -07:00
|
|
|
return Scaffold(
|
2023-05-12 07:21:13 -07:00
|
|
|
appBar: ImmichSearchBar(
|
2022-03-02 15:44:24 -07:00
|
|
|
searchFocusNode: searchFocusNode,
|
2022-11-21 05:13:14 -07:00
|
|
|
onSubmitted: onSearchSubmitted,
|
2022-03-02 15:44:24 -07:00
|
|
|
),
|
2022-02-27 11:45:12 -07:00
|
|
|
body: GestureDetector(
|
|
|
|
onTap: () {
|
|
|
|
searchFocusNode.unfocus();
|
|
|
|
ref.watch(searchPageStateProvider.notifier).disableSearch();
|
|
|
|
},
|
|
|
|
child: Stack(
|
|
|
|
children: [
|
|
|
|
ListView(
|
2022-03-16 08:19:31 -07:00
|
|
|
children: [
|
2022-07-07 11:40:54 -07:00
|
|
|
Padding(
|
2023-03-23 08:08:14 -07:00
|
|
|
padding: const EdgeInsets.symmetric(
|
|
|
|
horizontal: 16.0,
|
|
|
|
vertical: 4.0,
|
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
2023-03-24 20:44:53 -07:00
|
|
|
Text(
|
2023-03-23 08:08:14 -07:00
|
|
|
"search_page_places",
|
2023-03-28 08:34:06 -07:00
|
|
|
style: Theme.of(context).textTheme.titleSmall,
|
2023-03-23 08:08:14 -07:00
|
|
|
).tr(),
|
|
|
|
TextButton(
|
|
|
|
child: Text(
|
|
|
|
'search_page_view_all_button',
|
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
fontSize: 14.0,
|
|
|
|
),
|
|
|
|
).tr(),
|
|
|
|
onPressed: () => AutoRouter.of(context).push(
|
|
|
|
const CuratedLocationRoute(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2022-03-16 08:19:31 -07:00
|
|
|
),
|
2022-11-21 05:13:14 -07:00
|
|
|
buildPlaces(),
|
2022-07-07 11:40:54 -07:00
|
|
|
Padding(
|
2023-03-24 20:44:53 -07:00
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
top: 24.0,
|
|
|
|
bottom: 4.0,
|
|
|
|
left: 16.0,
|
|
|
|
right: 16.0,
|
2023-03-23 08:08:14 -07:00
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
2023-03-24 20:44:53 -07:00
|
|
|
Text(
|
2023-03-23 08:08:14 -07:00
|
|
|
"search_page_things",
|
2023-03-28 08:34:06 -07:00
|
|
|
style: Theme.of(context).textTheme.titleSmall,
|
2023-03-23 08:08:14 -07:00
|
|
|
).tr(),
|
|
|
|
TextButton(
|
|
|
|
child: Text(
|
|
|
|
'search_page_view_all_button',
|
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
fontSize: 14.0,
|
|
|
|
),
|
|
|
|
).tr(),
|
|
|
|
onPressed: () => AutoRouter.of(context).push(
|
|
|
|
const CuratedObjectRoute(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2022-03-27 12:58:54 -07:00
|
|
|
),
|
2023-03-23 08:08:14 -07:00
|
|
|
buildThings(),
|
2023-03-24 20:44:53 -07:00
|
|
|
const SizedBox(height: 24.0),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
|
|
child: Text(
|
|
|
|
'search_page_your_activity',
|
2023-03-28 08:34:06 -07:00
|
|
|
style: Theme.of(context).textTheme.titleSmall,
|
2023-03-24 20:44:53 -07:00
|
|
|
).tr(),
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
leading: Icon(
|
2023-05-08 12:01:39 -07:00
|
|
|
Icons.favorite_border,
|
2023-03-24 20:44:53 -07:00
|
|
|
color: categoryIconColor,
|
|
|
|
),
|
|
|
|
title:
|
|
|
|
Text('search_page_favorites', style: categoryTitleStyle)
|
|
|
|
.tr(),
|
|
|
|
onTap: () => AutoRouter.of(context).push(
|
|
|
|
const FavoritesRoute(),
|
|
|
|
),
|
|
|
|
),
|
2023-03-28 08:34:06 -07:00
|
|
|
const CategoryDivider(),
|
2023-03-24 20:44:53 -07:00
|
|
|
ListTile(
|
|
|
|
leading: Icon(
|
|
|
|
Icons.schedule_outlined,
|
|
|
|
color: categoryIconColor,
|
|
|
|
),
|
|
|
|
title: Text(
|
|
|
|
'search_page_recently_added',
|
|
|
|
style: categoryTitleStyle,
|
|
|
|
).tr(),
|
|
|
|
onTap: () => AutoRouter.of(context).push(
|
|
|
|
const RecentlyAddedRoute(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(height: 24.0),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
|
|
|
child: Text(
|
|
|
|
'search_page_categories',
|
2023-03-28 08:34:06 -07:00
|
|
|
style: Theme.of(context).textTheme.titleSmall,
|
2023-03-24 20:44:53 -07:00
|
|
|
).tr(),
|
|
|
|
),
|
2023-03-28 08:34:06 -07:00
|
|
|
ListTile(
|
|
|
|
title: Text('Screenshots', style: categoryTitleStyle).tr(),
|
|
|
|
leading: Icon(
|
|
|
|
Icons.screenshot,
|
|
|
|
color: categoryIconColor,
|
|
|
|
),
|
|
|
|
onTap: () => AutoRouter.of(context).push(
|
|
|
|
SearchResultRoute(
|
|
|
|
searchTerm: 'screenshots',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const CategoryDivider(),
|
|
|
|
ListTile(
|
|
|
|
title: Text('search_page_selfies', style: categoryTitleStyle)
|
|
|
|
.tr(),
|
|
|
|
leading: Icon(
|
|
|
|
Icons.photo_camera_front_outlined,
|
|
|
|
color: categoryIconColor,
|
|
|
|
),
|
|
|
|
onTap: () => AutoRouter.of(context).push(
|
|
|
|
SearchResultRoute(
|
|
|
|
searchTerm: 'selfies',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const CategoryDivider(),
|
2023-03-24 20:44:53 -07:00
|
|
|
ListTile(
|
|
|
|
title: Text('search_page_videos', style: categoryTitleStyle)
|
|
|
|
.tr(),
|
|
|
|
leading: Icon(
|
|
|
|
Icons.play_circle_outline,
|
|
|
|
color: categoryIconColor,
|
|
|
|
),
|
|
|
|
onTap: () => AutoRouter.of(context).push(
|
|
|
|
const AllVideosRoute(),
|
|
|
|
),
|
|
|
|
),
|
2023-03-28 08:34:06 -07:00
|
|
|
const CategoryDivider(),
|
2023-03-24 20:44:53 -07:00
|
|
|
ListTile(
|
|
|
|
title: Text(
|
|
|
|
'search_page_motion_photos',
|
|
|
|
style: categoryTitleStyle,
|
|
|
|
).tr(),
|
|
|
|
leading: Icon(
|
|
|
|
Icons.motion_photos_on_outlined,
|
|
|
|
color: categoryIconColor,
|
|
|
|
),
|
|
|
|
onTap: () => AutoRouter.of(context).push(
|
|
|
|
const AllMotionPhotosRoute(),
|
|
|
|
),
|
|
|
|
),
|
2022-03-16 08:19:31 -07:00
|
|
|
],
|
2022-02-27 11:45:12 -07:00
|
|
|
),
|
2022-06-30 18:08:49 -07:00
|
|
|
if (isSearchEnabled)
|
2022-11-21 05:13:14 -07:00
|
|
|
SearchSuggestionList(onSubmitted: onSearchSubmitted),
|
2022-02-27 11:45:12 -07:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2023-03-28 08:34:06 -07:00
|
|
|
|
|
|
|
class CategoryDivider extends StatelessWidget {
|
|
|
|
const CategoryDivider({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return const Padding(
|
|
|
|
padding: EdgeInsets.only(
|
|
|
|
left: 72,
|
|
|
|
right: 16,
|
|
|
|
),
|
|
|
|
child: Divider(
|
|
|
|
height: 0,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|