mirror of
https://github.com/git-touch/git-touch
synced 2025-02-28 09:17:56 +01:00
refactor(github): lazy load readme
This commit is contained in:
parent
397063a6b0
commit
40dff68e76
@ -49,31 +49,33 @@ class GhRepoScreen extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String> _fetchReadme(BuildContext context) async {
|
|
||||||
try {
|
|
||||||
final res = await context.read<AuthModel>().ghClient.request(
|
|
||||||
'GET', '/repos/$owner/$name/readme', headers: {
|
|
||||||
HttpHeaders.acceptHeader: 'application/vnd.github.v3.html'
|
|
||||||
});
|
|
||||||
return res.body;
|
|
||||||
} catch (e) {
|
|
||||||
// 404
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final theme = Provider.of<ThemeModel>(context);
|
final theme = Provider.of<ThemeModel>(context);
|
||||||
return RefreshStatefulScaffold<Tuple2<GhRepoRepository, String>>(
|
return RefreshStatefulScaffold<
|
||||||
|
Tuple3<GhRepoRepository, Future<int>, Future<String>>>(
|
||||||
title: AppBarTitle('Repository'),
|
title: AppBarTitle('Repository'),
|
||||||
fetch: () async {
|
fetch: () async {
|
||||||
final rs = await Future.wait([
|
final ghClient = context.read<AuthModel>().ghClient;
|
||||||
_query(context),
|
|
||||||
_fetchReadme(context),
|
|
||||||
]);
|
|
||||||
|
|
||||||
return Tuple2(rs[0] as GhRepoRepository, rs[1] as String);
|
final repo = await _query(context);
|
||||||
|
|
||||||
|
final countFuture = ghClient
|
||||||
|
.getJSON('/repos/$owner/$name/stats/contributors')
|
||||||
|
.then((v) => (v as List).length);
|
||||||
|
|
||||||
|
final readmeFuture = ghClient.request(
|
||||||
|
'GET',
|
||||||
|
'/repos/$owner/$name/readme',
|
||||||
|
headers: {HttpHeaders.acceptHeader: 'application/vnd.github.v3.html'},
|
||||||
|
).then((res) {
|
||||||
|
return res.body;
|
||||||
|
}).catchError((err) {
|
||||||
|
// 404
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
return Tuple3(repo, countFuture, readmeFuture);
|
||||||
},
|
},
|
||||||
actionBuilder: (data, setState) {
|
actionBuilder: (data, setState) {
|
||||||
final repo = data.item1;
|
final repo = data.item1;
|
||||||
@ -94,7 +96,9 @@ class GhRepoScreen extends StatelessWidget {
|
|||||||
},
|
},
|
||||||
bodyBuilder: (data, setState) {
|
bodyBuilder: (data, setState) {
|
||||||
final repo = data.item1;
|
final repo = data.item1;
|
||||||
final readme = data.item2;
|
final contributionFuture = data.item2;
|
||||||
|
final readmeFuture = data.item3;
|
||||||
|
|
||||||
final ref = branch == null ? repo.defaultBranchRef : repo.ref;
|
final ref = branch == null ? repo.defaultBranchRef : repo.ref;
|
||||||
final license = repo.licenseInfo?.spdxId ?? repo.licenseInfo?.name;
|
final license = repo.licenseInfo?.spdxId ?? repo.licenseInfo?.name;
|
||||||
|
|
||||||
@ -317,14 +321,10 @@ class GhRepoScreen extends StatelessWidget {
|
|||||||
TableViewItem(
|
TableViewItem(
|
||||||
leftIconData: Octicons.organization,
|
leftIconData: Octicons.organization,
|
||||||
text: Text('Contributors'),
|
text: Text('Contributors'),
|
||||||
rightWidget: FutureBuilder<String>(
|
rightWidget: FutureBuilder<int>(
|
||||||
future: context
|
future: contributionFuture,
|
||||||
.read<AuthModel>()
|
|
||||||
.ghClient
|
|
||||||
.getJSON('/repos/$owner/$name/stats/contributors')
|
|
||||||
.then((v) => v.length.toString()),
|
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
return Text(snapshot.data ?? '');
|
return Text(snapshot.data?.toString() ?? '');
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
url: '/github/$owner/$name/contributors',
|
url: '/github/$owner/$name/contributors',
|
||||||
@ -332,7 +332,16 @@ class GhRepoScreen extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
if (readme != null) MarkdownHtmlView(readme)
|
FutureBuilder<String>(
|
||||||
|
future: readmeFuture,
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
if (snapshot.data == null) {
|
||||||
|
return Container();
|
||||||
|
} else {
|
||||||
|
return MarkdownHtmlView(snapshot.data);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user