Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reddit api, reddit scrapper #2

Merged
merged 3 commits into from
Sep 12, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
+ reddit post to meme model mapper
+ reddit api getMemes wrapper
+ reddit scrapper implementation
  • Loading branch information
IgorKhramtsov committed Sep 11, 2021
commit 5ad00a071d45b826e4dfb171841ec7b92667b6a9
19 changes: 9 additions & 10 deletions lib/application/feed/bloc/feed_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:async';

import 'package:devour/domain/meme/abstract_meme_model.dart';
import 'package:devour/infrastructure/api/reddit/reddit_api.dart';
import 'package:devour/infrastructure/meme_scrapper/reddit_scrapper.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:injectable/injectable.dart';
@@ -14,10 +14,10 @@ const int kMemeChunkSize = 20;

@injectable
class FeedBloc extends Bloc<FeedEvent, FeedState> {
RedditAPI redditAPI;
RedditScrapperFacade redditScrapper;

/// BLoC for feed widget.
FeedBloc(this.redditAPI) : super(FeedState.loading());
FeedBloc(this.redditScrapper) : super(FeedState.loading());

@override
Stream<FeedState> mapEventToState(
@@ -26,13 +26,12 @@ class FeedBloc extends Bloc<FeedEvent, FeedState> {
yield* event.map(
init: (e) async* {
yield FeedState.loading();
final scrappedMemes = await redditAPI.getMemes();
print(scrappedMemes);
// yield state.copyWith(
// isLoading: false,
// memes: scrappedMemes,
// iterator: 0,
// );
final scrappedMemes = await redditScrapper.getMemes(kMemeChunkSize);
yield state.copyWith(
isLoading: false,
memes: scrappedMemes,
iterator: 0,
);
},
like: (e) async* {
yield state;
13 changes: 2 additions & 11 deletions lib/domain/meme/abstract_meme_model.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:freezed_annotation/freezed_annotation.dart';

part 'abstract_meme_model.freezed.dart';
part 'abstract_meme_model.g.dart';

// part 'abstract_meme_model.g.dart';
@freezed
@@ -19,18 +18,10 @@ abstract class AbstractMemeModel with _$AbstractMemeModel {
factory AbstractMemeModel.reddit({
required String title,
required String author,
@JsonKey(name: 'image_reviews') required List<String> imagePreviews,
@JsonKey(name: 'url') required String imageLink,
@JsonKey(name: 'post_link') required String sourceLink,
required String imageLink,
required String sourceLink,
required String subreddit,
required int ups,
@JsonKey(name: 'spoilers_enabled') required bool spoilersEnabled,
required bool nsfw,
}) = RedditMemeModel;

const AbstractMemeModel._();

factory AbstractMemeModel.fromJson(Map<String, Object?> json) =>
_$AbstractMemeModelFromJson(json);
// ignore: public_member_api_docs
}
Loading