Skip to content

Commit ff0104e

Browse files
committed
fix(github): readme loading in repo screen
1 parent 36de5ec commit ff0104e

File tree

2 files changed

+48
-35
lines changed

2 files changed

+48
-35
lines changed

lib/home.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:git_touch/models/theme.dart';
66
import 'package:git_touch/screens/bb_explore.dart';
77
import 'package:git_touch/screens/bb_teams.dart';
88
import 'package:git_touch/screens/bb_user.dart';
9+
import 'package:git_touch/screens/gh_repo.dart';
910
import 'package:git_touch/screens/gl_search.dart';
1011
import 'package:git_touch/screens/gt_orgs.dart';
1112
import 'package:git_touch/screens/gt_user.dart';
@@ -40,6 +41,7 @@ class _HomeState extends State<Home> {
4041
// return IssueScreen('reactjs', 'rfcs', 29);
4142
// return IssueScreen('reactjs', 'rfcs', 68, isPullRequest: true);
4243
// return Image.asset('images/spinner.webp', width: 32, height: 32);
44+
// return GhRepoScreen('shreyas1599', 'test');
4345
final auth = Provider.of<AuthModel>(context);
4446
switch (auth.activeAccount.platform) {
4547
case PlatformType.github:

lib/screens/gh_repo.dart

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import 'package:git_touch/widgets/app_bar_title.dart';
99
import 'package:git_touch/widgets/entry_item.dart';
1010
import 'package:git_touch/widgets/label.dart';
1111
import 'package:git_touch/widgets/language_bar.dart';
12-
import 'package:git_touch/widgets/loading.dart';
1312
import 'package:git_touch/widgets/mutation_button.dart';
1413
import 'package:git_touch/widgets/markdown_view.dart';
1514
import 'package:git_touch/widgets/repo_header.dart';
1615
import 'package:git_touch/widgets/table_view.dart';
1716
import 'package:github/github.dart';
1817
import 'package:provider/provider.dart';
1918
import 'package:git_touch/models/theme.dart';
19+
import 'package:tuple/tuple.dart';
2020
import 'package:git_touch/widgets/action_button.dart';
2121

2222
class GhRepoScreen extends StatelessWidget {
@@ -25,6 +25,16 @@ class GhRepoScreen extends StatelessWidget {
2525
final String branch;
2626
GhRepoScreen(this.owner, this.name, {this.branch});
2727

28+
Future<GhRepoRepository> _query(BuildContext context) async {
29+
var res = await context.read<AuthModel>().gqlClient.execute(GhRepoQuery(
30+
variables: GhRepoArguments(
31+
owner: owner,
32+
name: name,
33+
branchSpecified: branch != null,
34+
branch: branch ?? '')));
35+
return res.data.repository;
36+
}
37+
2838
String _buildWatchState(GhRepoSubscriptionState state) {
2939
switch (state) {
3040
case GhRepoSubscriptionState.IGNORED:
@@ -38,21 +48,35 @@ class GhRepoScreen extends StatelessWidget {
3848
}
3949
}
4050

51+
Future<String> _fetchReadme(BuildContext context) async {
52+
try {
53+
final res = await context
54+
.read<AuthModel>()
55+
.ghClient
56+
.repositories
57+
.getReadme(RepositorySlug(owner, name));
58+
return res.text;
59+
} catch (e) {
60+
// 404
61+
return null;
62+
}
63+
}
64+
4165
@override
4266
Widget build(BuildContext context) {
4367
final theme = Provider.of<ThemeModel>(context);
44-
return RefreshStatefulScaffold<GhRepoRepository>(
68+
return RefreshStatefulScaffold<Tuple2<GhRepoRepository, String>>(
4569
title: AppBarTitle('Repository'),
4670
fetch: () async {
47-
var res = await context.read<AuthModel>().gqlClient.execute(GhRepoQuery(
48-
variables: GhRepoArguments(
49-
owner: owner,
50-
name: name,
51-
branchSpecified: branch != null,
52-
branch: branch ?? '')));
53-
return res.data.repository;
71+
final rs = await Future.wait([
72+
_query(context),
73+
_fetchReadme(context),
74+
]);
75+
76+
return Tuple2(rs[0] as GhRepoRepository, rs[1] as String);
5477
},
55-
actionBuilder: (repo, setState) {
78+
actionBuilder: (data, setState) {
79+
final repo = data.item1;
5680
return ActionButton(
5781
title: 'Repository Actions',
5882
items: [
@@ -68,7 +92,9 @@ class GhRepoScreen extends StatelessWidget {
6892
],
6993
);
7094
},
71-
bodyBuilder: (repo, setState) {
95+
bodyBuilder: (data, setState) {
96+
final repo = data.item1;
97+
final readme = data.item2;
7298
final ref = branch == null ? repo.defaultBranchRef : repo.ref;
7399
final license = repo.licenseInfo?.spdxId ?? repo.licenseInfo?.name;
74100

@@ -306,30 +332,15 @@ class GhRepoScreen extends StatelessWidget {
306332
],
307333
],
308334
),
309-
FutureBuilder<String>(
310-
future: context
311-
.read<AuthModel>()
312-
.ghClient
313-
.repositories
314-
.getReadme(RepositorySlug(owner, name))
315-
.then((file) => file.text),
316-
builder: (context, snapshot) {
317-
if (snapshot.connectionState == ConnectionState.waiting) {
318-
return Loading();
319-
}
320-
if (snapshot.hasData) {
321-
return Container(
322-
padding: CommonStyle.padding,
323-
color: theme.palette.background,
324-
child: MarkdownView(
325-
snapshot.data,
326-
basePaths: [owner, name, branch ?? 'master'], // TODO:
327-
),
328-
);
329-
}
330-
return Container();
331-
},
332-
),
335+
if (readme != null)
336+
Container(
337+
padding: CommonStyle.padding,
338+
color: theme.palette.background,
339+
child: MarkdownView(
340+
readme,
341+
basePaths: [owner, name, branch ?? 'master'], // TODO:
342+
),
343+
),
333344
CommonStyle.verticalGap,
334345
],
335346
);

0 commit comments

Comments
 (0)