Skip to content

Commit 091c466

Browse files
committed
⚙️ feature(media_content): Added media content search
1 parent be5e5e8 commit 091c466

File tree

16 files changed

+441
-36
lines changed

16 files changed

+441
-36
lines changed

lib/core/routes/app_routes.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ sealed class AppRoutes {
44
static const home = AppRoute._('home', '/home');
55
static const apod = AppRoute._('apod', 'apod');
66
static const viewApod = AppRoute._('viewApod', 'viewApod');
7+
8+
static const search = AppRoute._('search', '/search');
9+
static const mediaContent = AppRoute._('content', 'mediaContent');
710
}
811

912
class AppRoute {

lib/core/routes/go_router.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import 'package:nasa_app_challenge/features/apod/presentation/blocs/apods_bloc/a
88
import 'package:nasa_app_challenge/features/apod/presentation/pages/apods_page.dart';
99
import 'package:nasa_app_challenge/features/apod/presentation/pages/viewer_apod_page.dart';
1010
import 'package:nasa_app_challenge/features/home/presentation/pages/home_page.dart';
11+
import 'package:nasa_app_challenge/features/searches/presentation/pages/media_content_detail.dart';
12+
import 'package:nasa_app_challenge/features/searches/presentation/pages/search_contents_page.dart';
1113
import 'package:nasa_app_challenge/features/welcome/presentation/pages/onboarding_page.dart';
1214
import 'package:nasa_app_challenge/features/welcome/presentation/pages/splash_page.dart';
1315

@@ -59,5 +61,18 @@ final goRouterConfig = GoRouter(
5961
),
6062
],
6163
),
64+
GoRoute(
65+
name: AppRoutes.search.name,
66+
path: AppRoutes.search.path,
67+
builder: (__, _) => const SearchContentsPage(),
68+
routes: [
69+
GoRoute(
70+
name: AppRoutes.mediaContent.name,
71+
path: AppRoutes.mediaContent.path,
72+
builder: (__, state) => MediaContentPage(
73+
content: state.extra! as MediaContent,
74+
),
75+
),
76+
]),
6277
],
6378
);

lib/core/shared/data/repositories/media_content_repository_imp.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import 'package:injectable/injectable.dart';
12
import 'package:nasa_api/nasa_api.dart';
23
import 'package:nasa_app_challenge/core/core.dart';
34
import 'package:nasa_app_challenge/core/shared/domain/entities/search_media_response.dart';
45
import 'package:nasa_app_challenge/core/shared/domain/repositories/media_content_repository.dart';
56
import 'package:nasa_app_challenge/core/shared/domain/requests/media_content_request.dart';
67
import 'package:nasa_core/nasa_core.dart';
78

9+
@Injectable(as: MediaContentRepository)
810
class MediaContentRepositoryImp implements MediaContentRepository {
911
MediaContentRepositoryImp(this._api);
1012

lib/core/shared/domain/entities/link.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Link with _$Link {
88
const factory Link({
99
required String href,
1010
required String rel,
11-
required String render,
11+
String? render,
1212
}) = _Link;
1313

1414
factory Link.fromJson(Map<String, dynamic> json) => _$LinkFromJson(json);

lib/core/shared/domain/entities/media_content.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class MediaContent with _$MediaContent {
1111
const factory MediaContent({
1212
@JsonKey(name: 'href') required String collection,
1313
required List<MediaData> data,
14-
required List<Link> links,
14+
List<Link>? links,
1515
}) = _MediaContent;
1616

1717
factory MediaContent.fromJson(Map<String, dynamic> json) =>

lib/core/shared/domain/entities/media_data.dart

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ class MediaData with _$MediaData {
99
const factory MediaData.image({
1010
required String title,
1111
required String description,
12-
required String photographer,
13-
required String location,
1412
required DateTime dateCreated,
1513
required String center,
1614
required String nasaId,
15+
String? location,
16+
String? photographer,
1717
String? description508,
1818
@Default([]) List<String> keywords,
1919
}) = _Image;
@@ -33,8 +33,6 @@ class MediaData with _$MediaData {
3333
const factory MediaData.audio({
3434
required String title,
3535
required String description,
36-
required String photographer,
37-
required String location,
3836
required DateTime dateCreated,
3937
required String center,
4038
required String nasaId,
@@ -47,23 +45,3 @@ class MediaData with _$MediaData {
4745
}
4846

4947
// "data": [
50-
// {
51-
// "description": "Chemist Trey Barnes prepares a gas sample for injection into a gas chromatography-mass spectrometry system preconcentrator for analyzing trace level gas contaminants inside NASA Engineering’s Analytical Laboratories at Kennedy Space Center in Florida on July 7, 2021. One of seven branches in the NASA Laboratories, Development, and Testing Division, the Analytical Laboratories branch provides microscopic imagery and analysis through the use of a wide variety of microscopic techniques to identify contaminants and other urgent problems associated with aerospace flight hardware, ground support equipment, and related facilities. ",
52-
// "title": "CSI: Chemistry Space Investigation",
53-
// "photographer": "NASA/Frank Michaux",
54-
// "location": "Analytical Chemistry Lab",
55-
// "nasa_id": "KSC-20210707-PH-FMX01_0262",
56-
// "date_created": "2021-07-07T00:00:00Z",
57-
// "keywords": [
58-
// "Analytical Chemistry Lab",
59-
// "CSI",
60-
// "Chemistry Space Investigation",
61-
// "KSC",
62-
// "Kennedy Space Center",
63-
// "NASA",
64-
// "NASA Engineers"
65-
// ],
66-
// "media_type": "image",
67-
// "center": "KSC"
68-
// }
69-
// ],

lib/features/home/presentation/pages/home_page.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ class _HomeViewState extends State<_HomeView>
5151
ApodsHomeView(),
5252
PlanetsView(),
5353
Center(
54-
child: Text('View 3'),
54+
child: Text('Video library'),
5555
),
5656
Center(
57-
child: Text('View 4'),
57+
child: Text('Podcasts & Audio files'),
5858
),
5959
],
6060
),

lib/features/home/presentation/widgets/home_search_text_field.dart

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import 'package:flutter/cupertino.dart';
22
import 'package:flutter/material.dart';
33
import 'package:flutter_screenutil/flutter_screenutil.dart';
4+
import 'package:go_router/go_router.dart';
5+
import 'package:nasa_app_challenge/core/core.dart';
46

57
class HomeSearchTextField extends StatelessWidget {
68
const HomeSearchTextField({
@@ -15,14 +17,20 @@ class HomeSearchTextField extends StatelessWidget {
1517
toolbarHeight: (kToolbarHeight + 12).sp,
1618
actions: [
1719
Expanded(
18-
child: TextField(
19-
readOnly: true,
20-
onTap: () {},
21-
decoration: const InputDecoration(
22-
hintText: 'Explore the space',
23-
prefixIcon: Icon(
24-
CupertinoIcons.search,
25-
color: Colors.white54,
20+
child: Hero(
21+
tag: 'search-text-field',
22+
child: Material(
23+
type: MaterialType.transparency,
24+
child: TextField(
25+
readOnly: true,
26+
onTap: () => context.pushNamed(AppRoutes.search.name),
27+
decoration: const InputDecoration(
28+
hintText: 'Explore the space',
29+
prefixIcon: Icon(
30+
CupertinoIcons.search,
31+
color: Colors.white54,
32+
),
33+
),
2634
),
2735
),
2836
),
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import 'dart:async';
2+
3+
import 'package:bloc/bloc.dart';
4+
import 'package:freezed_annotation/freezed_annotation.dart';
5+
import 'package:injectable/injectable.dart';
6+
import 'package:nasa_app_challenge/core/core.dart';
7+
import 'package:nasa_app_challenge/core/shared/domain/repositories/media_content_repository.dart';
8+
import 'package:nasa_app_challenge/core/shared/domain/requests/media_content_request.dart';
9+
10+
part 'search_bloc.freezed.dart';
11+
part 'search_event.dart';
12+
part 'search_state.dart';
13+
14+
@injectable
15+
class SearchBloc extends Bloc<SearchEvent, SearchState> {
16+
SearchBloc(this._repository) : super(const SearchState.initial()) {
17+
on<_PerformSearch>(_onPerformSearch);
18+
}
19+
20+
final MediaContentRepository _repository;
21+
22+
Future<void> _onPerformSearch(
23+
_PerformSearch event,
24+
Emitter<SearchState> emit,
25+
) async {
26+
emit(const _Loading());
27+
final res = await _repository.searchMediaContent(
28+
MediaContentRequest(page: 1, query: event.text, pageSize: 80),
29+
);
30+
res.when(
31+
success: (data) => emit(_Success(results: data)),
32+
error: (exception) => emit(_Error(exception: exception)),
33+
);
34+
}
35+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
part of 'search_bloc.dart';
2+
3+
@freezed
4+
class SearchEvent with _$SearchEvent {
5+
const factory SearchEvent.performSearch(String text) = _PerformSearch;
6+
}

0 commit comments

Comments
 (0)