-
-
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.
Merge pull request #287 from khoadng/e621
E621
- Loading branch information
Showing
84 changed files
with
3,649 additions
and
542 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,91 @@ | ||
// ignore_for_file: avoid_positional_boolean_parameters | ||
|
||
// Package imports: | ||
import 'package:dio/dio.dart'; | ||
import 'package:retrofit/retrofit.dart'; | ||
|
||
part 'e621_api.g.dart'; | ||
|
||
@RestApi() | ||
abstract class E621Api { | ||
factory E621Api( | ||
Dio dio, { | ||
String baseUrl, | ||
}) = _E621Api; | ||
|
||
@POST('/favorites.json') | ||
Future<HttpResponse> addToFavorites( | ||
@Query('login') String? login, | ||
@Query('api_key') String? apiKey, | ||
@Query('post_id') int postId, | ||
); | ||
|
||
@DELETE('/favorites/{postId}.json') | ||
Future<HttpResponse> removeFromFavorites( | ||
@Path() int postId, | ||
@Query('login') String? login, | ||
@Query('api_key') String? apiKey, | ||
); | ||
|
||
@GET('/comments.json') | ||
Future<HttpResponse> getComments( | ||
@Query('group_by') String groupBy, | ||
@Query('search[post_id]') int postId, | ||
@Query('limit') int limit, { | ||
@CancelRequest() CancelToken? cancelToken, | ||
}); | ||
|
||
@GET('/artists.json') | ||
Future<HttpResponse> getArtists( | ||
@Query('search[name]') String name, { | ||
@CancelRequest() CancelToken? cancelToken, | ||
}); | ||
|
||
@GET('/artists/{nameOrId}.json') | ||
Future<HttpResponse> getArtist( | ||
@Path() String nameOrId, { | ||
@CancelRequest() CancelToken? cancelToken, | ||
}); | ||
|
||
@GET('/posts.json') | ||
Future<HttpResponse> getPosts( | ||
@Query('login') String? login, | ||
@Query('api_key') String? apiKey, | ||
@Query('page') int page, | ||
@Query('tags') String tags, | ||
@Query('limit') int limit, { | ||
@CancelRequest() CancelToken? cancelToken, | ||
}); | ||
|
||
@GET('/popular.json') | ||
Future<HttpResponse> getPopularPosts( | ||
@Query('login') String? login, | ||
@Query('api_key') String? apiKey, | ||
@Query('date') String date, | ||
@Query('scale') String scale, | ||
); | ||
|
||
@GET('/tags.json') | ||
Future<HttpResponse> getTagsByNamePattern( | ||
@Query('login') String? login, | ||
@Query('api_key') String? apiKey, | ||
@Query('page') int page, | ||
@Query('search[hide_empty]') String hideEmpty, | ||
@Query('search[name_matches]') String stringPattern, | ||
@Query('search[order]') String order, | ||
@Query('limit') int limit, | ||
); | ||
|
||
@GET('/tags/autocomplete.json') | ||
Future<HttpResponse> autocomplete( | ||
@Query('search[name_matches]') String query, | ||
@Query('expiry') int expiry, | ||
); | ||
|
||
@GET('/notes.json') | ||
Future<HttpResponse> getNotes( | ||
@Query('search[post_id]') int postId, | ||
@Query('limit') int limit, { | ||
@CancelRequest() CancelToken? cancelToken, | ||
}); | ||
} |
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
File renamed without changes.
File renamed without changes.
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,20 @@ | ||
// Package imports: | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
|
||
// Project imports: | ||
import 'package:boorusama/boorus/core/feats/boorus/boorus.dart'; | ||
import 'package:boorusama/boorus/core/feats/notes/notes.dart'; | ||
import 'package:boorusama/boorus/core/feats/posts/posts.dart'; | ||
|
||
final noteRepoProvider = Provider<NoteRepository>((ref) { | ||
throw UnimplementedError(); | ||
}); | ||
|
||
final notesControllerProvider = NotifierProvider.autoDispose | ||
.family<NotesControllerNotifier, NotesControllerState, Post>( | ||
NotesControllerNotifier.new, | ||
dependencies: [ | ||
noteRepoProvider, | ||
currentBooruConfigProvider, | ||
], | ||
); |
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,6 @@ | ||
// Project imports: | ||
import 'package:boorusama/boorus/core/feats/notes/notes.dart'; | ||
|
||
abstract interface class NoteRepository { | ||
Future<List<Note>> getNotes(int postId); | ||
} |
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 'note.dart'; | ||
export 'note_coordinate.dart'; | ||
export 'note_provider.dart'; | ||
export 'note_repository.dart'; | ||
export 'notes_controller.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,61 @@ | ||
// Package imports: | ||
import 'package:equatable/equatable.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/notes/notes.dart'; | ||
import 'package:boorusama/boorus/core/feats/posts/posts.dart'; | ||
import 'package:boorusama/functional.dart'; | ||
|
||
class NotesControllerState extends Equatable { | ||
const NotesControllerState({ | ||
required this.notes, | ||
required this.enableNotes, | ||
}); | ||
|
||
final IList<Note> notes; | ||
final bool enableNotes; | ||
|
||
factory NotesControllerState.initial() => NotesControllerState( | ||
notes: <Note>[].lock, | ||
enableNotes: true, | ||
); | ||
|
||
NotesControllerState copyWith({ | ||
IList<Note>? notes, | ||
bool? enableNotes, | ||
}) => | ||
NotesControllerState( | ||
notes: notes ?? this.notes, | ||
enableNotes: enableNotes ?? this.enableNotes, | ||
); | ||
|
||
@override | ||
List<Object?> get props => [notes, enableNotes]; | ||
} | ||
|
||
class NotesControllerNotifier | ||
extends AutoDisposeFamilyNotifier<NotesControllerState, Post> { | ||
@override | ||
NotesControllerState build(Post arg) { | ||
ref.watch(currentBooruConfigProvider); | ||
|
||
return NotesControllerState.initial(); | ||
} | ||
|
||
void toggleNoteVisibility() { | ||
state = state.copyWith( | ||
enableNotes: !state.enableNotes, | ||
); | ||
} | ||
|
||
Future<void> load() async { | ||
if (state.notes.isEmpty && arg.isTranslated) { | ||
final notes = await ref.read(noteRepoProvider).getNotes(arg.id); | ||
state = state.copyWith( | ||
notes: notes.lock, | ||
); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.