mirror of
https://github.com/git-touch/git-touch
synced 2025-01-19 02:40:05 +01:00
feat: github compare screen (#86)
This commit is contained in:
parent
8a1180dae8
commit
8f5dafd2d0
@ -350,3 +350,14 @@ class GithubFilesItem {
|
||||
factory GithubFilesItem.fromJson(Map<String, dynamic> json) =>
|
||||
_$GithubFilesItemFromJson(json);
|
||||
}
|
||||
|
||||
@JsonSerializable(fieldRename: FieldRename.snake)
|
||||
class GithubComparisonItem {
|
||||
List<GithubFilesItem> files;
|
||||
String status;
|
||||
int aheadBy;
|
||||
int behindBy;
|
||||
GithubComparisonItem();
|
||||
factory GithubComparisonItem.fromJson(Map<String, dynamic> json) =>
|
||||
_$GithubComparisonItemFromJson(json);
|
||||
}
|
||||
|
@ -500,3 +500,24 @@ Map<String, dynamic> _$GithubFilesItemToJson(GithubFilesItem instance) =>
|
||||
'changes': instance.changes,
|
||||
'patch': instance.patch,
|
||||
};
|
||||
|
||||
GithubComparisonItem _$GithubComparisonItemFromJson(Map<String, dynamic> json) {
|
||||
return GithubComparisonItem()
|
||||
..files = (json['files'] as List)
|
||||
?.map((e) => e == null
|
||||
? null
|
||||
: GithubFilesItem.fromJson(e as Map<String, dynamic>))
|
||||
?.toList()
|
||||
..status = json['status'] as String
|
||||
..aheadBy = json['ahead_by'] as int
|
||||
..behindBy = json['behind_by'] as int;
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$GithubComparisonItemToJson(
|
||||
GithubComparisonItem instance) =>
|
||||
<String, dynamic>{
|
||||
'files': instance.files,
|
||||
'status': instance.status,
|
||||
'ahead_by': instance.aheadBy,
|
||||
'behind_by': instance.behindBy,
|
||||
};
|
||||
|
@ -38,6 +38,7 @@ import 'package:git_touch/screens/settings.dart';
|
||||
import 'package:git_touch/screens/gh_user.dart';
|
||||
import 'package:git_touch/screens/gh_users.dart';
|
||||
import 'package:git_touch/screens/gh_user_organization.dart';
|
||||
import 'package:git_touch/screens/gh_compare.dart';
|
||||
// import 'package:git_touch/screens/gh_gists.dart';
|
||||
|
||||
class RouterScreen {
|
||||
@ -77,6 +78,7 @@ class GithubRouter {
|
||||
GithubRouter.watchers,
|
||||
GithubRouter.contributors,
|
||||
GithubRouter.files,
|
||||
GithubRouter.compare,
|
||||
];
|
||||
static final user = RouterScreen('/:login', (_, p) {
|
||||
final login = p['login'].first;
|
||||
@ -133,6 +135,10 @@ class GithubRouter {
|
||||
p['name'].first,
|
||||
int.parse(p['number'].first),
|
||||
));
|
||||
static final compare = RouterScreen(
|
||||
'/:owner/:name/compare/:before/:head',
|
||||
(context, p) => GhComparisonScreen(p['owner'].first, p['name'].first,
|
||||
p['before'].first, p['head'].first));
|
||||
static final commits = RouterScreen('/:owner/:name/commits',
|
||||
(context, p) => GhCommitsScreen(p['owner'].first, p['name'].first));
|
||||
static final object = RouterScreen('/:owner/:name/blob/:ref', (_, p) {
|
||||
|
55
lib/screens/gh_compare.dart
Normal file
55
lib/screens/gh_compare.dart
Normal file
@ -0,0 +1,55 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:git_touch/models/github.dart';
|
||||
import 'package:git_touch/scaffolds/refresh_stateful.dart';
|
||||
import 'package:git_touch/widgets/app_bar_title.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:git_touch/widgets/files_item.dart';
|
||||
import 'package:git_touch/models/auth.dart';
|
||||
import 'package:git_touch/widgets/action_button.dart';
|
||||
|
||||
class GhComparisonScreen extends StatelessWidget {
|
||||
final String owner;
|
||||
final String name;
|
||||
final String before;
|
||||
final String head;
|
||||
GhComparisonScreen(this.owner, this.name, this.before, this.head);
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
return RefreshStatefulScaffold(
|
||||
title: AppBarTitle('Files'),
|
||||
fetchData: () async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final res = await auth.ghClient.getJSON(
|
||||
'/repos/$owner/$name/compare/$before...$head',
|
||||
convert: (vs) => GithubComparisonItem.fromJson(vs),
|
||||
);
|
||||
print('/repos/$owner/$name/compare/$before...$head');
|
||||
return res.files;
|
||||
},
|
||||
actionBuilder: (v, _) {
|
||||
return ActionButton(
|
||||
title: 'Actions',
|
||||
items: [
|
||||
...ActionItem.getUrlActions(
|
||||
'https://github.com/$owner/$name/compare/$before...$head'),
|
||||
],
|
||||
);
|
||||
},
|
||||
bodyBuilder: (v, _) {
|
||||
return Wrap(
|
||||
children: v
|
||||
.map<Widget>((vs) => FilesItem(
|
||||
filename: vs.filename,
|
||||
additions: vs.additions,
|
||||
deletions: vs.deletions,
|
||||
status: vs.status,
|
||||
changes: vs.changes,
|
||||
patch: vs.patch,
|
||||
))
|
||||
.toList(),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
@ -110,7 +110,7 @@ class EventItem extends StatelessWidget {
|
||||
final theme = Provider.of<ThemeModel>(context);
|
||||
return Link(
|
||||
url:
|
||||
'https://github.com/${e.repoOwner}/${e.repoName}/compare/${e.payload.before}...${e.payload.head}',
|
||||
'/${e.repoOwner}/${e.repoName}/compare/${e.payload.before}/${e.payload.head}',
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
|
Loading…
Reference in New Issue
Block a user