clean up select server page

This commit is contained in:
Henry Hiles 2026-06-05 16:54:14 -04:00
commit ceb765e805
Signed by: Henry-Hiles
SSH key fingerprint: SHA256:VKQUdS31Q90KvX7EkKMHMBpUspcmItAh86a+v7PGiIs

View file

@ -8,7 +8,6 @@ import "package:nexus/models/homeserver.dart";
import "package:nexus/pages/login_page.dart"; import "package:nexus/pages/login_page.dart";
import "package:nexus/widgets/appbar.dart"; import "package:nexus/widgets/appbar.dart";
import "package:nexus/widgets/divider_text.dart"; import "package:nexus/widgets/divider_text.dart";
import "package:nexus/widgets/loading.dart";
class SelectServerPage extends HookConsumerWidget { class SelectServerPage extends HookConsumerWidget {
const SelectServerPage({super.key}); const SelectServerPage({super.key});
@ -16,57 +15,54 @@ class SelectServerPage extends HookConsumerWidget {
@override @override
Widget build(BuildContext context, WidgetRef ref) { Widget build(BuildContext context, WidgetRef ref) {
final theme = Theme.of(context); final theme = Theme.of(context);
final client = ref.watch(ClientController.provider.notifier);
final hasError = useState(false);
final isLoading = useState(false);
final homeserverFocusNode = useFocusNode();
final launch = ref.watch(LaunchHelper.provider).launchUrl; final launch = ref.watch(LaunchHelper.provider).launchUrl;
final isLoading = useState(false);
final homeserverUrl = useTextEditingController(); final homeserverUrl = useTextEditingController();
Future<void> setHomeserver(Uri? newHomeserver) async { Future<void> setHomeserver(Uri? newHomeserver) async {
isLoading.value = true; isLoading.value = true;
try {
if (newHomeserver?.hasScheme == false) { if (newHomeserver?.hasScheme == false) {
newHomeserver = Uri.https(newHomeserver!.path); newHomeserver = Uri.https(newHomeserver!.path);
} }
final newUrl = newHomeserver == null final newUrl = newHomeserver == null
? null ? null
: await client.discoverHomeserver(newHomeserver); : await ref
.watch(ClientController.provider.notifier)
.discoverHomeserver(newHomeserver);
if (context.mounted) { if (context.mounted) {
if (newUrl == null) { if (newUrl == null) {
hasError.value = true;
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
SnackBar( SnackBar(
content: Text( content: Text(
"Homeserver verification failed. Is your homeserver down?", "Homeserver verification failed. Is your homeserver down?",
style: TextStyle(color: theme.colorScheme.onErrorContainer), style: .new(color: theme.colorScheme.onErrorContainer),
), ),
backgroundColor: theme.colorScheme.errorContainer, backgroundColor: theme.colorScheme.errorContainer,
), ),
); );
} else { } else {
homeserverUrl.text = newHomeserver!.origin;
await Navigator.of(context).push( await Navigator.of(context).push(
MaterialPageRoute(builder: (_) => LoginPage(homeserver: newUrl)), MaterialPageRoute(builder: (_) => LoginPage(homeserver: newUrl)),
); );
} }
} }
} finally {
homeserverFocusNode.requestFocus();
isLoading.value = false; isLoading.value = false;
} }
}
return Scaffold( return Scaffold(
appBar: Appbar(), appBar: Appbar(),
body: isLoading.value body: Center(
? const Loading()
: Center(
child: ConstrainedBox( child: ConstrainedBox(
constraints: BoxConstraints(maxWidth: 600), constraints: .new(maxWidth: 600),
child: Column( child: ListView(
children: [ children: [
Row( Row(
children: [ children: [
@ -74,110 +70,73 @@ class SelectServerPage extends HookConsumerWidget {
SizedBox(width: 12), SizedBox(width: 12),
Expanded( Expanded(
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: .start,
children: [ children: [
Text( Text("Nexus", style: theme.textTheme.displayMedium),
"Nexus",
style: theme.textTheme.displayMedium,
),
Text( Text(
"A Simple Matrix Client", "A Simple Matrix Client",
style: theme.textTheme.headlineMedium, style: theme.textTheme.headlineMedium,
overflow: TextOverflow.ellipsis, overflow: .ellipsis,
), ),
], ],
), ),
), ),
], ],
), ),
Padding( Padding(padding: .symmetric(vertical: 12), child: Divider()),
padding: EdgeInsetsGeometry.symmetric(vertical: 12),
child: Divider(),
),
DividerText("Enter a homeserver domain:"), DividerText("Enter a homeserver domain:"),
Row( Row(
spacing: 8, spacing: 8,
children: [ children: [
Expanded( Expanded(
child: TextField( child: TextField(
focusNode: homeserverFocusNode, textInputAction: .done,
textInputAction: TextInputAction.done, autofocus: true,
onSubmitted: (_) => onSubmitted: (text) => setHomeserver(.tryParse(text)),
setHomeserver(Uri.tryParse(homeserverUrl.text)),
onChanged: (newVal) {
if (hasError.value) {
hasError.value = false;
}
},
controller: homeserverUrl, controller: homeserverUrl,
decoration: InputDecoration( decoration: .new(
labelText: "Homeserver URL (e.g. matrix.org)", labelText: "Homeserver URL",
hintText: "e.g. matrix.org", hintText: "matrix.org",
focusedBorder: hasError.value
? OutlineInputBorder(
borderSide: BorderSide(
color: theme.colorScheme.error,
),
)
: null,
enabledBorder: hasError.value
? OutlineInputBorder(
borderSide: BorderSide(
color: theme.colorScheme.error,
),
)
: null,
), ),
), ),
), ),
IconButton.filled( IconButton.filled(
tooltip: "Confirm homeserver choice", tooltip: "Confirm homeserver choice",
onPressed: isLoading.value || hasError.value onPressed: isLoading.value
? null ? null
: () => setHomeserver( : () => setHomeserver(.tryParse(homeserverUrl.text)),
Uri.tryParse(homeserverUrl.text),
),
icon: Icon(Icons.check), icon: Icon(Icons.check),
), ),
], ],
), ),
Expanded( DividerText("Or, choose from some popular homeservers:"),
child: ListView(
padding: EdgeInsets.only(top: 12),
children: [
DividerText(
"Or, choose from some popular homeservers:",
),
...(<Homeserver>[ ...(<Homeserver>[
Homeserver( .new(
name: "Matrix.org", name: "Matrix.org",
description: description:
"The Matrix.org Foundation offers the matrix.org homeserver as an easy entry point for anyone wanting to try out Matrix.", "The Matrix.org Foundation offers the matrix.org homeserver as an easy entry point for anyone wanting to try out Matrix.",
url: Uri.https("matrix.org"), url: .https("matrix.org"),
iconUrl: iconUrl:
"https://raw.githubusercontent.com/element-hq/logos/refs/heads/master/matrix/matrix-favicon${Theme.brightnessOf(context) == Brightness.dark ? "-white" : ""}.png", "https://raw.githubusercontent.com/element-hq/logos/refs/heads/master/matrix/matrix-favicon${Theme.brightnessOf(context) == Brightness.dark ? "-white" : ""}.png",
), ),
Homeserver( .new(
name: "Federated Nexus", name: "Federated Nexus",
description: description:
"Federated Nexus is a community resource hosting multiple FOSS (especially federated) services, including Matrix and Forgejo. By the same developers who made Nexus client.", "Federated Nexus is a community resource hosting multiple FOSS (especially federated) services, including Matrix and Forgejo. By the same developers who made Nexus client.",
url: Uri.https("federated.nexus"), url: .https("federated.nexus"),
iconUrl: iconUrl: "https://federated.nexus/images/icon.png",
"https://federated.nexus/images/icon.png",
), ),
Homeserver( .new(
name: "Unredacted", name: "Unredacted",
description: description:
"Unredacted is a 501(c)(3) non-profit organization that builds Internet infrastructure and services to help people evade censorship and protect their right to privacy.", "Unredacted is a 501(c)(3) non-profit organization that builds Internet infrastructure and services to help people evade censorship and protect their right to privacy.",
url: Uri.https( url: .https("unredacted.org", "services/si/matrix"),
"unredacted.org",
"services/si/matrix",
),
iconUrl: "https://unredacted.org/favicon.ico", iconUrl: "https://unredacted.org/favicon.ico",
), ),
].map( ].map(
(homeserver) => Card( (homeserver) => Card(
child: ListTile( child: ListTile(
enabled: !isLoading.value,
title: Text(homeserver.name), title: Text(homeserver.name),
leading: Image.network( leading: Image.network(
homeserver.iconUrl, homeserver.iconUrl,
@ -196,13 +155,9 @@ class SelectServerPage extends HookConsumerWidget {
), ),
), ),
)), )),
],
),
),
SizedBox(height: 5),
TextButton( TextButton(
onPressed: () => onPressed: () => launch(.https("servers.joinmatrix.org")),
launch(Uri.https("servers.joinmatrix.org")),
child: Text("See more homeservers..."), child: Text("See more homeservers..."),
), ),
], ],