Conversation
Mbin rejects magazine names that fall outside /^[a-zA-Z0-9_]{2,25}$/, but
the create-community form only disabled submit on an empty name, so an
invalid name failed server-side with no guidance.
- Add mbin_community_name.dart with pure, tested helpers to validate a
name, describe why it is invalid, and derive a sanitized suggestion.
- Give the shared TextEditor helperText/errorText support.
- In CommunityOwnerPanelGeneral (creation only), on Mbin: show the rule as
helper text, an inline error while the name is invalid, a one-tap
"Use suggestion" action, and keep submit disabled until the name is
valid. Lemmy/PieFed behaviour is unchanged.
- Add flutter_test dev dependency and focused unit tests for the helpers.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01N7b7QotawaBJQ4isQKd14x
jwr1
left a comment
There was a problem hiding this comment.
Hello @neo22neo, thank you for submitting your first PR here! I especially like the idea of suggesting a community name based on the title someone has set already. I haven't checked out the code locally yet, but upon first review of the code, I do have a few things to note.
| case MbinCommunityNameIssue.tooLong: | ||
| return l(context).community_nameTooLong(mbinCommunityNameMaxLength); |
There was a problem hiding this comment.
Instead of enforcing the max community length as an error, why don't you use the maxLength field on the TextEditor widget? It would display the current and max length of the text as the user is typing, and prevent the user from typing over that length.
| var suggestion = name | ||
| .replaceAll(_mbinCommunityNameInvalidChars, '_') | ||
| .replaceAll(RegExp(r'_+'), '_') | ||
| .replaceAll(RegExp(r'^_+|_+$'), ''); | ||
|
|
||
| if (suggestion.length > mbinCommunityNameMaxLength) { | ||
| suggestion = suggestion | ||
| .substring(0, mbinCommunityNameMaxLength) | ||
| .replaceAll(RegExp(r'_+$'), ''); | ||
| } |
There was a problem hiding this comment.
Would it work to move the .replaceAll(RegExp(r'^_+|_+$'), '') portion from line 49 to after the if statement, that way we could remove the .replaceAll(RegExp(r'_+$'), '') portion from line 54 that's in the if statement?
| /// A best-effort valid name derived from [name], or `null` when nothing | ||
| /// usable can be salvaged (e.g. the input has no letters/digits at all) or | ||
| /// when [name] is already valid. | ||
| String? suggestMbinCommunityName(String name) { |
There was a problem hiding this comment.
One addition that would be nice for this function is to also make the suggested name all lowercase, as that seems to be the general convention for community names.
Problem
When creating a community on an Mbin server, the form only disabled the submit button on an empty name. Mbin rejects any magazine name outside
/^[a-zA-Z0-9_]{2,25}$/(RegPatterns::MAGAZINE_NAME), so names with spaces, hyphens, accents, etc. failed server-side with no guidance for the user.Changes
lib/src/utils/mbin_community_name.dart(new) — pure, testable helpers:isValidMbinCommunityName— the^[a-zA-Z0-9_]{2,25}$check.mbinCommunityNameIssue— why a name is invalid (invalidCharacters/tooShort/tooLong); empty is treated as "not entered yet".suggestMbinCommunityName— best-effort sanitized name (unsupported runs →_, collapsed, trimmed, truncated to 25), ornullwhen nothing usable can be salvaged.lib/src/widgets/text_editor.dart— sharedTextEditorgainshelperText/errorTextpassthrough.lib/src/screens/explore/community_owner_panel.dart— inCommunityOwnerPanelGeneral(creation path only), when the active server is Mbin:maxLength: 25, no extra validation).lib/l10n/app_en.arb— new keys:community_nameMbinHelp,community_nameInvalidCharacters,community_nameTooShort,community_nameTooLong,community_nameUseSuggestion.pubspec.yaml/test/— addflutter_testdev dependency and focused unit tests for the new helpers.Notes
MbinOrg/mbinsrc/Utils/RegPatterns.php).dart format/flutter test/flutter gen-l10nwere not run locally — please double-check CI.🤖 Generated with Claude Code