Skip to content
代码片段 群组 项目
提交 13e79e2c 编辑于 作者: Neil Wang's avatar Neil Wang 提交者: Neil Wang
浏览文件

refactor: #845 projectRepositoryPage use ProjectProvider

上级 cacb0363
No related branches found
No related tags found
无相关合并请求
import 'package:jihu_gitlab_app/core/connection_provider/connection_provider.dart';
import 'package:jihu_gitlab_app/core/net/api.dart';
import 'package:jihu_gitlab_app/core/net/http_client.dart';
import 'package:jihu_gitlab_app/core/project_provider.dart';
import 'package:jihu_gitlab_app/modules/projects/repository/repository_file_content_fetcher.dart';
import 'package:jihu_gitlab_app/modules/projects/repository/repository_tree_data_fetcher.dart';
import 'package:jihu_gitlab_app/modules/projects/repository/repository_tree_item.dart';
......@@ -11,7 +12,6 @@ class ProjectRepositoryModel {
List<RepositoryTreeItem> _repositoryTreeItems = [];
late String _fullPath;
late String _projectName;
String? _destinationHost;
late RepositoryTreeDataFetcher _treeDataFetcher;
late RepositoryFileContentFetcher _fileContentFetcher;
int _itemLength = 0;
......@@ -19,12 +19,11 @@ class ProjectRepositoryModel {
bool _repositoryIsEmpty = true;
bool isLoading = false;
void init(String fullPath, String projectName, String? destinationHost) {
void init(String fullPath, String projectName) {
_fullPath = fullPath;
_projectName = projectName;
_destinationHost = destinationHost;
_treeDataFetcher = RepositoryTreeDataFetcher(_fullPath, _destinationHost);
_fileContentFetcher = RepositoryFileContentFetcher(_fullPath, _destinationHost);
_treeDataFetcher = RepositoryTreeDataFetcher(_fullPath, ProjectProvider().specifiedHost);
_fileContentFetcher = RepositoryFileContentFetcher(_fullPath, ProjectProvider().specifiedHost);
}
Future<void> getFirst5TreeItems() async {
......@@ -74,16 +73,14 @@ class ProjectRepositoryModel {
});
}
String get _host => _destinationHost == null ? ConnectionProvider.currentBaseUrl.get : _destinationHost!;
String get _host => ProjectProvider().specifiedHost ?? ConnectionProvider.currentBaseUrl.get;
String get _graphql => _destinationHost == null ? Api.graphql() : "$_destinationHost${Api.graphql()}";
String get _graphql => ProjectProvider().specifiedHost == null ? Api.graphql() : "${ProjectProvider().specifiedHost}${Api.graphql()}";
String get projectName => _projectName;
String get fullPath => _fullPath;
String? get destinationHost => _destinationHost;
String? get ref => _ref;
bool get showTheViewAllButton => _itemLength > _itemLimit;
......
......@@ -3,6 +3,7 @@ import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:jihu_gitlab_app/core/browser_launcher.dart';
import 'package:jihu_gitlab_app/core/project_provider.dart';
import 'package:jihu_gitlab_app/core/widgets/loading_view.dart';
import 'package:jihu_gitlab_app/core/widgets/tips_view.dart';
import 'package:jihu_gitlab_app/core/widgets/white_round_rect_container.dart';
......@@ -62,7 +63,7 @@ class _ProjectRepositoryPageState extends State<ProjectRepositoryPage> {
@override
void initState() {
_model.init(widget.fullPath, widget.projectName, widget.destinationHost);
_model.init(widget.fullPath, widget.projectName);
_controller = _createWebViewController();
_notifier = ValueNotifier(_isLoadingWebView);
_webViewHeightNotifier = ValueNotifier(_webViewHeight);
......@@ -113,7 +114,7 @@ class _ProjectRepositoryPageState extends State<ProjectRepositoryPage> {
List<Widget> _buildTreeItemViews(List<RepositoryTreeItem> items) {
List<Widget> views = [];
for (var item in items) {
views.add(RepositoryTreeItemView(fullPath: _model.fullPath, data: item, ref: _model.ref, destinationHost: _model.destinationHost));
views.add(RepositoryTreeItemView(fullPath: _model.fullPath, data: item, ref: _model.ref, destinationHost: ProjectProvider().specifiedHost));
views.add(const Divider(color: Color(0xFFEAEAEA), height: 1, thickness: 1));
}
if (!_model.showTheViewAllButton) views.removeLast();
......@@ -166,7 +167,7 @@ class _ProjectRepositoryPageState extends State<ProjectRepositoryPage> {
fullPath: _model.fullPath,
ref: _model.ref,
pageTitle: _model.projectName,
destinationHost: _model.destinationHost,
destinationHost: ProjectProvider().specifiedHost,
)));
}
......
......@@ -19,7 +19,7 @@ void main() {
when(client.post<dynamic>('/api/graphql', buildRequestBodyOfRepositoryTree(fullPath, ''))).thenAnswer((_) => Future(() => Response.of<dynamic>({})));
HttpClient.injectInstanceForTesting(client);
model = ProjectRepositoryModel();
model.init(fullPath, "JiHu Gitlab", null);
model.init(fullPath, "JiHu Gitlab");
ConnectionProvider().reset(Tester.jihuLabUser());
});
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册