mirror of
https://github.com/git-touch/git-touch
synced 2024-12-18 19:22:54 +01:00
improvement: sort tree items
This commit is contained in:
parent
71bd29e041
commit
146f731c95
@ -50,17 +50,19 @@ class GiteaObjectScreen extends StatelessWidget {
|
||||
},
|
||||
bodyBuilder: (p, _) {
|
||||
if (p is List) {
|
||||
return ObjectTree(
|
||||
items: p.map((t) {
|
||||
final v = GiteaTree.fromJson(t);
|
||||
return ObjectTreeItem(
|
||||
final items = p.map((t) => GiteaTree.fromJson(t)).toList();
|
||||
items.sort((a, b) {
|
||||
return sortByKey('dir', a.type, b.type);
|
||||
});
|
||||
return ObjectTree(items: [
|
||||
for (var v in items)
|
||||
ObjectTreeItem(
|
||||
name: v.name,
|
||||
type: v.type,
|
||||
size: v.type == 'file' ? v.size : null,
|
||||
url: '/gitea/$owner/$name/blob?path=${v.path.urlencode}',
|
||||
);
|
||||
}),
|
||||
);
|
||||
),
|
||||
]);
|
||||
} else {
|
||||
final v = GiteaBlob.fromJson(p);
|
||||
return BlobView(v.name, base64Text: v.content);
|
||||
|
@ -57,19 +57,11 @@ class ObjectScreen extends StatelessWidget {
|
||||
),
|
||||
));
|
||||
final data = res.data.repository.object;
|
||||
|
||||
if (data.resolveType == 'Tree') {
|
||||
(data as GhObjectTree).entries.sort((a, b) {
|
||||
if (a.type == 'tree' && b.type == 'blob') {
|
||||
return -1;
|
||||
}
|
||||
if (a.type == 'blob' && b.type == 'tree') {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
return sortByKey('tree', a.type, b.type);
|
||||
});
|
||||
}
|
||||
|
||||
return data;
|
||||
},
|
||||
actionBuilder: (data, _) {
|
||||
|
@ -194,3 +194,9 @@ String convertBase64ToString(String input) {
|
||||
final bits = base64.decode(input.replaceAll('\n', ''));
|
||||
return utf8.decode(bits);
|
||||
}
|
||||
|
||||
int sortByKey<T>(T key, T a, T b) {
|
||||
if (a == key && b != key) return -1;
|
||||
if (a != key && b == key) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user