Skip to content

Commit

Permalink
Add tag list screen
Browse files Browse the repository at this point in the history
  • Loading branch information
up2code committed May 19, 2024
1 parent 5b39677 commit 0b195f9
Show file tree
Hide file tree
Showing 17 changed files with 571 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ class HomeScreen extends StatelessWidget {
ShortcutMenuButton(
title: 'Tags',
iconData: Icons.label,
onPressed: () {},
onPressed: () {
context.goTagSearchScreen();
},
),
ShortcutMenuButton(
title: 'Events',
Expand Down
8 changes: 8 additions & 0 deletions lib/src/features/tags/data/constants/fake_tags_list.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import 'package:vocadb_app/src/features/tags/domain/tag.dart';

final kFakeTagsList = [
Tag(id: 6107, name: '#コンパス', categoryName: 'Copyrights'),
Tag(id: 9078, name: '#コンパス ライブアリーナ', categoryName: 'Games'),
Tag(id: 7720, name: 'LIVE', categoryName: 'Copyrights'),
Tag(id: 10264, name: '10 million master', categoryName: 'Series'),
];
12 changes: 12 additions & 0 deletions lib/src/features/tags/data/tag_api_repository.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// ignore_for_file: public_member_api_docs, sort_constructors_first
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:vocadb_app/src/features/api/api_client.dart';
import 'package:vocadb_app/src/features/api/data/api_query_result.dart';
import 'package:vocadb_app/src/features/tags/data/tag_repository.dart';
import 'package:vocadb_app/src/features/tags/domain/tag.dart';
import 'package:vocadb_app/src/features/tags/domain/tags_list_params.dart';

class TagApiRepository implements TagRepository {
TagApiRepository({
Expand All @@ -23,6 +25,16 @@ class TagApiRepository implements TagRepository {

return Tag.fromJson(response);
}

@override
Future<List<Tag>> fetchTagsList({TagsListParams params = const TagsListParams()}) async {

final responseBody = await client.get('/api/tags', params: params.toJson());

final queryResult = ApiQueryResult.fromMap(responseBody);

return Tag.fromJsonToList(queryResult.items).toList();
}
}

final tagApiRepositoryProvider = Provider.autoDispose<TagApiRepository>((ref) {
Expand Down
7 changes: 7 additions & 0 deletions lib/src/features/tags/data/tag_fake_repository.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:vocadb_app/src/features/tags/data/constants/fake_tag_detail.dart';
import 'package:vocadb_app/src/features/tags/data/constants/fake_tags_list.dart';
import 'package:vocadb_app/src/features/tags/data/tag_repository.dart';
import 'package:vocadb_app/src/features/tags/domain/tag.dart';
import 'package:vocadb_app/src/features/tags/domain/tags_list_params.dart';

class TagFakeRepository implements TagRepository {
@override
Future<Tag> fetchTagID(int id, {String lang = 'Default'}) {
return Future.value(kFakeTagDetail);
}

@override
Future<List<Tag>> fetchTagsList({TagsListParams params = const TagsListParams()}) async {
return Future.value(kFakeTagsList);
}
}

final tagFakeRepositoryProvider = Provider<TagFakeRepository>((ref) {
Expand Down
2 changes: 2 additions & 0 deletions lib/src/features/tags/data/tag_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import 'package:vocadb_app/src/features/settings/data/user_settings_repository.d
import 'package:vocadb_app/src/features/tags/data/tag_api_repository.dart';
import 'package:vocadb_app/src/features/tags/data/tag_fake_repository.dart';
import 'package:vocadb_app/src/features/tags/domain/tag.dart';
import 'package:vocadb_app/src/features/tags/domain/tags_list_params.dart';

abstract class TagRepository {
Future<Tag> fetchTagID(int id, {String lang = 'Default'});
Future<List<Tag>> fetchTagsList({TagsListParams params});
}

final tagRepositoryProvider = Provider.autoDispose<TagRepository>((ref) {
Expand Down
4 changes: 4 additions & 0 deletions lib/src/features/tags/domain/tag.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ class Tag with _$Tag {
}) = _Tag;

factory Tag.fromJson(Map<String, dynamic> json) => _$TagFromJson(json);

static List<Tag> fromJsonToList(List<dynamic> source) {
return source.map((e) => Tag.fromJson(e)).toList();
}
}

extension TagExtended on Tag {
Expand Down
21 changes: 21 additions & 0 deletions lib/src/features/tags/domain/tags_list_params.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'package:freezed_annotation/freezed_annotation.dart';

part 'tags_list_params.freezed.dart';
part 'tags_list_params.g.dart';

@freezed
class TagsListParams with _$TagsListParams {
@JsonSerializable(includeIfNull: false)
const factory TagsListParams({
String? query,
String? categoryName,
@Default(0) int start,
@Default(10) int maxResults,
@Default('None') String sort,
@Default('Name') String nameMatchMode,
@Default('Default') String lang,
}) = _TagsListParams;

factory TagsListParams.fromJson(Map<String, dynamic> json) =>
_$TagsListParamsFromJson(json);
}
Loading

0 comments on commit 0b195f9

Please sign in to comment.