Skip to content

Commit f562685

Browse files
author
tensor-programming
committed
minor refactor
1 parent a9d6965 commit f562685

File tree

5 files changed

+14
-16
lines changed

5 files changed

+14
-16
lines changed

lib/blocs/contribution_bloc.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ class ContributionBloc {
1717
Stream<int> _timer = Stream.empty();
1818
// BehaviorSubject allows seeding the tabIndex data to pending.
1919
// Tagname is the name of the tab and modifier for the contributions
20-
BehaviorSubject<int> _tabIndex = BehaviorSubject<int>(seedValue: 0);
20+
BehaviorSubject<String> _tabName =
21+
BehaviorSubject<String>(seedValue: 'unreviewed');
2122
// Stream<String> _log = Stream.empty();
2223

2324
BehaviorSubject<String> _filter = BehaviorSubject<String>(seedValue: 'all');
@@ -27,11 +28,11 @@ class ContributionBloc {
2728
Stream<String> get voteCount => _voteCount;
2829
Stream<int> get timer => _timer;
2930

30-
Sink<int> get tabIndex => _tabIndex;
31+
Sink<String> get tabName => _tabName;
3132
Sink<String> get filter => _filter;
3233

3334
ContributionBloc(this.api, this.parseWebsite) {
34-
_results = _tabIndex
35+
_results = _tabName
3536

3637
// Apply the api updateContributions function to tabIndex stream to get results.
3738
.asyncMap(api.updateContributions)
@@ -50,7 +51,7 @@ class ContributionBloc {
5051
}
5152

5253
void dispose() {
53-
_tabIndex.close();
54+
_tabName.close();
5455
_filter.close();
5556
}
5657
}

lib/components/list_page.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import 'package:utopian_rocks/blocs/contribution_bloc.dart';
99
class ListPage extends StatelessWidget {
1010
final ContributionBloc bloc;
1111
final String tabName;
12-
final Function(int, ContributionBloc) callback;
12+
final Function(String, ContributionBloc) callback;
1313

1414
ListPage(this.tabName, this.bloc, this.callback);
1515
// Pass in the [tabName] or string which represents the page name.
@@ -19,8 +19,8 @@ class ListPage extends StatelessWidget {
1919
Widget build(BuildContext context) {
2020
// get block from [ContributionProvider] to add to [StreamBuilder]
2121
final parseWebsite = ParseWebsite();
22-
final tab = DefaultTabController.of(context);
23-
callback(tab.index, bloc);
22+
23+
callback(tabName, bloc);
2424

2525
parseWebsite.getHtml();
2626

lib/main.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class RootApp extends StatelessWidget {
169169
);
170170
}
171171

172-
void initialize(int tabIndex, ContributionBloc bloc) {
173-
bloc.tabIndex.add(tabIndex);
172+
void initialize(String tabName, ContributionBloc bloc) {
173+
bloc.tabName.add(tabName);
174174
}
175175
}

lib/model/repository.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import 'dart:async';
22
import 'dart:convert';
33

44
import 'package:utopian_rocks/model/model.dart';
5-
import 'package:utopian_rocks/utils/utils.dart';
65

76
import 'package:http/http.dart' show Client;
87

@@ -12,12 +11,12 @@ class Api {
1211
static const String _url = 'https://utopian.rocks/api/posts?status={0}';
1312

1413
// grab the contributions from the endpoint based on the tabname.
15-
Future<List<Contribution>> updateContributions(int tabIndex) async {
14+
Future<List<Contribution>> updateContributions(String tabName) async {
1615
List<Contribution> items = [];
1716
await _client
1817
// add the tabname to the url to change the API endpoint based on the page request
1918
// Decode the json and then serialize it into [Contribution] objects.
20-
.get(Uri.parse(_url.replaceFirst("{0}", statuses[tabIndex])))
19+
.get(Uri.parse(_url.replaceFirst("{0}", tabName ?? "unreviewed")))
2120
.then((res) => res.body)
2221
.then(json.decode)
2322
.then((json) => json.forEach(

lib/utils/utils.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,8 @@ List<Contribution> applyFilter(
8787
String filter,
8888
List<Contribution> contributions,
8989
) {
90-
var cons = contributions;
91-
9290
if (filter != 'all') {
93-
return cons.where((c) => c.category == filter).toList();
91+
return contributions.where((c) => c.category == filter).toList();
9492
}
95-
return cons;
93+
return contributions;
9694
}

0 commit comments

Comments
 (0)