mirror of
https://github.com/git-touch/git-touch
synced 2025-01-31 08:04:51 +01:00
feat(gitea): main screen
This commit is contained in:
parent
62c4c380f8
commit
76c6948b05
@ -3,6 +3,7 @@ import 'package:flutter/cupertino.dart';
|
||||
import 'package:git_touch/models/auth.dart';
|
||||
import 'package:git_touch/models/notification.dart';
|
||||
import 'package:git_touch/models/theme.dart';
|
||||
import 'package:git_touch/screens/gitea_user.dart';
|
||||
import 'package:git_touch/screens/gitlab_explore.dart';
|
||||
import 'package:git_touch/screens/gitlab_project.dart';
|
||||
import 'package:git_touch/screens/gitlab_todos.dart';
|
||||
@ -55,6 +56,14 @@ class _HomeState extends State<Home> {
|
||||
return GitlabUserScreen(null);
|
||||
}
|
||||
break;
|
||||
case PlatformType.gitea:
|
||||
switch (index) {
|
||||
case 0:
|
||||
return GiteaUserScreen(null);
|
||||
case 1:
|
||||
return GiteaUserScreen(null);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -117,6 +126,17 @@ class _HomeState extends State<Home> {
|
||||
title: Text('Me'),
|
||||
),
|
||||
];
|
||||
case PlatformType.gitea:
|
||||
return [
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.explore),
|
||||
title: Text('Explore'),
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.person),
|
||||
title: Text('Me'),
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
import 'dart:io';
|
||||
import 'dart:convert';
|
||||
import 'dart:async';
|
||||
import 'package:git_touch/models/gitea.dart';
|
||||
import 'package:git_touch/utils/request_serilizer.dart';
|
||||
import 'package:gql_http_link/gql_http_link.dart';
|
||||
import 'package:artemis/artemis.dart';
|
||||
@ -21,6 +22,7 @@ const clientId = 'df930d7d2e219f26142a';
|
||||
class PlatformType {
|
||||
static const github = 'github';
|
||||
static const gitlab = 'gitlab';
|
||||
static const gitea = 'gitea';
|
||||
}
|
||||
|
||||
class DataWithPage<T> {
|
||||
@ -161,6 +163,35 @@ class AuthModel with ChangeNotifier {
|
||||
return DataWithPage(info, next, next != null);
|
||||
}
|
||||
|
||||
Future loginToGitea(String domain, String token) async {
|
||||
try {
|
||||
loading = true;
|
||||
notifyListeners();
|
||||
|
||||
final res = await http.get('$domain/api/v1/user',
|
||||
headers: {'Authorization': 'token $token'});
|
||||
final info = json.decode(res.body);
|
||||
if (info['message'] != null) {
|
||||
throw info['message'];
|
||||
}
|
||||
final user = GiteaUser.fromJson(info);
|
||||
|
||||
await _addAccount(Account(
|
||||
platform: PlatformType.gitea,
|
||||
domain: domain,
|
||||
token: token,
|
||||
login: user.login,
|
||||
avatarUrl: user.avatarUrl,
|
||||
));
|
||||
} catch (err) {
|
||||
Fimber.e('loginToGitea failed', ex: err);
|
||||
// TODO: show errors
|
||||
} finally {
|
||||
loading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
Future fetchGitea(String p) async {
|
||||
final res = await http.get('https://try.gitea.io' + '/api/v1' + p,
|
||||
headers: {'Authorization': ''});
|
||||
|
@ -9,23 +9,25 @@ import 'package:provider/provider.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
|
||||
class GiteaUserScreen extends StatelessWidget {
|
||||
final String username;
|
||||
|
||||
GiteaUserScreen(this.username);
|
||||
final String login;
|
||||
GiteaUserScreen(this.login);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return RefreshStatefulScaffold<
|
||||
Tuple2<GiteaUser, Iterable<GiteaRepository>>>(
|
||||
title: Text('User'),
|
||||
title: Text(login == null ? 'Me' : 'User'),
|
||||
fetchData: () async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final u = login ?? auth.activeAccount.login;
|
||||
final items = await Future.wait([
|
||||
auth.fetchGitea('/users/$username'),
|
||||
auth.fetchGitea('/users/$username/repos'),
|
||||
auth.fetchGitea('/users/$u'),
|
||||
auth.fetchGitea('/users/$u/repos'),
|
||||
]);
|
||||
return Tuple2(GiteaUser.fromJson(items[0]),
|
||||
(items[1] as List).map((v) => GiteaRepository.fromJson(v)));
|
||||
return Tuple2(
|
||||
GiteaUser.fromJson(items[0]),
|
||||
(items[1] as List).map((v) => GiteaRepository.fromJson(v)),
|
||||
);
|
||||
},
|
||||
bodyBuilder: (data, _) {
|
||||
final user = data.item1;
|
||||
|
@ -22,6 +22,8 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
String _token = '';
|
||||
String _gitlabToken = '';
|
||||
String _gitlabDomain = 'https://gitlab.com';
|
||||
String _giteaToken = '';
|
||||
String _giteaDomain = 'https://try.gitea.io';
|
||||
|
||||
Widget _buildAccountItem(int index) {
|
||||
final theme = Provider.of<ThemeModel>(context);
|
||||
@ -146,7 +148,7 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
// _buildAddItem(
|
||||
// text: 'GitLab Account by Token',
|
||||
// onTap: () async {
|
||||
// var result =
|
||||
// final result =
|
||||
// await Provider.of<ThemeModel>(context).showConfirm(
|
||||
// context,
|
||||
// Column(
|
||||
@ -193,6 +195,44 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
// }
|
||||
// }
|
||||
// },
|
||||
// ),
|
||||
// _buildAddItem(
|
||||
// text: 'Gitea Account by Token',
|
||||
// onTap: () async {
|
||||
// final result =
|
||||
// await Provider.of<ThemeModel>(context).showConfirm(
|
||||
// context,
|
||||
// Column(
|
||||
// children: <Widget>[
|
||||
// CupertinoTextField(
|
||||
// placeholder: 'Domain',
|
||||
// onChanged: (v) {
|
||||
// setState(() {
|
||||
// _giteaDomain = v;
|
||||
// });
|
||||
// },
|
||||
// ),
|
||||
// SizedBox(height: 8),
|
||||
// CupertinoTextField(
|
||||
// placeholder: 'Access token',
|
||||
// onChanged: (v) {
|
||||
// setState(() {
|
||||
// _giteaToken = v;
|
||||
// });
|
||||
// },
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// );
|
||||
// if (result == true) {
|
||||
// try {
|
||||
// await auth.loginToGitea(_giteaDomain, _giteaToken);
|
||||
// } catch (err) {
|
||||
// Provider.of<ThemeModel>(context).showConfirm(
|
||||
// context, Text('Token invalid: $err'));
|
||||
// }
|
||||
// }
|
||||
// },
|
||||
// )
|
||||
],
|
||||
),
|
||||
|
Loading…
x
Reference in New Issue
Block a user