Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
chore: new design for custom prompt (#7833)
Richard Shiueecb1c07917b0
diff --git a/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_category_list.dart b/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_category_list.dartindex 8afd82b919..ee8bc89b5a 100644--- a/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_category_list.dart+++ b/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_category_list.dart@@ -5,7 +5,7 @@ import 'package:easy_localization/easy_localization.dart';import 'package:flutter/material.dart';import 'package:flutter_bloc/flutter_bloc.dart';-class AiPromptCategoryList extends StatelessWidget {+class AiPromptCategoryList extends StatefulWidget {const AiPromptCategoryList({super.key,required this.padding,@@ -13,19 +13,26 @@ class AiPromptCategoryList extends StatelessWidget {final EdgeInsetsGeometry padding;+ @override+ State<AiPromptCategoryList> createState() => _AiPromptCategoryListState();+}++class _AiPromptCategoryListState extends State<AiPromptCategoryList> {+ bool isSearching = false;@overrideWidget build(BuildContext context) {final theme = AppFlowyTheme.of(context);return Padding(- padding: padding,+ padding: EdgeInsets.all(+ theme.spacing.l,+ ),child: TextFieldTapRegion(groupId: "ai_prompt_category_list",child: Column(crossAxisAlignment: CrossAxisAlignment.stretch,spacing: theme.spacing.s,children: [- _buildSearchField(context),_buildFeaturedCategory(context),const AFDivider(),Expanded(@@ -62,16 +69,6 @@ class AiPromptCategoryList extends StatelessWidget {);}- Widget _buildSearchField(BuildContext context) {- return AFTextField(- groupId: "ai_prompt_category_list",- hintText: "Search",- size: AFTextFieldSize.m,- controller: context.read<AiPromptSelectorCubit>().filterTextController,- autoFocus: true,- );- }-Widget _buildCategoryItem(BuildContext context,AiPromptCategory? category,diff --git a/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_modal.dart b/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_modal.dartindex fac3ec1068..2f56bfaefb 100644--- a/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_modal.dart+++ b/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_modal.dart@@ -88,12 +88,7 @@ class AiPromptModal extends StatelessWidget {),Expanded(flex: 2,- child: AiPromptVisibleList(- padding: EdgeInsets.symmetric(- vertical: theme.spacing.l,- horizontal: theme.spacing.l,- ),- ),+ child: AiPromptVisibleList(),),Expanded(flex: 3,@@ -115,10 +110,6 @@ class AiPromptModal extends StatelessWidget {}return AiPromptPreview(prompt: selectedPrompt,- padding: EdgeInsets.symmetric(- vertical: theme.spacing.l,- horizontal: theme.spacing.l,- ),);},),@@ -131,20 +122,6 @@ class AiPromptModal extends StatelessWidget {),),),- AFModalFooter(- trailing: [- AFFilledTextButton.primary(- text: LocaleKeys.ai_customPrompt_usePrompt.tr(),- onTap: () {- final selectedPrompt =- context.read<AiPromptSelectorCubit>().selectedPrompt;- if (selectedPrompt != null) {- Navigator.of(context).pop(selectedPrompt);- }- },- ),- ],- ),],),);diff --git a/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_preview.dart b/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_preview.dartindex bcbcfb25db..a61570b548 100644--- a/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_preview.dart+++ b/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_preview.dart@@ -10,57 +10,83 @@ class AiPromptPreview extends StatelessWidget {const AiPromptPreview({super.key,required this.prompt,- required this.padding,});final AiPrompt prompt;- final EdgeInsetsGeometry padding;@overrideWidget build(BuildContext context) {final theme = AppFlowyTheme.of(context);return SelectionArea(- child: ListView(- padding: padding,+ child: Column(children: [- SelectionContainer.disabled(- child: Text(- prompt.name,- style: theme.textStyle.headline.standard(- color: theme.textColorScheme.primary,- ),+ Padding(+ padding: EdgeInsets.only(+ top: theme.spacing.l,+ left: theme.spacing.l,+ right: theme.spacing.l,),- ),- VSpace(theme.spacing.xs),- SelectionContainer.disabled(- child: Text(- LocaleKeys.ai_customPrompt_prompt.tr(),- style: theme.textStyle.heading4.standard(- color: theme.textColorScheme.primary,+ child: SelectionContainer.disabled(+ child: Row(+ children: [+ Expanded(+ child: Text(+ prompt.name,+ style: theme.textStyle.headline.standard(+ color: theme.textColorScheme.primary,+ ),+ ),+ ),+ HSpace(theme.spacing.s),+ AFFilledTextButton.primary(+ text: LocaleKeys.ai_customPrompt_usePrompt.tr(),+ onTap: () {+ Navigator.of(context).pop(prompt);+ },+ ),+ ],),),),VSpace(theme.spacing.xs),- _PromptContent(- prompt: prompt,- ),- VSpace(theme.spacing.xl),- if (prompt.example.isNotEmpty) ...[- SelectionContainer.disabled(- child: Text(- LocaleKeys.ai_customPrompt_example.tr(),- style: theme.textStyle.heading4.standard(- color: theme.textColorScheme.primary,- ),+ Expanded(+ child: ListView(+ padding: EdgeInsets.all(+ theme.spacing.l,),+ children: [+ SelectionContainer.disabled(+ child: Text(+ LocaleKeys.ai_customPrompt_prompt.tr(),+ style: theme.textStyle.heading4.standard(+ color: theme.textColorScheme.primary,+ ),+ ),+ ),+ VSpace(theme.spacing.xs),+ _PromptContent(+ prompt: prompt,+ ),+ VSpace(theme.spacing.xl),+ if (prompt.example.isNotEmpty) ...[+ SelectionContainer.disabled(+ child: Text(+ LocaleKeys.ai_customPrompt_example.tr(),+ style: theme.textStyle.heading4.standard(+ color: theme.textColorScheme.primary,+ ),+ ),+ ),+ VSpace(theme.spacing.xs),+ _PromptExample(+ prompt: prompt,+ ),+ VSpace(theme.spacing.xl),+ ],+ ],),- VSpace(theme.spacing.xs),- _PromptExample(- prompt: prompt,- ),- VSpace(theme.spacing.xl),- ],+ ),],),);diff --git a/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_visible_list.dart b/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_visible_list.dartindex 72d7bdc91d..64b58cb4a1 100644--- a/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_visible_list.dart+++ b/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_visible_list.dart@@ -1,7 +1,14 @@+import 'dart:async';+import 'package:appflowy/ai/ai.dart';+import 'package:appflowy/generated/flowy_svgs.g.dart';+import 'package:appflowy/generated/locale_keys.g.dart';+import 'package:appflowy/util/theme_extension.dart';import 'package:appflowy_ui/appflowy_ui.dart';import 'package:diffutil_dart/diffutil.dart';-import 'package:flutter/widgets.dart';+import 'package:easy_localization/easy_localization.dart';+import 'package:flowy_infra_ui/widget/spacing.dart';+import 'package:flutter/material.dart';import 'package:flutter_bloc/flutter_bloc.dart';const Duration _listItemAnimationDuration = Duration(milliseconds: 150);@@ -9,11 +16,8 @@ const Duration _listItemAnimationDuration = Duration(milliseconds: 150);class AiPromptVisibleList extends StatefulWidget {const AiPromptVisibleList({super.key,- required this.padding,});- final EdgeInsetsGeometry padding;-@overrideState<AiPromptVisibleList> createState() => _AiPromptVisibleListState();}@@ -23,18 +27,26 @@ class _AiPromptVisibleListState extends State<AiPromptVisibleList> {final scrollController = ScrollController();final List<AiPrompt> oldList = [];+ late AiPromptSelectorCubit cubit;+ late bool filterIsEmpty;+@overridevoid initState() {super.initState();- final prompts = context.read<AiPromptSelectorCubit>().state.maybeMap(- ready: (value) => value.visiblePrompts,- orElse: () => <AiPrompt>[],- );+ cubit = context.read<AiPromptSelectorCubit>();+ final textController = cubit.filterTextController;+ final prompts = cubit.state.maybeMap(+ ready: (value) => value.visiblePrompts,+ orElse: () => <AiPrompt>[],+ );+ filterIsEmpty = textController.text.isEmpty;+ textController.addListener(handleFilterTextChanged);oldList.addAll(prompts);}@overridevoid dispose() {+ cubit.filterTextController.removeListener(handleFilterTextChanged);scrollController.dispose();super.dispose();}@@ -50,34 +62,82 @@ class _AiPromptVisibleListState extends State<AiPromptVisibleList> {);handleVisiblePromptListChanged(list);},- child: AnimatedList(- controller: scrollController,- padding: widget.padding,- key: listKey,- initialItemCount: oldList.length,- itemBuilder: (context, index, animation) {- final cubit = context.read<AiPromptSelectorCubit>();-- return cubit.state.maybeMap(- ready: (state) {- final prompt = state.visiblePrompts[index];- return Padding(- padding: EdgeInsets.only(- top: index == 0 ? 0 : spacing.s,- bottom:- index == state.visiblePrompts.length - 1 ? 0 : spacing.s,- ),- child: _AiPromptListItem(- animation: animation,- prompt: prompt,- isSelected: state.selectedPromptId == prompt.id,- ),- );- },- orElse: () => const SizedBox.shrink(),- );- },+ child: Column(+ children: [+ VSpace(spacing.l),+ Padding(+ padding: EdgeInsets.symmetric(horizontal: spacing.l),+ child: buildSearchField(context),+ ),+ VSpace(spacing.s),+ Expanded(+ child: AnimatedList(+ controller: scrollController,+ padding: EdgeInsets.all(spacing.l),+ key: listKey,+ initialItemCount: oldList.length,+ itemBuilder: (context, index, animation) {+ final cubit = context.read<AiPromptSelectorCubit>();++ return cubit.state.maybeMap(+ ready: (state) {+ final prompt = state.visiblePrompts[index];+ return Padding(+ padding: EdgeInsets.only(+ top: index == 0 ? 0 : spacing.s,+ bottom: index == state.visiblePrompts.length - 1+ ? 0+ : spacing.s,+ ),+ child: _AiPromptListItem(+ animation: animation,+ prompt: prompt,+ isSelected: state.selectedPromptId == prompt.id,+ ),+ );+ },+ orElse: () => const SizedBox.shrink(),+ );+ },+ ),+ ),+ ],+ ),+ );+ }++ Widget buildSearchField(BuildContext context) {+ final theme = AppFlowyTheme.of(context);+ final iconSize = 20.0;++ return AFTextField(+ groupId: "ai_prompt_category_list",+ hintText: "Search",+ controller: context.read<AiPromptSelectorCubit>().filterTextController,+ autoFocus: true,+ suffixIconConstraints: BoxConstraints.tightFor(+ width: iconSize + theme.spacing.m,+ height: iconSize,),+ suffixIconBuilder: filterIsEmpty+ ? null+ : (context, isObscured) => TextFieldTapRegion(+ groupId: "ai_prompt_category_list",+ child: Padding(+ padding: EdgeInsets.only(right: theme.spacing.m),+ child: GestureDetector(+ onTap: () => context+ .read<AiPromptSelectorCubit>()+ .filterTextController+ .clear(),+ child: FlowySvg(+ FlowySvgs.toast_close_s,+ color: theme.textColorScheme.secondary,+ size: const Size.square(20),+ ),+ ),+ ),+ ),);}@@ -120,6 +180,12 @@ class _AiPromptVisibleListState extends State<AiPromptVisibleList> {..clear()..addAll(newList);}++ void handleFilterTextChanged() {+ setState(() {+ filterIsEmpty = cubit.filterTextController.text.isEmpty;+ });+ }}class _AiPromptListItem extends StatefulWidget {@@ -139,6 +205,14 @@ class _AiPromptListItem extends StatefulWidget {class _AiPromptListItemState extends State<_AiPromptListItem> {bool isHovering = false;+ Timer? timer;++ @override+ void dispose() {+ timer?.cancel();+ timer = null;+ super.dispose();+ }@overrideWidget build(BuildContext context) {@@ -150,68 +224,114 @@ class _AiPromptListItemState extends State<_AiPromptListItem> {curve: Curves.easeIn,);+ final surfacePrimaryHover =+ Theme.of(context).isLightMode ? Color(0xFFF8FAFF) : Color(0xFF3C3F4E);+return FadeTransition(opacity: curvedAnimation,child: SizeTransition(sizeFactor: curvedAnimation,child: MouseRegion(onEnter: (_) {- setState(() => isHovering = true);+ setState(() {+ isHovering = true;+ timer = Timer(const Duration(milliseconds: 300), () {+ if (mounted) {+ cubit.selectPrompt(widget.prompt.id);+ }+ });+ });},onExit: (_) {- setState(() => isHovering = false);+ setState(() {+ isHovering = false;+ timer?.cancel();+ });},child: GestureDetector(onTap: () {cubit.selectPrompt(widget.prompt.id);},- onDoubleTap: () {- Navigator.of(context).pop(widget.prompt);- },- child: Container(- padding: EdgeInsets.all(theme.spacing.m),- decoration: BoxDecoration(- borderRadius: BorderRadius.circular(theme.borderRadius.m),- border: Border.all(- color: widget.isSelected- ? isHovering- ? theme.borderColorScheme.themeThickHover- : theme.borderColorScheme.themeThick- : isHovering- ? theme.borderColorScheme.greyTertiaryHover- : theme.borderColorScheme.greyTertiary,- ),- color: theme.surfaceColorScheme.primary,- ),- child: Column(- crossAxisAlignment: CrossAxisAlignment.start,- children: [- Row(+ child: Stack(+ children: [+ Container(+ padding: EdgeInsets.all(theme.spacing.m),+ decoration: BoxDecoration(+ borderRadius: BorderRadius.circular(theme.borderRadius.m),+ border: Border.all(+ color: widget.isSelected+ ? isHovering+ ? theme.borderColorScheme.themeThickHover+ : theme.borderColorScheme.themeThick+ : isHovering+ ? theme.borderColorScheme.greyTertiaryHover+ : theme.borderColorScheme.greyTertiary,+ ),+ color: theme.surfaceColorScheme.primary,+ ),+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.start,children: [- Expanded(- child: Text(- widget.prompt.name,- maxLines: 1,- style: theme.textStyle.body.standard(- color: theme.textColorScheme.primary,+ Row(+ children: [+ Expanded(+ child: Text(+ widget.prompt.name,+ maxLines: 1,+ style: theme.textStyle.body.standard(+ color: theme.textColorScheme.primary,+ ),+ overflow: TextOverflow.ellipsis,+ softWrap: true,+ ),),- overflow: TextOverflow.ellipsis,- softWrap: true,+ ],+ ),+ Text(+ widget.prompt.content,+ maxLines: 2,+ style: theme.textStyle.caption.standard(+ color: theme.textColorScheme.secondary,),+ overflow: TextOverflow.ellipsis,+ softWrap: true,),],),- Text(- widget.prompt.content,- maxLines: 2,- style: theme.textStyle.caption.standard(- color: theme.textColorScheme.secondary,+ ),+ if (isHovering)+ Positioned(+ top: theme.spacing.s,+ right: theme.spacing.s,+ child: DecoratedBox(+ decoration: BoxDecoration(boxShadow: theme.shadow.small),+ child: AFBaseButton(+ onTap: () {+ Navigator.of(context).pop(widget.prompt);+ },+ builder: (context, isHovering, disabled) {+ return Text(+ LocaleKeys.ai_customPrompt_usePrompt.tr(),+ style: theme.textStyle.body.standard(+ color: theme.textColorScheme.primary,+ ),+ );+ },+ backgroundColor: (context, isHovering, disabled) {+ if (isHovering) {+ return surfacePrimaryHover;+ }+ return theme.surfaceColorScheme.primary;+ },+ padding: EdgeInsets.symmetric(+ vertical: theme.spacing.s,+ horizontal: theme.spacing.m,+ ),+ borderRadius: theme.borderRadius.m,+ ),),- overflow: TextOverflow.ellipsis,- softWrap: true,),- ],- ),+ ],),),),diff --git a/frontend/appflowy_flutter/lib/ai/widgets/prompt_input/prompt_input_text_controller.dart b/frontend/appflowy_flutter/lib/ai/widgets/prompt_input/prompt_input_text_controller.dartindex dcbd8fa380..3dfa67d224 100644--- a/frontend/appflowy_flutter/lib/ai/widgets/prompt_input/prompt_input_text_controller.dart+++ b/frontend/appflowy_flutter/lib/ai/widgets/prompt_input/prompt_input_text_controller.dart@@ -58,7 +58,7 @@ class AiPromptInputTextEditingController extends TextEditingController {style: theme.textStyle.body.standard().copyWith(color: theme.textColorScheme.purple,backgroundColor:- theme.fillColorScheme.purpleLight.withAlpha(128),+ theme.fillColorScheme.purpleThick.withAlpha(51),),),);diff --git a/frontend/resources/translations/en.json b/frontend/resources/translations/en.jsonindex 4f72aef3e6..b0c05c6f5b 100644--- a/frontend/resources/translations/en.json+++ b/frontend/resources/translations/en.json@@ -3307,7 +3307,7 @@"travel": "Travel","others": "Other","prompt": "Prompt",- "example": "Example",+ "example": "Prompt Example","sampleOutput": "Sample output","contentSeo": "Content/SEO","emailMarketing": "Email Marketing",@@ -3349,4 +3349,4 @@"rewrite": "Rewrite","insertBelow": "Insert below"}-}\ No newline at end of file+}