forked from AppFlowy-IO/AppFlowy
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: edit group title + rebuild improvement (AppFlowy-IO#6156)
* fix: edit group title + rebuild improvement * chore: fix clippy * chore: fix clippy * fix: stop widget replacement causing perf issues * fix: after merge main * chore: minor cleanup in view_editor * fix: attempt to fix hover issue in tests
- Loading branch information
Showing
25 changed files
with
592 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
frontend/appflowy_flutter/lib/plugins/database/board/application/column_header_bloc.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import 'package:appflowy/plugins/database/board/group_ext.dart'; | ||
import 'package:appflowy/plugins/database/domain/group_service.dart'; | ||
import 'package:appflowy_backend/protobuf/flowy-database2/group.pb.dart'; | ||
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
import 'package:freezed_annotation/freezed_annotation.dart'; | ||
|
||
import '../../application/database_controller.dart'; | ||
import '../../application/field/field_controller.dart'; | ||
|
||
part 'column_header_bloc.freezed.dart'; | ||
|
||
class ColumnHeaderBloc extends Bloc<ColumnHeaderEvent, ColumnHeaderState> { | ||
ColumnHeaderBloc({ | ||
required this.databaseController, | ||
required this.fieldId, | ||
required this.group, | ||
}) : super(const ColumnHeaderState.loading()) { | ||
groupBackendSvc = GroupBackendService(viewId); | ||
_dispatch(); | ||
} | ||
|
||
final DatabaseController databaseController; | ||
final String fieldId; | ||
final GroupPB group; | ||
|
||
late final GroupBackendService groupBackendSvc; | ||
|
||
FieldController get fieldController => databaseController.fieldController; | ||
String get viewId => databaseController.viewId; | ||
|
||
void _dispatch() { | ||
on<ColumnHeaderEvent>( | ||
(event, emit) async { | ||
await event.when( | ||
initial: () { | ||
final name = group.generateGroupName(databaseController); | ||
emit(ColumnHeaderState.initial(name)); | ||
}, | ||
startEditing: () async { | ||
state.maybeMap( | ||
ready: (state) => emit(state.copyWith(isEditing: true)), | ||
orElse: () {}, | ||
); | ||
}, | ||
endEditing: (String? groupName) async { | ||
if (groupName != null) { | ||
final stateGroupName = state.maybeMap( | ||
ready: (state) => state.groupName, | ||
orElse: () => null, | ||
); | ||
|
||
if (stateGroupName == null || stateGroupName == groupName) { | ||
state.maybeMap( | ||
ready: (state) => emit( | ||
state.copyWith( | ||
groupName: stateGroupName!, | ||
isEditing: false, | ||
), | ||
), | ||
orElse: () {}, | ||
); | ||
} | ||
|
||
await groupBackendSvc.renameGroup( | ||
groupId: group.groupId, | ||
fieldId: fieldId, | ||
name: groupName, | ||
); | ||
state.maybeMap( | ||
ready: (state) { | ||
emit(state.copyWith(groupName: groupName, isEditing: false)); | ||
}, | ||
orElse: () {}, | ||
); | ||
} | ||
}, | ||
); | ||
}, | ||
); | ||
} | ||
} | ||
|
||
@freezed | ||
class ColumnHeaderEvent with _$ColumnHeaderEvent { | ||
const factory ColumnHeaderEvent.initial() = _Initial; | ||
const factory ColumnHeaderEvent.startEditing() = _StartEditing; | ||
const factory ColumnHeaderEvent.endEditing(String? groupName) = _EndEditing; | ||
} | ||
|
||
@freezed | ||
class ColumnHeaderState with _$ColumnHeaderState { | ||
const ColumnHeaderState._(); | ||
|
||
const factory ColumnHeaderState.loading() = _ColumnHeaderLoadingState; | ||
|
||
const factory ColumnHeaderState.error({ | ||
required FlowyError error, | ||
}) = _ColumnHeaderErrorState; | ||
|
||
const factory ColumnHeaderState.ready({ | ||
required String groupName, | ||
@Default(false) bool isEditing, | ||
@Default(false) bool canEdit, | ||
}) = _ColumnHeaderReadyState; | ||
|
||
factory ColumnHeaderState.initial(String name) => | ||
ColumnHeaderState.ready(groupName: name); | ||
|
||
bool get isLoading => maybeMap(loading: (_) => true, orElse: () => false); | ||
bool get isError => maybeMap(error: (_) => true, orElse: () => false); | ||
bool get isReady => maybeMap(ready: (_) => true, orElse: () => false); | ||
} |
Oops, something went wrong.