Skip to content

Commit

Permalink
fix: launch review
Browse files Browse the repository at this point in the history
  • Loading branch information
richardshiue committed Jan 10, 2025
1 parent 790d561 commit 3dad1a0
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 77 deletions.
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/ai_chat/application/ai_prompt_input_bloc.dart';
import 'package:appflowy/plugins/ai_chat/application/chat_input_control_cubit.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/util/theme_extension.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/protobuf.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:extended_text_field/extended_text_field.dart';
Expand Down Expand Up @@ -49,8 +50,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 +189,6 @@ class _DesktopAIPromptInputState extends State<DesktopAIPromptInput> {
setState(() {
showPredefinedFormatSection =
!showPredefinedFormatSection;
if (!showPredefinedFormatSection) {
predefinedFormat =
const PredefinedFormat.auto();
}
});
},
sendButtonState: sendButtonState,
Expand Down Expand Up @@ -466,10 +466,11 @@ 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: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).isLightMode
? const Color(0xFFBDC2C8)
: const Color(0xFF3C3E51),
),
isCollapsed: true,
isDense: true,
),
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/ai_chat/application/ai_prompt_input_bloc.dart';
import 'package:appflowy/plugins/ai_chat/application/chat_entity.dart';
import 'package:appflowy/plugins/ai_chat/application/chat_input_control_cubit.dart';
import 'package:appflowy/util/theme_extension.dart';
import 'package:appflowy/workspace/application/view/view_ext.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:extended_text_field/extended_text_field.dart';
Expand Down Expand Up @@ -43,8 +44,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 +269,11 @@ class _MobileAIPromptInputState extends State<MobileAIPromptInput> {
AIType.appflowyAI => LocaleKeys.chat_inputMessageHint.tr(),
AIType.localAI => LocaleKeys.chat_inputLocalAIMessageHint.tr()
},
hintStyle: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).isLightMode
? const Color(0xFFBDC2C8)
: const Color(0xFF3C3E51),
),
isCollapsed: true,
isDense: true,
),
Expand Down Expand Up @@ -304,9 +313,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
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

0 comments on commit 3dad1a0

Please sign in to comment.