reset on error
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import 'package:flutter/material.dart' show GlobalKey, NavigatorState;
|
||||
|
||||
const addMountTitle = 'New Mount Settings';
|
||||
const appTitle = 'Repertory Management Portal';
|
||||
const databaseTypeList = ['rocksdb', 'sqlite'];
|
||||
@@ -7,3 +9,5 @@ const padding = 15.0;
|
||||
const protocolTypeList = ['http', 'https'];
|
||||
const providerTypeList = ['Encrypt', 'Remote', 'S3', 'Sia'];
|
||||
const ringBufferSizeList = ['128', '256', '512', '1024', '2048'];
|
||||
|
||||
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
|
||||
|
@@ -30,6 +30,7 @@ class _MyAppState extends State<MyApp> {
|
||||
);
|
||||
|
||||
return MaterialApp(
|
||||
navigatorKey: constants.navigatorKey,
|
||||
themeMode: ThemeMode.dark,
|
||||
darkTheme: ThemeData(
|
||||
useMaterial3: true,
|
||||
|
@@ -3,11 +3,13 @@ import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:repertory/helpers.dart';
|
||||
import 'package:repertory/models/mount_list.dart';
|
||||
import 'package:repertory/types/mount_config.dart';
|
||||
|
||||
class Mount with ChangeNotifier {
|
||||
final MountConfig mountConfig;
|
||||
Mount(this.mountConfig, {isAdd = false}) {
|
||||
final MountList? _mountList;
|
||||
Mount(this.mountConfig, this._mountList, {isAdd = false}) {
|
||||
if (isAdd) {
|
||||
return;
|
||||
}
|
||||
@@ -28,6 +30,11 @@ class Mount with ChangeNotifier {
|
||||
),
|
||||
);
|
||||
|
||||
if (response.statusCode == 404) {
|
||||
_mountList?.reset();
|
||||
return;
|
||||
}
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
return;
|
||||
}
|
||||
@@ -50,6 +57,11 @@ class Mount with ChangeNotifier {
|
||||
),
|
||||
);
|
||||
|
||||
if (response.statusCode == 404) {
|
||||
_mountList?.reset();
|
||||
return;
|
||||
}
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
return;
|
||||
}
|
||||
@@ -108,6 +120,11 @@ class Mount with ChangeNotifier {
|
||||
),
|
||||
);
|
||||
|
||||
if (response.statusCode == 404) {
|
||||
_mountList?.reset();
|
||||
return null;
|
||||
}
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
return null;
|
||||
}
|
||||
|
@@ -2,7 +2,9 @@ import 'dart:convert';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart' show ModalRoute;
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:repertory/constants.dart' as constants;
|
||||
import 'package:repertory/helpers.dart';
|
||||
import 'package:repertory/models/mount.dart';
|
||||
import 'package:repertory/types/mount_config.dart';
|
||||
@@ -48,15 +50,21 @@ class MountList with ChangeNotifier {
|
||||
Uri.parse('${getBaseUri()}/api/v1/mount_list'),
|
||||
);
|
||||
|
||||
if (response.statusCode == 404) {
|
||||
reset();
|
||||
return;
|
||||
}
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<Mount> nextList = [];
|
||||
|
||||
jsonDecode(response.body).forEach((type, value) {
|
||||
nextList.addAll(
|
||||
value
|
||||
.map((name) => Mount(MountConfig(type: type, name: name)))
|
||||
.map((name) => Mount(MountConfig(type: type, name: name), this))
|
||||
.toList(),
|
||||
);
|
||||
});
|
||||
@@ -100,6 +108,19 @@ class MountList with ChangeNotifier {
|
||||
return _fetch();
|
||||
}
|
||||
|
||||
Future<void> reset() async {
|
||||
_mountList = [];
|
||||
notifyListeners();
|
||||
|
||||
_fetch();
|
||||
|
||||
if (constants.navigatorKey.currentContext == null ||
|
||||
ModalRoute.of(constants.navigatorKey.currentContext!)?.settings.name !=
|
||||
'/') {
|
||||
constants.navigatorKey.currentState?.pushReplacementNamed('/');
|
||||
}
|
||||
}
|
||||
|
||||
void remove(String name) {
|
||||
_mountList.removeWhere((item) => item.name == name);
|
||||
|
||||
|
@@ -219,6 +219,7 @@ class _AddMountScreenState extends State<AddMountScreen> {
|
||||
settings: _settings[mountType],
|
||||
type: mountType,
|
||||
),
|
||||
null,
|
||||
isAdd: true,
|
||||
);
|
||||
});
|
||||
|
Reference in New Issue
Block a user