Skip to content

Commit

Permalink
fix: show default view name (#6571)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xazin authored Oct 22, 2024
1 parent ca6a900 commit da80c59
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class NotificationReminderBloc
emit(
NotificationReminderState(
createdAt: createdAt,
pageTitle: view.name,
pageTitle: view.nameOrDefault,
view: view,
reminderContent: node.delta?.toPlainText() ?? '',
nodes: [node],
Expand All @@ -68,7 +68,7 @@ class NotificationReminderBloc
emit(
NotificationReminderState(
createdAt: createdAt,
pageTitle: view.name,
pageTitle: view.nameOrDefault,
view: view,
reminderContent: reminder.message,
status: NotificationReminderStatus.loaded,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import 'dart:io';

import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/application/mobile_router.dart';
import 'package:appflowy/workspace/application/sidebar/folder/folder_bloc.dart';
import 'package:appflowy/workspace/application/view/view_bloc.dart';
import 'package:appflowy/workspace/application/view/view_ext.dart';
import 'package:appflowy/workspace/presentation/home/home_sizes.dart';
import 'package:appflowy/workspace/presentation/home/menu/view/draggable_view_item.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
Expand Down Expand Up @@ -262,9 +260,7 @@ class _SingleMobileInnerViewItemState extends State<SingleMobileInnerViewItem> {
// title
Expanded(
child: FlowyText.regular(
widget.view.name.isEmpty
? LocaleKeys.menuAppHeader_defaultNewPageName.tr()
: widget.view.name,
widget.view.nameOrDefault,
fontSize: 16.0,
figmaLineHeight: 20.0,
overflow: TextOverflow.ellipsis,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:appflowy/startup/startup.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/view/prelude.dart';
import 'package:appflowy/workspace/application/view/view_ext.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
Expand Down Expand Up @@ -172,7 +173,7 @@ class _DocumentPageState extends State<DocumentPage>

Widget buildBanner(BuildContext context) {
return DocumentBanner(
viewName: widget.view.name,
viewName: widget.view.nameOrDefault,
onRestore: () =>
context.read<DocumentBloc>().add(const DocumentEvent.restorePage()),
onDelete: () => context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/database/domain/database_view_service.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/mention/mention_block.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';
import 'package:appflowy/workspace/application/view/view_ext.dart';
import 'package:appflowy/workspace/application/view/view_service.dart';
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
Expand Down Expand Up @@ -98,7 +99,7 @@ extension InsertDatabase on EditorState {
final prefix = _referencedDatabasePrefix(view.layout);
final ref = await ViewBackendService.createDatabaseLinkedView(
parentViewId: view.id,
name: "$prefix ${view.name}",
name: "$prefix ${view.nameOrDefault}",
layoutType: view.layout,
databaseId: databaseId,
).then((value) => value.toNullable());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,7 @@ class SubPageBlockComponentState extends State<SubPageBlockComponent>
const HSpace(10),
Flexible(
child: FlowyText(
view.name.trim().isEmpty
? LocaleKeys.menuAppHeader_defaultNewPageName
.tr()
: view.name,
view.nameOrDefault,
fontSize: textStyle.fontSize,
fontWeight: textStyle.fontWeight,
lineHeight: textStyle.height,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,15 @@ class InlinePageReferenceService extends InlineActionsDelegate {

items = allViews
.where(
(view) => view.name.toLowerCase().contains(search.toLowerCase()),
(view) =>
view.id != currentViewId &&
view.name.toLowerCase().contains(search.toLowerCase()) ||
(view.name.isEmpty && search.isEmpty) ||
(view.name.isEmpty &&
LocaleKeys.menuAppHeader_defaultNewPageName
.tr()
.toLowerCase()
.contains(search.toLowerCase())),
)
.take(limitResults)
.map((view) => _fromView(view))
Expand Down Expand Up @@ -224,8 +232,8 @@ class InlinePageReferenceService extends InlineActionsDelegate {
}

InlineActionsMenuItem _fromView(ViewPB view) => InlineActionsMenuItem(
keywords: [view.name.toLowerCase()],
label: view.name,
keywords: [view.nameOrDefault.toLowerCase()],
label: view.nameOrDefault,
icon: (onSelected) => view.icon.value.isNotEmpty
? FlowyText.emoji(
view.icon.value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class ViewExtKeys {
}

extension ViewExtension on ViewPB {
String get nameOrDefault =>
name.isEmpty ? LocaleKeys.menuAppHeader_defaultNewPageName.tr() : name;

Widget defaultIcon({Size? size}) => FlowySvg(
switch (layout) {
ViewLayoutPB.Board => FlowySvgs.icon_board_s,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:appflowy/workspace/application/view/view_ext.dart';
import 'package:flutter/material.dart';

import 'package:appflowy/startup/startup.dart';
Expand Down Expand Up @@ -27,7 +28,7 @@ class RecentViewTile extends StatelessWidget {
children: [
icon,
const HSpace(6),
FlowyText(view.name),
FlowyText(view.nameOrDefault),
],
),
focusColor: Theme.of(context).colorScheme.primary.withOpacity(0.1),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,7 @@ class _SingleInnerViewItemState extends State<SingleInnerViewItem> {

Widget _buildViewItem(bool onHover, [bool isSelected = false]) {
final name = FlowyText.regular(
widget.view.name.isEmpty
? LocaleKeys.menuAppHeader_defaultNewPageName.tr()
: widget.view.name,
widget.view.nameOrDefault,
overflow: TextOverflow.ellipsis,
fontSize: 14.0,
figmaLineHeight: 18.0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/workspace/application/sidebar/folder/folder_bloc.dart';
import 'package:appflowy/workspace/application/view/view_bloc.dart';
import 'package:appflowy/workspace/application/view/view_ext.dart';
import 'package:appflowy/workspace/application/view/view_service.dart';
import 'package:appflowy/workspace/presentation/home/menu/view/view_action_type.dart';
import 'package:appflowy/workspace/presentation/home/menu/view/view_item.dart';
Expand Down Expand Up @@ -57,7 +58,7 @@ class ViewAction extends StatelessWidget {
if (containPublishedPage && context.mounted) {
await showConfirmDeletionDialog(
context: context,
name: view.name,
name: view.nameOrDefault,
description: LocaleKeys.publish_containsPublishedPage.tr(),
onConfirm: () {
context.read<ViewBloc>().add(const ViewEvent.delete());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:appflowy/workspace/application/view/view_ext.dart';
import 'package:flutter/material.dart';

import 'package:appflowy/workspace/application/view/view_listener.dart';
Expand Down Expand Up @@ -38,5 +39,5 @@ class _ViewTabBarItemState extends State<ViewTabBarItem> {
}

@override
Widget build(BuildContext context) => FlowyText.medium(view.name);
Widget build(BuildContext context) => FlowyText.medium(view.nameOrDefault);
}

0 comments on commit da80c59

Please sign in to comment.