mirror of
https://github.com/git-touch/git-touch
synced 2025-02-28 09:17:56 +01:00
feat: show repository directory
This commit is contained in:
parent
7d6d1ecd46
commit
09f91f77ae
lib/screens
92
lib/screens/object.dart
Normal file
92
lib/screens/object.dart
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:git_touch/providers/settings.dart';
|
||||||
|
import 'package:git_touch/scaffolds/refresh.dart';
|
||||||
|
import 'package:git_touch/utils/utils.dart';
|
||||||
|
import 'package:git_touch/widgets/link.dart';
|
||||||
|
|
||||||
|
class ObjectScreen extends StatelessWidget {
|
||||||
|
final String owner;
|
||||||
|
final String name;
|
||||||
|
final String branch;
|
||||||
|
final List<String> paths;
|
||||||
|
|
||||||
|
ObjectScreen({
|
||||||
|
@required this.owner,
|
||||||
|
@required this.name,
|
||||||
|
this.branch = 'master',
|
||||||
|
this.paths = const [],
|
||||||
|
});
|
||||||
|
|
||||||
|
get expression => '$branch:' + paths.join('/');
|
||||||
|
|
||||||
|
IconData _buildIconData(item) {
|
||||||
|
switch (item['type']) {
|
||||||
|
case 'tree':
|
||||||
|
return Octicons.file_directory;
|
||||||
|
case 'blob':
|
||||||
|
return Octicons.file;
|
||||||
|
default:
|
||||||
|
return Octicons.link;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return RefreshScaffold(
|
||||||
|
title: Text(paths.join('/')),
|
||||||
|
onRefresh: () async {
|
||||||
|
var data = await SettingsProvider.of(context).query('''{
|
||||||
|
repository(owner: "$owner", name: "$name") {
|
||||||
|
object(expression: "$expression") {
|
||||||
|
... on Tree {
|
||||||
|
entries {
|
||||||
|
type
|
||||||
|
name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}''');
|
||||||
|
return data['repository']['object']['entries'];
|
||||||
|
},
|
||||||
|
bodyBuilder: (payload) {
|
||||||
|
return Column(
|
||||||
|
children: (payload as List).map((item) {
|
||||||
|
return Link(
|
||||||
|
screenBuilder: (context) {
|
||||||
|
switch (item['type']) {
|
||||||
|
case 'tree':
|
||||||
|
return ObjectScreen(
|
||||||
|
name: name,
|
||||||
|
owner: owner,
|
||||||
|
branch: branch,
|
||||||
|
paths: [...paths, item['name']],
|
||||||
|
);
|
||||||
|
case 'blob': // TODO:
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: Container(
|
||||||
|
padding: EdgeInsets.all(12),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
border: Border(
|
||||||
|
bottom: BorderSide(color: Colors.grey.shade100))),
|
||||||
|
child: Row(
|
||||||
|
children: <Widget>[
|
||||||
|
Icon(_buildIconData(item),
|
||||||
|
color: Color(0x80032f62), size: 20),
|
||||||
|
SizedBox(width: 4),
|
||||||
|
Expanded(
|
||||||
|
child:
|
||||||
|
Text(item['name'], style: TextStyle(fontSize: 16)))
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,7 @@ import 'dart:convert';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter_markdown/flutter_markdown.dart';
|
import 'package:flutter_markdown/flutter_markdown.dart';
|
||||||
|
import 'package:git_touch/screens/object.dart';
|
||||||
import 'package:share/share.dart';
|
import 'package:share/share.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
import '../providers/settings.dart';
|
import '../providers/settings.dart';
|
||||||
@ -185,7 +186,10 @@ class _RepoScreenState extends State<RepoScreen> {
|
|||||||
),
|
),
|
||||||
EntryItem(
|
EntryItem(
|
||||||
text: 'Files',
|
text: 'Files',
|
||||||
url: payload['url'] + '?files=1',
|
screenBuilder: (context) => ObjectScreen(
|
||||||
|
owner: widget.owner,
|
||||||
|
name: widget.name,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
EntryItem(
|
EntryItem(
|
||||||
text: 'Commits',
|
text: 'Commits',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user