Skip to content

Commit

Permalink
fix: launch review 0.8.1 (#7185)
Browse files Browse the repository at this point in the history
* fix: launch review

* chore: scroll to end upon sending new message

* chore: bump editor version

* chore: scroll to bottom after adding message

* chore: code reorg

* chore: bump editor version

* chore: bump editor ver

* chore: bump editor

* chore: bump editor

* fix: file block node insertion

* fix: do the same thing on image

* chore: update icons and translations
  • Loading branch information
richardshiue authored Jan 14, 2025
1 parent 2b1d1ba commit d1efda4
Show file tree
Hide file tree
Showing 14 changed files with 126 additions and 147 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ class ChatAnimatedListReversedState extends State<ChatAnimatedListReversed>
// bottom of the list, set `_userHasScrolled` to false so that the scroll
// animation is triggered.
if (_userHasScrolled &&
widget.scrollController.offset >=
widget.scrollController.offset >
widget.scrollController.position.minScrollExtent) {
_userHasScrolled = false;
}
Expand All @@ -325,7 +325,7 @@ class ChatAnimatedListReversedState extends State<ChatAnimatedListReversed>
// Used later to trigger scroll to end only for the last inserted message.
_lastInsertedMessageId = data.id;

if (position == _oldList.length) {
if (position == 0) {
_scrollToEnd(data);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ class _DesktopAIPromptInputState extends State<DesktopAIPromptInput> {
final focusNode = FocusNode();
final textController = TextEditingController();

bool showPredefinedFormatSection = false;
PredefinedFormat predefinedFormat = const PredefinedFormat.auto();
bool showPredefinedFormatSection = true;
PredefinedFormat predefinedFormat = const PredefinedFormat(
imageFormat: ImageFormat.text,
textFormat: TextFormat.bulletList,
);
late SendButtonState sendButtonState;

@override
Expand Down Expand Up @@ -185,10 +188,6 @@ class _DesktopAIPromptInputState extends State<DesktopAIPromptInput> {
setState(() {
showPredefinedFormatSection =
!showPredefinedFormatSection;
if (!showPredefinedFormatSection) {
predefinedFormat =
const PredefinedFormat.auto();
}
});
},
sendButtonState: sendButtonState,
Expand Down Expand Up @@ -466,10 +465,7 @@ class _PromptTextFieldState extends State<_PromptTextField> {
focusedBorder: InputBorder.none,
contentPadding: calculateContentPadding(),
hintText: widget.hintText,
hintStyle: Theme.of(context)
.textTheme
.bodyMedium
?.copyWith(color: Theme.of(context).hintColor),
hintStyle: AIChatUILayout.inputHintTextStyle(context),
isCollapsed: true,
isDense: true,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ class _MobileAIPromptInputState extends State<MobileAIPromptInput> {
final focusNode = FocusNode();
final textController = TextEditingController();

bool showPredefinedFormatSection = false;
PredefinedFormat predefinedFormat = const PredefinedFormat.auto();
bool showPredefinedFormatSection = true;
PredefinedFormat predefinedFormat = const PredefinedFormat(
imageFormat: ImageFormat.text,
textFormat: TextFormat.bulletList,
);
late SendButtonState sendButtonState;

@override
Expand Down Expand Up @@ -265,6 +268,7 @@ class _MobileAIPromptInputState extends State<MobileAIPromptInput> {
AIType.appflowyAI => LocaleKeys.chat_inputMessageHint.tr(),
AIType.localAI => LocaleKeys.chat_inputLocalAIMessageHint.tr()
},
hintStyle: AIChatUILayout.inputHintTextStyle(context),
isCollapsed: true,
isDense: true,
),
Expand Down Expand Up @@ -304,9 +308,6 @@ class _MobileAIPromptInputState extends State<MobileAIPromptInput> {
onTogglePredefinedFormatSection: () {
setState(() {
showPredefinedFormatSection = !showPredefinedFormatSection;
if (!showPredefinedFormatSection) {
predefinedFormat = const PredefinedFormat.auto();
}
});
},
onUpdateSelectedSources: widget.onUpdateSelectedSources,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,50 +24,25 @@ class PromptInputDesktopToggleFormatButton extends StatelessWidget {

@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: onTap,
behavior: HitTestBehavior.opaque,
child: SizedBox(
height: DesktopAIPromptSizes.actionBarButtonSize,
child: FlowyHover(
style: const HoverStyle(
borderRadius: BorderRadius.all(Radius.circular(8.0)),
),
child: Padding(
padding: const EdgeInsetsDirectional.all(6.0),
child: FlowyText(
_getDescription(),
fontSize: 12.0,
figmaLineHeight: 16.0,
return FlowyIconButton(
tooltipText: showFormatBar
? LocaleKeys.chat_changeFormat_defaultDescription.tr()
: LocaleKeys.chat_changeFormat_blankDescription.tr(),
width: 28.0,
onPressed: onTap,
icon: showFormatBar
? const FlowySvg(
FlowySvgs.m_aa_text_s,
size: Size.square(16.0),
color: Color(0xFF666D76),
)
: const FlowySvg(
FlowySvgs.ai_text_image_s,
size: Size(21.0, 16.0),
color: Color(0xFF666D76),
),
),
),
),
);
}

String _getDescription() {
if (!showFormatBar) {
return LocaleKeys.chat_changeFormat_blankDescription.tr();
}

return switch ((predefinedFormat, predefinedTextFormat)) {
(ImageFormat.image, _) => predefinedFormat.i18n,
(ImageFormat.text, TextFormat.auto) =>
LocaleKeys.chat_changeFormat_defaultDescription.tr(),
(ImageFormat.text, _) when predefinedTextFormat != null =>
predefinedTextFormat!.i18n,
(ImageFormat.textAndImage, TextFormat.auto) =>
LocaleKeys.chat_changeFormat_textWithImageDescription.tr(),
(ImageFormat.textAndImage, TextFormat.bulletList) =>
LocaleKeys.chat_changeFormat_bulletWithImageDescription.tr(),
(ImageFormat.textAndImage, TextFormat.numberedList) =>
LocaleKeys.chat_changeFormat_numberWithImageDescription.tr(),
(ImageFormat.textAndImage, TextFormat.table) =>
LocaleKeys.chat_changeFormat_tableWithImageDescription.tr(),
_ => throw UnimplementedError(),
};
}
}

class ChangeFormatBar extends StatelessWidget {
Expand All @@ -80,7 +55,7 @@ class ChangeFormatBar extends StatelessWidget {
required this.onSelectPredefinedFormat,
});

final PredefinedFormat predefinedFormat;
final PredefinedFormat? predefinedFormat;
final double buttonSize;
final double iconSize;
final double spacing;
Expand All @@ -97,7 +72,7 @@ class ChangeFormatBar extends StatelessWidget {
_buildFormatButton(context, ImageFormat.text),
_buildFormatButton(context, ImageFormat.textAndImage),
_buildFormatButton(context, ImageFormat.image),
if (predefinedFormat.imageFormat.hasText) ...[
if (predefinedFormat?.imageFormat.hasText ?? true) ...[
_buildDivider(),
_buildTextFormatButton(context, TextFormat.auto),
_buildTextFormatButton(context, TextFormat.bulletList),
Expand All @@ -113,11 +88,12 @@ class ChangeFormatBar extends StatelessWidget {
return GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
if (format == predefinedFormat.imageFormat) {
if (predefinedFormat != null &&
format == predefinedFormat!.imageFormat) {
return;
}
if (format.hasText) {
final textFormat = predefinedFormat.textFormat ?? TextFormat.auto;
final textFormat = predefinedFormat?.textFormat ?? TextFormat.auto;
onSelectPredefinedFormat(
PredefinedFormat(imageFormat: format, textFormat: textFormat),
);
Expand All @@ -132,7 +108,7 @@ class ChangeFormatBar extends StatelessWidget {
child: SizedBox.square(
dimension: buttonSize,
child: FlowyHover(
isSelected: () => format == predefinedFormat.imageFormat,
isSelected: () => format == predefinedFormat?.imageFormat,
child: Center(
child: FlowySvg(
format.icon,
Expand Down Expand Up @@ -162,12 +138,13 @@ class ChangeFormatBar extends StatelessWidget {
return GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
if (format == predefinedFormat.textFormat) {
if (predefinedFormat != null &&
format == predefinedFormat!.textFormat) {
return;
}
onSelectPredefinedFormat(
PredefinedFormat(
imageFormat: predefinedFormat.imageFormat,
imageFormat: predefinedFormat?.imageFormat ?? ImageFormat.text,
textFormat: format,
),
);
Expand All @@ -177,7 +154,7 @@ class ChangeFormatBar extends StatelessWidget {
child: SizedBox.square(
dimension: buttonSize,
child: FlowyHover(
isSelected: () => format == predefinedFormat.textFormat,
isSelected: () => format == predefinedFormat?.textFormat,
child: Center(
child: FlowySvg(
format.icon,
Expand Down Expand Up @@ -211,8 +188,8 @@ class PromptInputMobileToggleFormatButton extends StatelessWidget {
expandText: false,
text: showFormatBar
? const FlowySvg(
FlowySvgs.ai_text_auto_s,
size: Size.square(24.0),
FlowySvgs.m_aa_text_s,
size: Size.square(20.0),
)
: const FlowySvg(
FlowySvgs.ai_text_image_s,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:appflowy/util/theme_extension.dart';
import 'package:flutter/material.dart';
import 'package:universal_platform/universal_platform.dart';

Expand All @@ -17,6 +18,14 @@ class AIChatUILayout {
static EdgeInsets get messageMargin => UniversalPlatform.isMobile
? const EdgeInsets.symmetric(horizontal: 16)
: EdgeInsets.zero;

static TextStyle? inputHintTextStyle(BuildContext context) {
return Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).isLightMode
? const Color(0xFFBDC2C8)
: const Color(0xFF3C3E51),
);
}
}

class DesktopAIPromptSizes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class _ChangeFormatBottomSheetContent extends StatefulWidget {

class _ChangeFormatBottomSheetContentState
extends State<_ChangeFormatBottomSheetContent> {
PredefinedFormat predefinedFormat = const PredefinedFormat.auto();
PredefinedFormat? predefinedFormat;

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -106,7 +106,7 @@ class _Body extends StatelessWidget {
required this.onSelectPredefinedFormat,
});

final PredefinedFormat predefinedFormat;
final PredefinedFormat? predefinedFormat;
final void Function(PredefinedFormat) onSelectPredefinedFormat;

@override
Expand All @@ -119,7 +119,7 @@ class _Body extends StatelessWidget {
_buildFormatButton(ImageFormat.image),
const VSpace(32.0),
Opacity(
opacity: predefinedFormat.imageFormat.hasText ? 1 : 0,
opacity: predefinedFormat?.imageFormat.hasText ?? true ? 1 : 0,
child: Column(
children: [
_buildTextFormatButton(TextFormat.auto, true),
Expand All @@ -139,7 +139,7 @@ class _Body extends StatelessWidget {
]) {
return FlowyOptionTile.checkbox(
text: format.i18n,
isSelected: format == predefinedFormat.imageFormat,
isSelected: format == predefinedFormat?.imageFormat,
showTopBorder: isFirst,
leftIcon: FlowySvg(
format.icon,
Expand All @@ -148,11 +148,12 @@ class _Body extends StatelessWidget {
: const Size.square(20),
),
onTap: () {
if (format == predefinedFormat.imageFormat) {
if (predefinedFormat != null &&
format == predefinedFormat!.imageFormat) {
return;
}
if (format.hasText) {
final textFormat = predefinedFormat.textFormat ?? TextFormat.auto;
final textFormat = predefinedFormat?.textFormat ?? TextFormat.auto;
onSelectPredefinedFormat(
PredefinedFormat(imageFormat: format, textFormat: textFormat),
);
Expand All @@ -171,19 +172,20 @@ class _Body extends StatelessWidget {
]) {
return FlowyOptionTile.checkbox(
text: format.i18n,
isSelected: format == predefinedFormat.textFormat,
isSelected: format == predefinedFormat?.textFormat,
showTopBorder: isFirst,
leftIcon: FlowySvg(
format.icon,
size: const Size.square(20),
),
onTap: () {
if (format == predefinedFormat.textFormat) {
if (predefinedFormat != null &&
format == predefinedFormat!.textFormat) {
return;
}
onSelectPredefinedFormat(
PredefinedFormat(
imageFormat: predefinedFormat.imageFormat,
imageFormat: predefinedFormat?.imageFormat ?? ImageFormat.text,
textFormat: format,
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ class _ChangeFormatPopoverContent extends StatefulWidget {

class _ChangeFormatPopoverContentState
extends State<_ChangeFormatPopoverContent> {
PredefinedFormat predefinedFormat = const PredefinedFormat.auto();
PredefinedFormat? predefinedFormat;

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -362,7 +362,10 @@ class _ChangeFormatPopoverContentState
cursor: SystemMouseCursors.click,
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () => widget.onRegenerate?.call(predefinedFormat),
onTap: () {
widget.onRegenerate
?.call(predefinedFormat ?? const PredefinedFormat.auto());
},
child: SizedBox.square(
dimension: DesktopAIPromptSizes.predefinedFormatButtonHeight,
child: Center(
Expand Down Expand Up @@ -467,7 +470,9 @@ class _SaveToPageButtonState extends State<SaveToPageButton> {
final documentId = getOpenedDocumentId();
if (documentId != null) {
await onAddToExistingPage(context, documentId);
await forceReloadAndUpdateSelection(documentId);
await forceReload(documentId);
await Future.delayed(const Duration(milliseconds: 500));
await updateSelection(documentId);
} else {
widget.onOverrideVisibility?.call(true);
if (spaceView != null) {
Expand Down Expand Up @@ -497,6 +502,8 @@ class _SaveToPageButtonState extends State<SaveToPageButton> {
if (context.mounted) {
openPageFromMessage(context, view);
}
await Future.delayed(const Duration(milliseconds: 500));
await updateSelection(documentId);
},
),
);
Expand Down Expand Up @@ -565,14 +572,20 @@ class _SaveToPageButtonState extends State<SaveToPageButton> {
);
}

Future<void> forceReloadAndUpdateSelection(String documentId) async {
Future<void> forceReload(String documentId) async {
final bloc = DocumentBloc.findOpen(documentId);
if (bloc == null) {
return;
}
await bloc.forceReloadDocumentState();
await Future.delayed(const Duration(milliseconds: 500));
}

Future<void> updateSelection(String documentId) async {
final bloc = DocumentBloc.findOpen(documentId);
if (bloc == null) {
return;
}
await bloc.forceReloadDocumentState();
final editorState = bloc.state.editorState;
final lastNodePath = editorState?.getLastSelectable()?.$1.path;
if (editorState == null || lastNodePath == null) {
Expand Down
Loading

0 comments on commit d1efda4

Please sign in to comment.