mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-09-22 15:07:21 +00:00
feat: optimize error page in database row page and remove unused code (#6193)
This commit is contained in:
parent
31567d451f
commit
08e2be367c
@ -1,15 +1,14 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import 'package:appflowy/generated/locale_keys.g.dart';
|
import 'package:appflowy/generated/locale_keys.g.dart';
|
||||||
import 'package:appflowy/plugins/database/grid/application/row/row_document_bloc.dart';
|
import 'package:appflowy/plugins/database/grid/application/row/row_document_bloc.dart';
|
||||||
import 'package:appflowy/plugins/document/application/document_bloc.dart';
|
import 'package:appflowy/plugins/document/application/document_bloc.dart';
|
||||||
import 'package:appflowy/plugins/document/presentation/editor_page.dart';
|
import 'package:appflowy/plugins/document/presentation/editor_page.dart';
|
||||||
import 'package:appflowy/plugins/document/presentation/editor_style.dart';
|
import 'package:appflowy/plugins/document/presentation/editor_style.dart';
|
||||||
|
import 'package:appflowy/shared/flowy_error_page.dart';
|
||||||
import 'package:appflowy/workspace/application/view_info/view_info_bloc.dart';
|
import 'package:appflowy/workspace/application/view_info/view_info_bloc.dart';
|
||||||
import 'package:appflowy_backend/log.dart';
|
import 'package:appflowy_backend/log.dart';
|
||||||
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
|
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
|
||||||
import 'package:easy_localization/easy_localization.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
import 'package:flowy_infra_ui/widget/error_page.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
|
||||||
class RowDocument extends StatelessWidget {
|
class RowDocument extends StatelessWidget {
|
||||||
@ -27,17 +26,22 @@ class RowDocument extends StatelessWidget {
|
|||||||
return BlocProvider<RowDocumentBloc>(
|
return BlocProvider<RowDocumentBloc>(
|
||||||
create: (context) => RowDocumentBloc(viewId: viewId, rowId: rowId)
|
create: (context) => RowDocumentBloc(viewId: viewId, rowId: rowId)
|
||||||
..add(const RowDocumentEvent.initial()),
|
..add(const RowDocumentEvent.initial()),
|
||||||
child: BlocBuilder<RowDocumentBloc, RowDocumentState>(
|
child: BlocConsumer<RowDocumentBloc, RowDocumentState>(
|
||||||
|
listener: (_, state) => state.loadingState.maybeWhen(
|
||||||
|
error: (error) => Log.error('RowDocument error: $error'),
|
||||||
|
orElse: () => null,
|
||||||
|
),
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
return state.loadingState.when(
|
return state.loadingState.when(
|
||||||
loading: () => const Center(
|
loading: () => const Center(
|
||||||
child: CircularProgressIndicator.adaptive(),
|
child: CircularProgressIndicator.adaptive(),
|
||||||
),
|
),
|
||||||
error: (error) => FlowyErrorPage.message(
|
error: (error) => Center(
|
||||||
error.toString(),
|
child: AppFlowyErrorPage(
|
||||||
howToFix: LocaleKeys.errorDialog_howToFixFallback.tr(),
|
error: error,
|
||||||
),
|
),
|
||||||
finish: () => RowEditor(
|
),
|
||||||
|
finish: () => _RowEditor(
|
||||||
viewPB: state.viewPB!,
|
viewPB: state.viewPB!,
|
||||||
onIsEmptyChanged: (isEmpty) => context
|
onIsEmptyChanged: (isEmpty) => context
|
||||||
.read<RowDocumentBloc>()
|
.read<RowDocumentBloc>()
|
||||||
@ -50,9 +54,8 @@ class RowDocument extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class RowEditor extends StatefulWidget {
|
class _RowEditor extends StatelessWidget {
|
||||||
const RowEditor({
|
const _RowEditor({
|
||||||
super.key,
|
|
||||||
required this.viewPB,
|
required this.viewPB,
|
||||||
this.onIsEmptyChanged,
|
this.onIsEmptyChanged,
|
||||||
});
|
});
|
||||||
@ -60,36 +63,23 @@ class RowEditor extends StatefulWidget {
|
|||||||
final ViewPB viewPB;
|
final ViewPB viewPB;
|
||||||
final void Function(bool)? onIsEmptyChanged;
|
final void Function(bool)? onIsEmptyChanged;
|
||||||
|
|
||||||
@override
|
|
||||||
State<RowEditor> createState() => _RowEditorState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _RowEditorState extends State<RowEditor> {
|
|
||||||
late final DocumentBloc documentBloc;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
documentBloc = DocumentBloc(documentId: widget.viewPB.id)
|
|
||||||
..add(const DocumentEvent.initial());
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
documentBloc.close();
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MultiBlocProvider(
|
return BlocProvider(
|
||||||
providers: [BlocProvider.value(value: documentBloc)],
|
create: (context) => DocumentBloc(documentId: viewPB.id)
|
||||||
|
..add(const DocumentEvent.initial()),
|
||||||
child: BlocListener<DocumentBloc, DocumentState>(
|
child: BlocListener<DocumentBloc, DocumentState>(
|
||||||
listenWhen: (previous, current) =>
|
listenWhen: (previous, current) =>
|
||||||
previous.isDocumentEmpty != current.isDocumentEmpty,
|
previous.isDocumentEmpty != current.isDocumentEmpty,
|
||||||
listener: (context, state) {
|
listener: (_, state) {
|
||||||
if (state.isDocumentEmpty != null) {
|
if (state.isDocumentEmpty != null) {
|
||||||
widget.onIsEmptyChanged?.call(state.isDocumentEmpty!);
|
onIsEmptyChanged?.call(state.isDocumentEmpty!);
|
||||||
|
}
|
||||||
|
if (state.error != null) {
|
||||||
|
Log.error('RowEditor error: ${state.error}');
|
||||||
|
}
|
||||||
|
if (state.editorState == null) {
|
||||||
|
Log.error('RowEditor unable to get editorState');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: BlocBuilder<DocumentBloc, DocumentState>(
|
child: BlocBuilder<DocumentBloc, DocumentState>(
|
||||||
@ -101,18 +91,18 @@ class _RowEditorState extends State<RowEditor> {
|
|||||||
final editorState = state.editorState;
|
final editorState = state.editorState;
|
||||||
final error = state.error;
|
final error = state.error;
|
||||||
if (error != null || editorState == null) {
|
if (error != null || editorState == null) {
|
||||||
Log.error(error);
|
return Center(
|
||||||
return FlowyErrorPage.message(
|
child: AppFlowyErrorPage(
|
||||||
error.toString(),
|
error: error,
|
||||||
howToFix: LocaleKeys.errorDialog_howToFixFallback.tr(),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return IntrinsicHeight(
|
return BlocProvider<ViewInfoBloc>(
|
||||||
|
create: (context) => ViewInfoBloc(view: viewPB),
|
||||||
|
child: IntrinsicHeight(
|
||||||
child: Container(
|
child: Container(
|
||||||
constraints: const BoxConstraints(minHeight: 300),
|
constraints: const BoxConstraints(minHeight: 300),
|
||||||
child: BlocProvider<ViewInfoBloc>(
|
|
||||||
create: (context) => ViewInfoBloc(view: widget.viewPB),
|
|
||||||
child: AppFlowyEditorPage(
|
child: AppFlowyEditorPage(
|
||||||
shrinkWrap: true,
|
shrinkWrap: true,
|
||||||
autoFocus: false,
|
autoFocus: false,
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import 'package:appflowy/generated/locale_keys.g.dart';
|
|
||||||
import 'package:appflowy/plugins/database/application/row/related_row_detail_bloc.dart';
|
import 'package:appflowy/plugins/database/application/row/related_row_detail_bloc.dart';
|
||||||
import 'package:appflowy/plugins/database/grid/application/row/row_detail_bloc.dart';
|
import 'package:appflowy/plugins/database/grid/application/row/row_detail_bloc.dart';
|
||||||
import 'package:appflowy/plugins/database/grid/presentation/widgets/common/type_option_separator.dart';
|
import 'package:appflowy/plugins/database/grid/presentation/widgets/common/type_option_separator.dart';
|
||||||
@ -9,14 +8,13 @@ import 'package:appflowy/plugins/document/presentation/banner.dart';
|
|||||||
import 'package:appflowy/plugins/document/presentation/editor_notification.dart';
|
import 'package:appflowy/plugins/document/presentation/editor_notification.dart';
|
||||||
import 'package:appflowy/plugins/document/presentation/editor_page.dart';
|
import 'package:appflowy/plugins/document/presentation/editor_page.dart';
|
||||||
import 'package:appflowy/plugins/document/presentation/editor_style.dart';
|
import 'package:appflowy/plugins/document/presentation/editor_style.dart';
|
||||||
|
import 'package:appflowy/shared/flowy_error_page.dart';
|
||||||
import 'package:appflowy/startup/startup.dart';
|
import 'package:appflowy/startup/startup.dart';
|
||||||
import 'package:appflowy/workspace/application/action_navigation/action_navigation_bloc.dart';
|
import 'package:appflowy/workspace/application/action_navigation/action_navigation_bloc.dart';
|
||||||
import 'package:appflowy/workspace/application/action_navigation/navigation_action.dart';
|
import 'package:appflowy/workspace/application/action_navigation/navigation_action.dart';
|
||||||
import 'package:appflowy_backend/log.dart';
|
import 'package:appflowy_backend/log.dart';
|
||||||
import 'package:appflowy_backend/protobuf/flowy-folder/protobuf.dart';
|
import 'package:appflowy_backend/protobuf/flowy-folder/protobuf.dart';
|
||||||
import 'package:appflowy_editor/appflowy_editor.dart' hide Log;
|
import 'package:appflowy_editor/appflowy_editor.dart' hide Log;
|
||||||
import 'package:easy_localization/easy_localization.dart';
|
|
||||||
import 'package:flowy_infra_ui/widget/error_page.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
|
||||||
@ -83,9 +81,10 @@ class _DatabaseDocumentPageState extends State<DatabaseDocumentPage> {
|
|||||||
final error = state.error;
|
final error = state.error;
|
||||||
if (error != null || editorState == null) {
|
if (error != null || editorState == null) {
|
||||||
Log.error(error);
|
Log.error(error);
|
||||||
return FlowyErrorPage.message(
|
return Center(
|
||||||
error.toString(),
|
child: AppFlowyErrorPage(
|
||||||
howToFix: LocaleKeys.errorDialog_howToFixFallback.tr(),
|
error: error,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user