Better files list
All checks were successful
ci/woodpecker/push/flutterBuild Pipeline was successful
All checks were successful
ci/woodpecker/push/flutterBuild Pipeline was successful
This commit is contained in:
parent
ec8f4a4b25
commit
c272d8c888
4 changed files with 139 additions and 75 deletions
28
lib/cubit/file_list_load_bloc.dart
Normal file
28
lib/cubit/file_list_load_bloc.dart
Normal file
|
@ -0,0 +1,28 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:gitea_client/model/File.dart';
|
||||
|
||||
import '../service/gitea_service.dart';
|
||||
|
||||
part 'file_list_load_event.dart';
|
||||
|
||||
part 'file_list_load_state.dart';
|
||||
|
||||
class FileListLoadBloc extends Bloc<FileListLoadEvent, FileListLoadState> {
|
||||
final GiteaService giteaService;
|
||||
FileListLoadBloc({required this.giteaService}) : super(const FileListLoadState()) {
|
||||
on<FileListLoadPathEvent>(_FileListLoadState);
|
||||
}
|
||||
|
||||
Future<void> _FileListLoadState(
|
||||
FileListLoadPathEvent event, Emitter<FileListLoadState> emit) async {
|
||||
if(event.repoName.isEmpty) return;
|
||||
emit(FileListLoadState(status: FileLoadStatus.loading));
|
||||
final fileListResult = await giteaService.getFolder(
|
||||
event.repoName.split('/')[0], event.repoName.split('/')[1], event.path);
|
||||
return emit(FileListLoadState(status: FileLoadStatus.success,files: fileListResult,path: event.path,repoFullname: event.repoName));
|
||||
|
||||
}
|
||||
}
|
15
lib/cubit/file_list_load_event.dart
Normal file
15
lib/cubit/file_list_load_event.dart
Normal file
|
@ -0,0 +1,15 @@
|
|||
part of 'file_list_load_bloc.dart';
|
||||
|
||||
abstract class FileListLoadEvent extends Equatable {
|
||||
const FileListLoadEvent();
|
||||
}
|
||||
|
||||
class FileListLoadPathEvent extends FileListLoadEvent {
|
||||
|
||||
final repoName;
|
||||
final path;
|
||||
const FileListLoadPathEvent(this.path, this.repoName);
|
||||
@override
|
||||
List<Object?> get props => [path,repoName];
|
||||
|
||||
}
|
15
lib/cubit/file_list_load_state.dart
Normal file
15
lib/cubit/file_list_load_state.dart
Normal file
|
@ -0,0 +1,15 @@
|
|||
part of 'file_list_load_bloc.dart';
|
||||
|
||||
enum FileLoadStatus { loading, success,failure }
|
||||
|
||||
class FileListLoadState extends Equatable {
|
||||
const FileListLoadState({this.path="", this.repoFullname ="", this.error_message = null, this.files= const <RepoFile>[],this.status = FileLoadStatus.loading});
|
||||
final FileLoadStatus status;
|
||||
final String path;
|
||||
final String repoFullname;
|
||||
final String? error_message;
|
||||
final List<RepoFile> files;
|
||||
|
||||
@override
|
||||
List<Object> get props => [path,repoFullname];
|
||||
}
|
|
@ -2,7 +2,9 @@ import 'dart:convert';
|
|||
|
||||
import 'package:badges/badges.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_markdown/flutter_markdown.dart';
|
||||
import 'package:gitea_client/cubit/file_list_load_bloc.dart';
|
||||
import 'package:gitea_client/model/repository.dart';
|
||||
import 'package:gitea_client/model/user.dart';
|
||||
import 'package:gitea_client/service/gitea_service.dart';
|
||||
|
@ -147,11 +149,16 @@ class _RepoHome extends State<RepoHome> {
|
|||
width: (media.width > 600)
|
||||
? media.width * 0.6
|
||||
: media.width * 0.9,
|
||||
|
||||
height: media.height - padding.top - padding.bottom -kToolbarHeight -kBottomNavigationBarHeight-30,
|
||||
height: media.height -
|
||||
padding.top -
|
||||
padding.bottom -
|
||||
kToolbarHeight -
|
||||
kBottomNavigationBarHeight -
|
||||
30,
|
||||
child: Column(
|
||||
children: [
|
||||
Expanded(child: Markdown(selectable: true, data: content)),
|
||||
Expanded(
|
||||
child: Markdown(selectable: true, data: content)),
|
||||
],
|
||||
)),
|
||||
);
|
||||
|
@ -201,25 +208,29 @@ class _RepoFiles extends State<RepoFiles> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FutureBuilder<List<RepoFile>>(
|
||||
future: readmeRequest,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasError) {
|
||||
return Center(
|
||||
child: Column(
|
||||
children: [
|
||||
Text("No Readme file found!",
|
||||
style: Theme.of(context).textTheme.headline6),
|
||||
],
|
||||
),
|
||||
);
|
||||
} else if (snapshot.hasData) {
|
||||
var files = (path == "/")
|
||||
return BlocProvider(
|
||||
create: (context) {
|
||||
return FileListLoadBloc(
|
||||
giteaService: GiteaService(apiAccess: widget.user.apiAccess))
|
||||
..add(FileListLoadPathEvent("/", widget.repo.fullName!));
|
||||
},
|
||||
child: BlocBuilder<FileListLoadBloc, FileListLoadState>(
|
||||
builder: (context, state) {
|
||||
switch (state.status) {
|
||||
case FileLoadStatus.failure:
|
||||
String error_message = state.error_message!;
|
||||
return Center(child: Text('failed to fetch $error_message'));
|
||||
case FileLoadStatus.success:
|
||||
if (state.files.isEmpty) {
|
||||
return const Center(
|
||||
child: Text('No files in current directory'));
|
||||
}
|
||||
var files = (state.path == "/")
|
||||
? []
|
||||
: [
|
||||
RepoFile(
|
||||
name: "..",
|
||||
path: path,
|
||||
path: state.path,
|
||||
sha: "",
|
||||
type: "dir",
|
||||
size: 0,
|
||||
|
@ -228,15 +239,13 @@ class _RepoFiles extends State<RepoFiles> {
|
|||
gitUrl: "",
|
||||
lLinks: Links(self: "", git: "", html: ""))
|
||||
];
|
||||
files.addAll(snapshot.data!);
|
||||
|
||||
files.addAll(state.files);
|
||||
return ListView.builder(
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return FileListItem(
|
||||
file: files[index],
|
||||
onTap: () => {
|
||||
if (files[index].type == "dir")
|
||||
setState(() {
|
||||
onTap: () {
|
||||
if (files[index].type == "dir") {
|
||||
String prev = files[index].path.contains("/")
|
||||
? files[index].path.substring(
|
||||
0, files[index].path.lastIndexOf('/'))
|
||||
|
@ -244,30 +253,27 @@ class _RepoFiles extends State<RepoFiles> {
|
|||
path = (files[index].name == "..")
|
||||
? prev
|
||||
: files[index].path;
|
||||
readmeRequest = null;
|
||||
readmeRequest = giteaService.getFolder(
|
||||
widget.repo.owner.username!,
|
||||
widget.repo.name,
|
||||
path);
|
||||
})
|
||||
else
|
||||
context.read<FileListLoadBloc>().add(FileListLoadPathEvent(path,widget.repo.fullName!));
|
||||
} else {
|
||||
Navigator.of(context).pushNamed("/fileview",
|
||||
arguments: CodePageData(
|
||||
files[index].path,
|
||||
widget.repo.name,
|
||||
widget.repo.owner.username!,
|
||||
widget.user))
|
||||
});
|
||||
widget.user));
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
itemCount: files.length,
|
||||
controller: _scrollController,
|
||||
);
|
||||
} else {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
default:
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -306,7 +312,7 @@ class _RepoIssues extends State<RepoIssues> {
|
|||
Widget build(BuildContext context) {
|
||||
return DefaultTabController(
|
||||
length: 2,
|
||||
child:DefaultTabController(
|
||||
child: DefaultTabController(
|
||||
length: 2,
|
||||
child: Scaffold(
|
||||
appBar: PreferredSize(
|
||||
|
@ -328,10 +334,10 @@ class _RepoIssues extends State<RepoIssues> {
|
|||
body: TabBarView(
|
||||
children: <Widget>[
|
||||
Column(
|
||||
children: const [Text("Lunches Page")],
|
||||
children: const [Text("Open Issues")],
|
||||
),
|
||||
Column(
|
||||
children: const [ Text("Cart Page")],
|
||||
children: const [Text("Closed Issues")],
|
||||
)
|
||||
],
|
||||
),
|
||||
|
|
Loading…
Reference in a new issue