-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
228 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export 'moebooru_comment.dart'; | ||
export 'moebooru_comment_dto.dart'; | ||
export 'moebooru_comment_parser.dart'; | ||
export 'moebooru_comment_provider.dart'; | ||
export 'moebooru_comment_repository.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Package imports: | ||
import 'package:equatable/equatable.dart'; | ||
|
||
class MoebooruComment extends Equatable { | ||
const MoebooruComment({ | ||
required this.id, | ||
required this.createdAt, | ||
required this.postId, | ||
required this.creator, | ||
required this.creatorId, | ||
required this.body, | ||
}); | ||
|
||
final int id; | ||
final DateTime createdAt; | ||
final int postId; | ||
final String creator; | ||
final int creatorId; | ||
final String body; | ||
|
||
@override | ||
List<Object> get props => [ | ||
id, | ||
createdAt, | ||
postId, | ||
creator, | ||
creatorId, | ||
body, | ||
]; | ||
} |
28 changes: 28 additions & 0 deletions
28
lib/boorus/moebooru/feats/comments/moebooru_comment_dto.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
class MoebooruCommentDto { | ||
final int? id; | ||
final String? createdAt; | ||
final int? postId; | ||
final String? creator; | ||
final int? creatorId; | ||
final String? body; | ||
|
||
MoebooruCommentDto({ | ||
this.id, | ||
this.createdAt, | ||
this.postId, | ||
this.creator, | ||
this.creatorId, | ||
this.body, | ||
}); | ||
|
||
factory MoebooruCommentDto.fromJson(Map<String, dynamic> json) { | ||
return MoebooruCommentDto( | ||
id: json['id'], | ||
createdAt: json['created_at'], | ||
postId: json['post_id'], | ||
creator: json['creator'], | ||
creatorId: json['creator_id'], | ||
body: json['body'], | ||
); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
lib/boorus/moebooru/feats/comments/moebooru_comment_parser.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Package imports: | ||
import 'package:retrofit/dio.dart'; | ||
|
||
// Project imports: | ||
import 'package:boorusama/foundation/http/http.dart'; | ||
import 'moebooru_comment.dart'; | ||
import 'moebooru_comment_dto.dart'; | ||
|
||
MoebooruComment moebooruCommentDtoToMoebooruComment(MoebooruCommentDto dto) { | ||
return MoebooruComment( | ||
id: dto.id ?? 0, | ||
createdAt: DateTime.tryParse(dto.createdAt ?? '') ?? DateTime.now(), | ||
postId: dto.postId ?? 0, | ||
creator: dto.creator ?? '', | ||
creatorId: dto.creatorId ?? 0, | ||
body: dto.body ?? '', | ||
); | ||
} | ||
|
||
List<MoebooruComment> parseMoebooruComments(HttpResponse<dynamic> response) => | ||
parseResponse( | ||
value: response, | ||
converter: (item) => MoebooruCommentDto.fromJson(item), | ||
).map(moebooruCommentDtoToMoebooruComment).toList(); |
19 changes: 19 additions & 0 deletions
19
lib/boorus/moebooru/feats/comments/moebooru_comment_provider.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Package imports: | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
|
||
// Project imports: | ||
import 'package:boorusama/boorus/core/feats/boorus/boorus.dart'; | ||
import 'package:boorusama/boorus/moebooru/moebooru_provider.dart'; | ||
import 'moebooru_comment.dart'; | ||
import 'moebooru_comment_repository.dart'; | ||
|
||
final moebooruCommentRepoProvider = Provider<MoebooruCommentRepository>((ref) { | ||
return MoebooruCommentRepositoryApi( | ||
api: ref.watch(moebooruApiProvider), | ||
booruConfig: ref.watch(currentBooruConfigProvider), | ||
); | ||
}); | ||
|
||
final moebooruCommentsProvider = | ||
FutureProvider.family<List<MoebooruComment>, int>((ref, postId) => | ||
ref.watch(moebooruCommentRepoProvider).getComments(postId)); |
25 changes: 25 additions & 0 deletions
25
lib/boorus/moebooru/feats/comments/moebooru_comment_repository.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Project imports: | ||
import 'package:boorusama/api/moebooru/moebooru_api.dart'; | ||
import 'package:boorusama/boorus/core/feats/boorus/boorus.dart'; | ||
import 'package:boorusama/boorus/moebooru/feats/comments/moebooru_comment_parser.dart'; | ||
import 'moebooru_comment.dart'; | ||
|
||
abstract interface class MoebooruCommentRepository { | ||
Future<List<MoebooruComment>> getComments(int postId); | ||
} | ||
|
||
class MoebooruCommentRepositoryApi implements MoebooruCommentRepository { | ||
MoebooruCommentRepositoryApi({ | ||
required this.api, | ||
required this.booruConfig, | ||
}); | ||
|
||
final MoebooruApi api; | ||
final BooruConfig booruConfig; | ||
|
||
@override | ||
Future<List<MoebooruComment>> getComments(int postId) => api | ||
.getComments(booruConfig.login, booruConfig.apiKey, postId) | ||
.then(parseMoebooruComments) | ||
.catchError((e) => <MoebooruComment>[]); | ||
} |
50 changes: 50 additions & 0 deletions
50
lib/boorus/moebooru/pages/comments/moebooru_comment_item.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Flutter imports: | ||
import 'package:flutter/material.dart'; | ||
|
||
// Package imports: | ||
import 'package:flutter_html/flutter_html.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
|
||
// Project imports: | ||
import 'package:boorusama/boorus/core/feats/boorus/boorus.dart'; | ||
import 'package:boorusama/boorus/core/feats/dtext/html_converter.dart'; | ||
import 'package:boorusama/boorus/core/widgets/comment_header.dart'; | ||
import 'package:boorusama/boorus/moebooru/feats/comments/comments.dart'; | ||
import 'package:boorusama/flutter.dart'; | ||
|
||
class MoebooruCommentItem extends ConsumerWidget { | ||
const MoebooruCommentItem({ | ||
super.key, | ||
required this.comment, | ||
}); | ||
|
||
final MoebooruComment comment; | ||
|
||
@override | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
final booru = ref.watch(currentBooruProvider); | ||
|
||
return Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
CommentHeader( | ||
authorName: comment.creator, | ||
authorTitleColor: context.colorScheme.primary, | ||
createdAt: comment.createdAt, | ||
), | ||
const SizedBox(height: 4), | ||
Html( | ||
style: { | ||
'body': Style( | ||
margin: EdgeInsets.zero, | ||
), | ||
}, | ||
data: dtext( | ||
comment.body, | ||
booru: booru, | ||
), | ||
) | ||
], | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters