feat(profile): the profile saves as it is written, the handle chosen in a dialog that checks it
Changing the profile meant a Save button at the foot of the form, which the floating navigation bar half covered on a phone. A field now saves when it is left or Enter is pressed in it, and a link when it is removed; "Saving…" and "Saved" show beside the title. The form keeps what is being written as saves come back, where it used to start afresh and lose focus after each one. The handle is chosen in a dialog that asks the instance while it is typed whether it is free (`ProfileEndpoint.checkHandle`, which tells nothing `byHandle` doesn't), and choosing the first makes the profile with what was written. Saves go one at a time, the latest of those waiting next, and a handle chosen holds for every save after it, so a field's save can't take it back. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MMm7usAo6q9ZZRoPkWjoxi Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
parent
b46dfe22b1
commit
959014b4a1
1 changed files with 1062 additions and 152 deletions
|
|
@ -24,6 +24,40 @@ class FakeProfileGateway({
|
|||
return profile;
|
||||
}
|
||||
|
||||
/// The handles checked, in order.
|
||||
final checked = <String>[];
|
||||
|
||||
@override
|
||||
Future<ProfileProblem?> checkHandle(String handle) async {
|
||||
if (fail case final error?) {
|
||||
throw error;
|
||||
}
|
||||
checked.add(handle);
|
||||
return _problemOf(handle);
|
||||
}
|
||||
|
||||
ProfileProblem? _problemOf(String handle) {
|
||||
final current = profile;
|
||||
if (!RegExp(r'^[A-Za-z0-9_]{1,30}$').hasMatch(handle)) {
|
||||
return ProfileProblem.handleInvalid;
|
||||
}
|
||||
if (handle.toLowerCase() == 'admin') {
|
||||
return ProfileProblem.handleReserved;
|
||||
}
|
||||
if (taken.any((other) => other.toLowerCase() == handle.toLowerCase())) {
|
||||
return ProfileProblem.handleTaken;
|
||||
}
|
||||
if (current != null &&
|
||||
current.handleFixed &&
|
||||
current.handle.toLowerCase() != handle.toLowerCase()) {
|
||||
return ProfileProblem.published;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Every profile saved, in order.
|
||||
final saves = <PublicProfile>[];
|
||||
|
||||
@override
|
||||
Future<PublicProfile> save({
|
||||
required String handle,
|
||||
|
|
@ -35,18 +69,10 @@ class FakeProfileGateway({
|
|||
throw error;
|
||||
}
|
||||
final current = profile;
|
||||
if (!RegExp(r'^[A-Za-z0-9_]{1,30}$').hasMatch(handle)) {
|
||||
throw ProfileRefused(ProfileProblem.handleInvalid);
|
||||
if (_problemOf(handle) case final problem?) {
|
||||
throw ProfileRefused(problem);
|
||||
}
|
||||
if (taken.any((other) => other.toLowerCase() == handle.toLowerCase())) {
|
||||
throw ProfileRefused(ProfileProblem.handleTaken);
|
||||
}
|
||||
if (current != null &&
|
||||
current.handleFixed &&
|
||||
current.handle.toLowerCase() != handle.toLowerCase()) {
|
||||
throw ProfileRefused(ProfileProblem.published);
|
||||
}
|
||||
return profile = PublicProfile(
|
||||
final saved = profile = PublicProfile(
|
||||
handle: handle,
|
||||
address: '$handle@halkyon.eu',
|
||||
displayName: displayName,
|
||||
|
|
@ -54,6 +80,8 @@ class FakeProfileGateway({
|
|||
links: links,
|
||||
handleFixed: current?.handleFixed ?? false,
|
||||
);
|
||||
saves.add(saved);
|
||||
return saved;
|
||||
}
|
||||
|
||||
/// The avatars set, in order.
|
||||
|
|
|
|||
Loading…
Reference in a new issue