mirror of
https://github.com/git-touch/git-touch
synced 2024-12-15 01:45:05 +01:00
refactor(gitlab): use webview to show markdown content
This commit is contained in:
parent
248b72ed1f
commit
6b9cc5a156
@ -177,9 +177,22 @@ class AuthModel with ChangeNotifier {
|
||||
return res.body;
|
||||
}
|
||||
|
||||
Future fetchGitlab(String p) async {
|
||||
final res = await http.get('${activeAccount.domain}/api/v4$p',
|
||||
headers: {'Private-Token': token});
|
||||
Future fetchGitlab(String p,
|
||||
{isPost = false, Map<String, dynamic> body = const {}}) async {
|
||||
http.Response res;
|
||||
if (isPost) {
|
||||
res = await http.post(
|
||||
'${activeAccount.domain}/api/v4$p',
|
||||
headers: {
|
||||
'Private-Token': token,
|
||||
HttpHeaders.contentTypeHeader: 'application/json'
|
||||
},
|
||||
body: jsonEncode(body),
|
||||
);
|
||||
} else {
|
||||
res = await http.get('${activeAccount.domain}/api/v4$p',
|
||||
headers: {'Private-Token': token});
|
||||
}
|
||||
final info = json.decode(utf8.decode(res.bodyBytes));
|
||||
if (info is Map && info['message'] != null) throw info['message'];
|
||||
return info;
|
||||
|
@ -7,8 +7,8 @@ import 'package:git_touch/scaffolds/refresh_stateful.dart';
|
||||
import 'package:git_touch/utils/utils.dart';
|
||||
import 'package:git_touch/widgets/app_bar_title.dart';
|
||||
import 'package:git_touch/widgets/entry_item.dart';
|
||||
import 'package:git_touch/widgets/html_view.dart';
|
||||
import 'package:git_touch/widgets/language_bar.dart';
|
||||
import 'package:git_touch/widgets/markdown_view.dart';
|
||||
import 'package:git_touch/widgets/repo_header.dart';
|
||||
import 'package:git_touch/widgets/table_view.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
@ -37,8 +37,16 @@ class GlProjectScreen extends StatelessWidget {
|
||||
final p = GitlabProject.fromJson(res[0]);
|
||||
String readme;
|
||||
if (p.readmeUrl != null) {
|
||||
readme = await auth.fetchWithGitlabToken(
|
||||
// we should get the markdown content, then render it
|
||||
// https://gitlab.com/gitlab-org/gitlab/-/issues/16335
|
||||
final md = await auth.fetchWithGitlabToken(
|
||||
p.readmeUrl.replaceFirst(r'/blob/', '/raw/'));
|
||||
final res = await auth.fetchGitlab('/markdown', isPost: true, body: {
|
||||
'text': md,
|
||||
'gfm': true,
|
||||
'project': '${p.namespace.name}/${p.name}'
|
||||
});
|
||||
readme = '<div class="markdown-body">' + res['html'] + '</div>';
|
||||
}
|
||||
return Tuple5(
|
||||
p,
|
||||
@ -146,13 +154,7 @@ class GlProjectScreen extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
CommonStyle.verticalGap,
|
||||
if (t.item5 != null)
|
||||
Container(
|
||||
padding: CommonStyle.padding,
|
||||
color: theme.palette.background,
|
||||
child: MarkdownView(t.item5),
|
||||
),
|
||||
CommonStyle.verticalGap,
|
||||
if (t.item5 != null) MarkdownHtmlView(t.item5)
|
||||
],
|
||||
);
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user