2019-10-03 06:16:44 +02:00
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2020-01-07 11:33:41 +01:00
|
|
|
import 'package:git_touch/graphql/gh.dart';
|
2019-10-03 06:16:44 +02:00
|
|
|
import 'package:git_touch/models/auth.dart';
|
|
|
|
import 'package:git_touch/models/theme.dart';
|
|
|
|
import 'package:git_touch/scaffolds/common.dart';
|
|
|
|
import 'package:git_touch/utils/utils.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
2019-12-13 06:13:45 +01:00
|
|
|
final issueAddRouter = RouterScreen(
|
2020-01-01 10:00:26 +01:00
|
|
|
'/:owner/:name/issues/new',
|
|
|
|
(context, params) {
|
|
|
|
return IssueFormScreen(params['owner'].first, params['name'].first);
|
|
|
|
},
|
|
|
|
);
|
2019-12-13 06:13:45 +01:00
|
|
|
|
2019-10-03 06:16:44 +02:00
|
|
|
class IssueFormScreen extends StatefulWidget {
|
|
|
|
final String owner;
|
|
|
|
final String name;
|
|
|
|
|
|
|
|
IssueFormScreen(this.owner, this.name);
|
|
|
|
|
|
|
|
@override
|
|
|
|
_IssueFormScreenState createState() => _IssueFormScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _IssueFormScreenState extends State<IssueFormScreen> {
|
2020-01-07 11:33:41 +01:00
|
|
|
var _title = '';
|
|
|
|
var _body = '';
|
2019-10-03 06:16:44 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return CommonScaffold(
|
|
|
|
title: Text('Submit an issue'),
|
|
|
|
body: Column(
|
|
|
|
children: <Widget>[
|
|
|
|
Padding(
|
|
|
|
padding: CommonStyle.padding,
|
|
|
|
child: CupertinoTextField(
|
|
|
|
placeholder: 'Title',
|
|
|
|
onChanged: (v) {
|
|
|
|
setState(() {
|
|
|
|
_title = v;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: CommonStyle.padding,
|
|
|
|
child: CupertinoTextField(
|
|
|
|
placeholder: 'Body',
|
|
|
|
onChanged: (v) {
|
|
|
|
setState(() {
|
|
|
|
_body = v;
|
|
|
|
});
|
|
|
|
},
|
2019-10-03 06:57:21 +02:00
|
|
|
maxLines: 10,
|
2019-10-03 06:16:44 +02:00
|
|
|
),
|
|
|
|
),
|
2019-10-03 06:57:21 +02:00
|
|
|
CupertinoButton.filled(
|
2019-10-03 06:16:44 +02:00
|
|
|
child: Text('Submit'),
|
|
|
|
onPressed: () async {
|
2020-01-07 11:33:41 +01:00
|
|
|
final auth = Provider.of<AuthModel>(context);
|
|
|
|
final theme = Provider.of<ThemeModel>(context);
|
|
|
|
final r0 = await auth.gqlClient.execute(
|
|
|
|
GhRepoIdQuery(
|
|
|
|
variables:
|
|
|
|
GhRepoIdArguments(owner: widget.owner, name: widget.name),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
final res = await auth.gqlClient.execute(GhCreateIssueQuery(
|
|
|
|
variables: GhCreateIssueArguments(
|
|
|
|
repoId: r0.data.repository.id, title: _title, body: _body),
|
|
|
|
));
|
|
|
|
final issue = res.data.createIssue.issue;
|
|
|
|
await theme.push(
|
|
|
|
context,
|
|
|
|
'/${issue.repository.owner.login}/${issue.repository.name}/issues/${issue.number}',
|
|
|
|
replace: true,
|
|
|
|
);
|
2019-10-03 06:16:44 +02:00
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|