Skip to content

Commit 4b54678

Browse files
feat(cat-voices): editable username (#2096)
* feat: more CatalystId comparing tools * feat: expose update account in user service * feat: updating username * feat: make CatalystIdText display only significant part * fix: handling whitespaces in CatalystId username * chore: rollback log level * refactor: rename DisplayName -> Username to unify with CatalystId * fix: document and drafts dao author query * chore: hide setup roles menu item * refactor: remove un used methods
1 parent e11dd0c commit 4b54678

File tree

32 files changed

+674
-413
lines changed

32 files changed

+674
-413
lines changed

catalyst_voices/apps/voices/lib/pages/account/account_page.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import 'dart:async';
22

33
import 'package:catalyst_voices/pages/account/widgets/account_action_tile.dart';
4-
import 'package:catalyst_voices/pages/account/widgets/account_display_name_tile.dart';
54
import 'package:catalyst_voices/pages/account/widgets/account_email_tile.dart';
65
import 'package:catalyst_voices/pages/account/widgets/account_header_tile.dart';
76
import 'package:catalyst_voices/pages/account/widgets/account_keychain_tile.dart';
87
import 'package:catalyst_voices/pages/account/widgets/account_page_title.dart';
98
import 'package:catalyst_voices/pages/account/widgets/account_roles_tile.dart';
109
import 'package:catalyst_voices/pages/account/widgets/account_status_banner.dart';
10+
import 'package:catalyst_voices/pages/account/widgets/account_username_tile.dart';
1111
import 'package:catalyst_voices/pages/spaces/appbar/account_popup/session_account_avatar.dart';
1212
import 'package:catalyst_voices/pages/spaces/appbar/session_action_header.dart';
1313
import 'package:catalyst_voices/widgets/widgets.dart';
@@ -72,7 +72,7 @@ class _AccountPageState extends State<AccountPage> {
7272
child: Column(
7373
mainAxisSize: MainAxisSize.min,
7474
children: const <Widget>[
75-
AccountDisplayNameTile(),
75+
AccountUsernameTile(),
7676
AccountEmailTile(),
7777
].separatedBy(const SizedBox(height: 20)).toList(),
7878
),
Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@ import 'package:catalyst_voices_view_models/catalyst_voices_view_models.dart';
88
import 'package:flutter/material.dart';
99
import 'package:flutter_bloc/flutter_bloc.dart';
1010

11-
class AccountDisplayNameTile extends StatefulWidget {
12-
const AccountDisplayNameTile({
11+
class AccountUsernameTile extends StatefulWidget {
12+
const AccountUsernameTile({
1313
super.key,
1414
});
1515

1616
@override
17-
State<AccountDisplayNameTile> createState() => _AccountDisplayNameTileState();
17+
State<AccountUsernameTile> createState() => _AccountUsernameTileState();
1818
}
1919

20-
class _AccountDisplayNameTileState extends State<AccountDisplayNameTile> {
20+
class _AccountUsernameTileState extends State<AccountUsernameTile> {
2121
late final TextEditingController _controller;
2222
late final FocusNode _focusNode;
2323

2424
bool _isEditMode = false;
25-
DisplayName _displayName = const DisplayName.pure();
26-
StreamSubscription<DisplayName>? _sub;
25+
Username _username = const Username.pure();
26+
StreamSubscription<Username>? _sub;
2727

2828
@override
2929
Widget build(BuildContext context) {
@@ -32,19 +32,19 @@ class _AccountDisplayNameTileState extends State<AccountDisplayNameTile> {
3232
title: context.l10n.displayName,
3333
onChanged: _onEditModeChange,
3434
isEditMode: _isEditMode,
35-
isSaveEnabled: _displayName.isValid,
36-
isEditEnabled: false,
37-
child: VoicesDisplayNameTextField(
35+
isSaveEnabled: _username.isValid,
36+
isEditEnabled: true,
37+
child: VoicesUsernameTextField(
3838
key: const Key('AccountDisplayNameTextField'),
3939
controller: _controller,
4040
focusNode: _focusNode,
4141
decoration: VoicesTextFieldDecoration(
4242
hintText: context.l10n.displayName,
43-
errorText: _displayName.displayError?.message(context),
43+
errorText: _username.displayError?.message(context),
4444
),
4545
onFieldSubmitted: null,
4646
readOnly: !_isEditMode,
47-
maxLength: _isEditMode ? DisplayName.lengthRange.max : null,
47+
maxLength: _isEditMode ? Username.lengthRange.max : null,
4848
),
4949
);
5050
}
@@ -64,27 +64,27 @@ class _AccountDisplayNameTileState extends State<AccountDisplayNameTile> {
6464
super.initState();
6565

6666
final bloc = context.read<AccountCubit>();
67-
final text = bloc.state.displayName.value;
67+
final text = bloc.state.username.value;
6868
final value = TextEditingValueExt.collapsedAtEndOf(text);
6969
_controller = TextEditingController.fromValue(value);
7070
_controller.addListener(_handleControllerChange);
71-
_displayName = bloc.state.displayName;
71+
_username = bloc.state.username;
7272

7373
_focusNode = FocusNode();
7474

7575
_sub = bloc.stream
76-
.map((event) => event.displayName)
76+
.map((event) => event.username)
7777
.distinct()
78-
.listen(_handleDisplayNameChange);
78+
.listen(_handleUsernameChange);
7979
}
8080

8181
void _handleControllerChange() {
8282
setState(() {
83-
_displayName = DisplayName.dirty(_controller.text);
83+
_username = Username.dirty(_controller.text);
8484
});
8585
}
8686

87-
void _handleDisplayNameChange(DisplayName displayName) {
87+
void _handleUsernameChange(Username displayName) {
8888
if (_isEditMode) {
8989
return;
9090
}
@@ -93,7 +93,7 @@ class _AccountDisplayNameTileState extends State<AccountDisplayNameTile> {
9393
}
9494

9595
void _onCancel() {
96-
final displayName = context.read<AccountCubit>().state.displayName;
96+
final displayName = context.read<AccountCubit>().state.username;
9797
_controller.textWithSelection = displayName.value;
9898
}
9999

@@ -118,7 +118,6 @@ class _AccountDisplayNameTileState extends State<AccountDisplayNameTile> {
118118
}
119119

120120
void _onSave() {
121-
// Note. not supported atm.
122-
// unawaited(context.read<AccountCubit>().updateDisplayName(_displayName));
121+
unawaited(context.read<AccountCubit>().updateUsername(_username));
123122
}
124123
}

catalyst_voices/apps/voices/lib/pages/proposal/widget/proposal_header.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class _ProposalMetadataSelector extends StatelessWidget {
155155
builder: (context, state) {
156156
return _ProposalMetadata(
157157
title: state.title,
158-
author: state.authorDisplayName,
158+
author: state.authorName,
159159
createdAt: state.createdAt,
160160
commentsCount: state.commentsCount,
161161
);

catalyst_voices/apps/voices/lib/pages/registration/create_base_profile/stage/setup_panel.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ class _DisplayNameSelector extends StatelessWidget {
6464

6565
@override
6666
Widget build(BuildContext context) {
67-
return BlocBaseProfileSelector<DisplayName>(
68-
selector: (state) => state.displayName,
67+
return BlocBaseProfileSelector<Username>(
68+
selector: (state) => state.username,
6969
builder: (context, state) => _DisplayNameTextField(displayName: state),
7070
);
7171
}
7272
}
7373

7474
class _DisplayNameTextField extends StatelessWidget {
75-
final DisplayName displayName;
75+
final Username displayName;
7676

7777
const _DisplayNameTextField({
7878
required this.displayName,
@@ -82,13 +82,13 @@ class _DisplayNameTextField extends StatelessWidget {
8282
Widget build(BuildContext context) {
8383
final l10n = context.l10n;
8484

85-
return VoicesDisplayNameTextField(
85+
return VoicesUsernameTextField(
8686
key: const Key('DisplayNameTextField'),
8787
initialText: displayName.value,
8888
onChanged: (value) {
8989
RegistrationCubit.of(context)
9090
.baseProfile
91-
.updateDisplayName(DisplayName.dirty(value ?? ''));
91+
.updateUsername(Username.dirty(value ?? ''));
9292
},
9393
onFieldSubmitted: null,
9494
decoration: VoicesTextFieldDecoration(
@@ -97,7 +97,7 @@ class _DisplayNameTextField extends StatelessWidget {
9797
helperText: l10n.createBaseProfileSetupDisplayNameHelper,
9898
errorText: displayName.displayError?.message(context),
9999
),
100-
maxLength: DisplayName.lengthRange.max,
100+
maxLength: Username.lengthRange.max,
101101
);
102102
}
103103
}

0 commit comments

Comments
 (0)