Redesign Settings as grouped searchable page
Replace the tabbed Settings flow with a single grouped page that searches and lazily loads server-backed sections. Preserve existing settings behavior while adding inline loading and retry states and updating coverage for the new navigation model.
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/session/server_session.dart';
|
||||
import '../settings_layout.dart';
|
||||
import '../settings_server_load.dart';
|
||||
import '../settings_server_view.dart';
|
||||
import 'session_security_api.dart';
|
||||
|
||||
/// The server's sign-in security: a warning when its password predates the
|
||||
@@ -30,40 +35,47 @@ class SettingsSecuritySection extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _SettingsSecuritySectionState extends State<SettingsSecuritySection> {
|
||||
SessionSecurity? _security;
|
||||
// One load per endpoint, created in initState: rebuilding never refetches.
|
||||
late ServerLoad<SessionSecurity> _security = _loaderFor(widget.endpoint);
|
||||
String? _message;
|
||||
bool _busy = false;
|
||||
Timer? _endpointSettle;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_load();
|
||||
}
|
||||
// The view starts the load when the section mounts (a lazy page section).
|
||||
ServerLoad<SessionSecurity> _loaderFor(String endpoint) =>
|
||||
ServerLoad(() => loadSessionSecurity(endpoint));
|
||||
|
||||
@override
|
||||
void didUpdateWidget(SettingsSecuritySection oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.endpoint != widget.endpoint) _load();
|
||||
}
|
||||
|
||||
Future<void> _load() async {
|
||||
final endpoint = widget.endpoint;
|
||||
try {
|
||||
final security = await loadSessionSecurity(endpoint);
|
||||
if (!mounted || endpoint != widget.endpoint) return;
|
||||
setState(() {
|
||||
_security = security;
|
||||
_message = null;
|
||||
});
|
||||
} on SessionSecurityException catch (error) {
|
||||
if (!mounted || endpoint != widget.endpoint) return;
|
||||
setState(() {
|
||||
_security = null;
|
||||
_message = error.message;
|
||||
});
|
||||
// The endpoint follows the URL draft while it is typed; wait until it
|
||||
// settles so each keystroke does not start a request.
|
||||
if (oldWidget.endpoint != widget.endpoint) {
|
||||
_endpointSettle?.cancel();
|
||||
_endpointSettle = Timer(settingsEndpointDebounce, _switchEndpoint);
|
||||
}
|
||||
}
|
||||
|
||||
void _switchEndpoint() {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_security.dispose();
|
||||
_message = null;
|
||||
_security = _loaderFor(widget.endpoint);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_endpointSettle?.cancel();
|
||||
_security.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
static String _describe(Object error) => error is SessionSecurityException
|
||||
? error.message
|
||||
: 'Could not read sign-in security: $error';
|
||||
|
||||
Future<bool> _confirm() async {
|
||||
const title = Text('Sign out everywhere?');
|
||||
const body = Text(
|
||||
@@ -123,7 +135,6 @@ class _SettingsSecuritySectionState extends State<SettingsSecuritySection> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final security = _security;
|
||||
final button = OutlinedButton(
|
||||
key: const Key('settings-revoke-all'),
|
||||
onPressed: _busy ? null : _revokeAll,
|
||||
@@ -132,16 +143,22 @@ class _SettingsSecuritySectionState extends State<SettingsSecuritySection> {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
if (security != null && security.weakPassword)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: Text(
|
||||
key: const Key('settings-weak-password'),
|
||||
'This server\'s sign-in password is weak. '
|
||||
'${security.rule.isEmpty ? '' : '${security.rule} '}'
|
||||
'Run ./password on the server to choose a stronger one.',
|
||||
),
|
||||
),
|
||||
ServerSettingsView<SessionSecurity>(
|
||||
load: _security,
|
||||
describe: _describe,
|
||||
retryKey: const Key('settings-security-retry'),
|
||||
builder: (context, security) => security.weakPassword
|
||||
? Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: Text(
|
||||
key: const Key('settings-weak-password'),
|
||||
'This server\'s sign-in password is weak. '
|
||||
'${security.rule.isEmpty ? '' : '${security.rule} '}'
|
||||
'Run ./password on the server to choose a stronger one.',
|
||||
),
|
||||
)
|
||||
: const SizedBox.shrink(),
|
||||
),
|
||||
const Text(
|
||||
'Signing out everywhere ends every session of this server\'s web '
|
||||
'login. Changing the password with ./password does the same.',
|
||||
|
||||
Reference in New Issue
Block a user