clean up select server page

This commit is contained in:
Henry Hiles 2026-06-05 16:54:14 -04:00
commit 8f310aa056
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,199 +15,155 @@ 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;
if (newHomeserver?.hasScheme == false) { try {
newHomeserver = Uri.https(newHomeserver!.path); if (newHomeserver?.hasScheme == false) {
} newHomeserver = Uri.https(newHomeserver!.path);
final newUrl = newHomeserver == null
? null
: await client.discoverHomeserver(newHomeserver);
if (context.mounted) {
if (newUrl == null) {
hasError.value = true;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
"Homeserver verification failed. Is your homeserver down?",
style: TextStyle(color: theme.colorScheme.onErrorContainer),
),
backgroundColor: theme.colorScheme.errorContainer,
),
);
} else {
homeserverUrl.text = newHomeserver!.origin;
await Navigator.of(context).push(
MaterialPageRoute(builder: (_) => LoginPage(homeserver: newUrl)),
);
} }
}
homeserverFocusNode.requestFocus(); final newUrl = newHomeserver == null
isLoading.value = false; ? null
: await ref
.watch(ClientController.provider.notifier)
.discoverHomeserver(newHomeserver);
if (context.mounted) {
if (newUrl == null) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
"Homeserver verification failed. Is your homeserver down?",
style: .new(color: theme.colorScheme.onErrorContainer),
),
backgroundColor: theme.colorScheme.errorContainer,
),
);
} else {
await Navigator.of(context).push(
MaterialPageRoute(builder: (_) => LoginPage(homeserver: newUrl)),
);
}
}
} finally {
isLoading.value = false;
}
} }
return Scaffold( return Scaffold(
appBar: Appbar(), appBar: Appbar(),
body: isLoading.value body: Center(
? const Loading() child: ConstrainedBox(
: Center( constraints: .new(maxWidth: 600),
child: ConstrainedBox( child: ListView(
constraints: BoxConstraints(maxWidth: 600), children: [
child: Column( Row(
children: [ children: [
Row( SvgPicture.asset("assets/icon.svg", width: 128),
SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: .start,
children: [ children: [
SvgPicture.asset("assets/icon.svg", width: 128), Text("Nexus", style: theme.textTheme.displayMedium),
SizedBox(width: 12), Text(
Expanded( "A Simple Matrix Client",
child: Column( style: theme.textTheme.headlineMedium,
crossAxisAlignment: CrossAxisAlignment.start, overflow: .ellipsis,
children: [
Text(
"Nexus",
style: theme.textTheme.displayMedium,
),
Text(
"A Simple Matrix Client",
style: theme.textTheme.headlineMedium,
overflow: TextOverflow.ellipsis,
),
],
),
), ),
], ],
), ),
Padding( ),
padding: EdgeInsetsGeometry.symmetric(vertical: 12), ],
child: Divider(), ),
), Padding(padding: .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: TextInputAction.done,
textInputAction: TextInputAction.done, autofocus: true,
onSubmitted: (_) => onSubmitted: (text) => setHomeserver(.tryParse(text)),
setHomeserver(Uri.tryParse(homeserverUrl.text)), controller: homeserverUrl,
onChanged: (newVal) { decoration: InputDecoration(
if (hasError.value) { labelText: "Homeserver URL",
hasError.value = false; hintText: "matrix.org",
}
},
controller: homeserverUrl,
decoration: InputDecoration(
labelText: "Homeserver URL (e.g. matrix.org)",
hintText: "e.g. 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(
tooltip: "Confirm homeserver choice",
onPressed: isLoading.value || hasError.value
? null
: () => setHomeserver(
Uri.tryParse(homeserverUrl.text),
),
icon: Icon(Icons.check),
),
],
),
Expanded(
child: ListView(
padding: EdgeInsets.only(top: 12),
children: [
DividerText(
"Or, choose from some popular homeservers:",
),
...(<Homeserver>[
Homeserver(
name: "Matrix.org",
description:
"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"),
iconUrl:
"https://raw.githubusercontent.com/element-hq/logos/refs/heads/master/matrix/matrix-favicon${Theme.brightnessOf(context) == Brightness.dark ? "-white" : ""}.png",
),
Homeserver(
name: "Federated Nexus",
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.",
url: Uri.https("federated.nexus"),
iconUrl:
"https://federated.nexus/images/icon.png",
),
Homeserver(
name: "Unredacted",
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.",
url: Uri.https(
"unredacted.org",
"services/si/matrix",
),
iconUrl: "https://unredacted.org/favicon.ico",
),
].map(
(homeserver) => Card(
child: ListTile(
title: Text(homeserver.name),
leading: Image.network(
homeserver.iconUrl,
errorBuilder: (_, _, _) => SizedBox.shrink(),
height: 32,
),
subtitle: Text(homeserver.description),
onTap: isLoading.value
? null
: () => setHomeserver(homeserver.url),
trailing: IconButton(
tooltip: "Launch homeserver info page",
onPressed: () => launch(homeserver.url),
icon: Icon(Icons.info_outline),
),
),
),
)),
],
), ),
), ),
SizedBox(height: 5), ),
TextButton( IconButton.filled(
onPressed: () => tooltip: "Confirm homeserver choice",
launch(Uri.https("servers.joinmatrix.org")), onPressed: isLoading.value
child: Text("See more homeservers..."), ? null
), : () => setHomeserver(.tryParse(homeserverUrl.text)),
], icon: Icon(Icons.check),
), ),
],
), ),
), DividerText("Or, choose from some popular homeservers:"),
...(<Homeserver>[
.new(
name: "Matrix.org",
description:
"The Matrix.org Foundation offers the matrix.org homeserver as an easy entry point for anyone wanting to try out Matrix.",
url: .https("matrix.org"),
iconUrl:
"https://raw.githubusercontent.com/element-hq/logos/refs/heads/master/matrix/matrix-favicon${Theme.brightnessOf(context) == Brightness.dark ? "-white" : ""}.png",
),
.new(
name: "Federated Nexus",
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.",
url: .https("federated.nexus"),
iconUrl: "https://federated.nexus/images/icon.png",
),
.new(
name: "Unredacted",
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.",
url: .https("unredacted.org", "services/si/matrix"),
iconUrl: "https://unredacted.org/favicon.ico",
),
].map(
(homeserver) => Card(
child: ListTile(
enabled: !isLoading.value,
title: Text(homeserver.name),
leading: Image.network(
homeserver.iconUrl,
errorBuilder: (_, _, _) => SizedBox.shrink(),
height: 32,
),
subtitle: Text(homeserver.description),
onTap: isLoading.value
? null
: () => setHomeserver(homeserver.url),
trailing: IconButton(
tooltip: "Launch homeserver info page",
onPressed: () => launch(homeserver.url),
icon: Icon(Icons.info_outline),
),
),
),
)),
TextButton(
onPressed: () => launch(.https("servers.joinmatrix.org")),
child: Text("See more homeservers..."),
),
],
),
),
),
); );
} }
} }