Skip to content

Commit be3584f

Browse files
committed
✨Add repo commit history section
1 parent 097937a commit be3584f

File tree

17 files changed

+781
-13
lines changed

17 files changed

+781
-13
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ Stable release build will be available soon..
4343
* See repo stargazerrs and fork Repos
4444
* PRs statuses
4545
* Gists
46-
* Themes mode
46+
* Themes mode
47+
* Commits
4748
* Following/Followers
4849
* View Gists and their files
4950
* View user profile, contribution graph, activities, repositories, pullrequest and issues

lib/bloc/User/model/gist_model.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,33 @@ class GistResponse {
77
this.user,
88
});
99

10-
final User user;
10+
final ActorModel user;
1111

1212
factory GistResponse.fromRawJson(String str) => GistResponse.fromJson(json.decode(str));
1313

1414
String toRawJson() => json.encode(toJson());
1515

1616
factory GistResponse.fromJson(Map<String, dynamic> json) => GistResponse(
17-
user: json["user"] == null ? null : User.fromJson(json["user"]),
17+
user: json["user"] == null ? null : ActorModel.fromJson(json["user"]),
1818
);
1919

2020
Map<String, dynamic> toJson() => {
2121
"user": user == null ? null : user.toJson(),
2222
};
2323
}
2424

25-
class User {
26-
User({
25+
class ActorModel {
26+
ActorModel({
2727
this.gists,
2828
});
2929

3030
final Gists gists;
3131

32-
factory User.fromRawJson(String str) => User.fromJson(json.decode(str));
32+
factory ActorModel.fromRawJson(String str) => ActorModel.fromJson(json.decode(str));
3333

3434
String toRawJson() => json.encode(toJson());
3535

36-
factory User.fromJson(Map<String, dynamic> json) => User(
36+
factory ActorModel.fromJson(Map<String, dynamic> json) => ActorModel(
3737
gists: json["gists"] == null ? null : Gists.fromJson(json["gists"]),
3838
);
3939

lib/bloc/commit/commit_bloc.dart

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import 'dart:async';
2+
import 'dart:developer' as developer;
3+
4+
import 'package:bloc/bloc.dart';
5+
import 'package:flutter_github_connect/bloc/commit/index.dart';
6+
7+
class CommitBloc extends Bloc<CommitEvent, CommitState> {
8+
9+
CommitBloc() : super(LoadingCommitState());
10+
11+
@override
12+
Stream<CommitState> mapEventToState(
13+
CommitEvent event,
14+
) async* {
15+
try {
16+
if(event is LoadCommitsEvent){
17+
if(event.isLoadNextCommit){
18+
yield* event.getNextCommits(currentState: state, bloc: this);
19+
}else{
20+
yield* event.getCommits(currentState: state, bloc: this);
21+
}
22+
}
23+
24+
} catch (_, stackTrace) {
25+
developer.log('$_', name: 'CommitBloc', error: _, stackTrace: stackTrace);
26+
yield state;
27+
}
28+
}
29+
}

lib/bloc/commit/commit_event.dart

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import 'dart:async';
2+
import 'dart:developer' as developer;
3+
4+
import 'package:equatable/equatable.dart';
5+
import 'package:flutter_github_connect/bloc/commit/index.dart';
6+
import 'package:flutter_github_connect/resources/gatway/api_gatway.dart';
7+
import 'package:flutter_github_connect/resources/repository/repo_repository.dart';
8+
import 'package:get_it/get_it.dart';
9+
import 'package:meta/meta.dart';
10+
11+
@immutable
12+
abstract class CommitEvent extends Equatable {
13+
@override
14+
List<Object> get props => [];
15+
final RepoRepository _repoRepository = RepoRepository(apiGatway: GetIt.instance<ApiGateway>());
16+
Stream<CommitState> getCommits({CommitState currentState, CommitBloc bloc})async*{}
17+
Stream<CommitState> getNextCommits({CommitState currentState, CommitBloc bloc}) async*{}
18+
}
19+
20+
class LoadCommitsEvent extends CommitEvent {
21+
final String name;
22+
final String owner;
23+
final int count;
24+
final bool isLoadNextCommit;
25+
26+
LoadCommitsEvent(this.name, this.owner,{this.count,this.isLoadNextCommit = false});
27+
@override
28+
Stream<CommitState> getCommits({CommitState currentState, CommitBloc bloc}) async* {
29+
try {
30+
yield LoadingCommitState();
31+
final history = await _repoRepository.fetchCommits(name: name, owner: owner);
32+
yield LoadedCommitState(history);
33+
} catch (_, stackTrace) {
34+
developer.log('$_', name: 'LoadCommitEvent', error: _, stackTrace: stackTrace);
35+
yield ErrorCommitState( _?.toString());
36+
}
37+
}
38+
39+
Stream<CommitState> getNextCommits({CommitState currentState, CommitBloc bloc}) async* {
40+
try {
41+
final state = currentState as LoadedCommitState;
42+
if (!state.history.pageInfo.hasNextPage) {
43+
print("No Issues left");
44+
return;
45+
}
46+
yield LoadingNextCommitState(state.history);
47+
final historyModel = await _repoRepository.fetchCommits(name: name, owner: owner,endCursor:state.history.pageInfo.endCursor);
48+
yield LoadedCommitState.next(
49+
currentHistoryModel: state.history,
50+
historyModel: historyModel
51+
);
52+
} catch (_, stackTrace) {
53+
developer.log('$_',
54+
name: 'LoadUserEvent', error: _, stackTrace: stackTrace);
55+
final state = currentState as LoadedCommitState;
56+
yield ErrorNextIssuessState(
57+
errorMessage: _?.toString(), history: state.history);
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)