From a877db592ba5019a0e5899ba7a63238591943b31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?lollipopkit=F0=9F=8F=B3=EF=B8=8F=E2=80=8D=E2=9A=A7?= =?UTF-8?q?=EF=B8=8F?= <10864310+lollipopkit@users.noreply.github.com> Date: Tue, 6 Aug 2024 19:09:50 +0800 Subject: [PATCH] opt.: chat btns if mouse cursor exists (#138) --- lib/data/model/chat/history/view.dart | 9 +- lib/view/page/home/chat.dart | 154 +++++++++++++++++++++----- lib/view/page/home/home.dart | 1 + pubspec.lock | 4 +- pubspec.yaml | 2 +- 5 files changed, 136 insertions(+), 34 deletions(-) diff --git a/lib/data/model/chat/history/view.dart b/lib/data/model/chat/history/view.dart index 4ed205c..c27b794 100644 --- a/lib/data/model/chat/history/view.dart +++ b/lib/data/model/chat/history/view.dart @@ -50,10 +50,15 @@ final class ChatRoleTitle extends StatelessWidget { ); if (!loading) return label; return Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, + mainAxisAlignment: MainAxisAlignment.start, children: [ label, - const SizedBox(width: 37, child: LinearProgressIndicator()), + UIs.width13, + const SizedBox( + height: 15, + width: 15, + child: CircularProgressIndicator(), + ), ], ); } diff --git a/lib/view/page/home/chat.dart b/lib/view/page/home/chat.dart index 899d929..2e8850b 100644 --- a/lib/view/page/home/chat.dart +++ b/lib/view/page/home/chat.dart @@ -118,7 +118,7 @@ class _ChatPageState extends State<_ChatPage> if (!scrollSwitchChat) return child; return SwitchIndicator( - onSwitchPage: (direction) { + onSwitchPage: (direction) async { switchDirection = direction; switch (direction) { case SwitchDirection.previous: @@ -128,7 +128,6 @@ class _ChatPageState extends State<_ChatPage> _switchNextChat(); break; } - return Future.value(); }, child: child, ); @@ -153,43 +152,140 @@ class _ChatPageState extends State<_ChatPage> ), }; - return InkWell( - borderRadius: BorderRadius.circular(13), - onLongPress: () { - final funcs = _buildChatItemFuncs(chatItems, chatItem); - context.showRoundDialog( - contentPadding: const EdgeInsets.all(11), - child: SingleChildScrollView( - child: Column( - mainAxisSize: MainAxisSize.min, - children: funcs, - ), - ), + final child = Padding( + padding: const EdgeInsets.only(top: 11, left: 11, right: 11, bottom: 2), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + title, + UIs.height13, + ListenBuilder( + listenable: node, + builder: () => ChatHistoryContentView(chatItem: chatItem), + ).paddingSymmetric(horizontal: 2), + UIs.height13, + ], + ), + ); + + return _isWide.listenVal( + (wide) { + final content = InkWell( + borderRadius: BorderRadius.circular(13), + onLongPress: wide + ? null + : () { + final funcs = _buildChatItemFuncs(chatItems, chatItem); + context.showRoundDialog( + contentPadding: const EdgeInsets.all(11), + child: SingleChildScrollView( + child: Column( + mainAxisSize: MainAxisSize.min, + children: funcs, + ), + ), + ); + }, + child: child, + ); + if (!wide) return content; + + final hovers = _buildChatItemHovers(chatItems, chatItem); + return Hover( + builder: (bool isHovered) { + final hover = AnimatedContainer( + duration: Durations.medium1, + curve: Curves.fastEaseInToSlowEaseOut, + width: isHovered ? hovers.length * 33.7 : 0, + height: 30, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(13), + ), + child: SingleChildScrollView( + scrollDirection: Axis.horizontal, + child: Row( + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.center, + children: hovers, + ), + ), + ); + return Stack( + children: [ + content, + Align(alignment: Alignment.topRight, child: hover), + ], + ); + }, ); }, - child: Padding( - padding: const EdgeInsets.only(top: 11, left: 11, right: 11, bottom: 2), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - title, - UIs.height13, - ListenBuilder( - listenable: node, - builder: () => ChatHistoryContentView(chatItem: chatItem), - ).paddingSymmetric(horizontal: 2), - UIs.height13, - ], + ); + } + + List _buildChatItemHovers( + List chatItems, + ChatHistoryItem chatItem, + ) { + final replayEnabled = chatItem.role.isUser; + const size = 19.0; + + return [ + Btn.icon( + onTap: () { + context.pop(); + _MarkdownCopyPage.go(context, chatItem); + }, + text: l10n.freeCopy, + icon: const Icon(BoxIcons.bxs_crop, size: size), + ), + if (replayEnabled) + ListenBuilder( + listenable: _sendBtnRN, + builder: () { + final isWorking = _loadingChatIds.contains(_curChatId); + if (isWorking) return UIs.placeholder; + return Btn.icon( + onTap: () { + context.pop(); + _onTapReplay(context, _curChatId, chatItem); + }, + text: l10n.replay, + icon: const Icon(MingCute.refresh_4_line, size: size), + ); + }, + ), + if (replayEnabled) + Btn.icon( + onTap: () { + context.pop(); + _onTapEditMsg(context, chatItem); + }, + text: libL10n.edit, + icon: const Icon(Icons.edit, size: size), ), + Btn.icon( + onTap: () { + context.pop(); + _onTapDelChatItem(context, chatItems, chatItem); + }, + text: l10n.delete, + icon: const Icon(Icons.delete, size: size), ), - ); + Btn.icon( + onTap: () { + context.pop(); + Pfs.copy(chatItem.toMarkdown); + }, + text: libL10n.copy, + icon: const Icon(MingCute.copy_2_fill, size: size), + ), + ]; } List _buildChatItemFuncs( List chatItems, ChatHistoryItem chatItem, ) { - // && Stores.setting.replay.fetch() final replayEnabled = chatItem.role.isUser; return [ diff --git a/lib/view/page/home/home.dart b/lib/view/page/home/home.dart index 0118e4d..56c7f0a 100644 --- a/lib/view/page/home/home.dart +++ b/lib/view/page/home/home.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'dart:io'; import 'dart:math' as math; +import 'dart:ui'; import 'package:app_links/app_links.dart'; import 'package:dart_openai/dart_openai.dart'; diff --git a/pubspec.lock b/pubspec.lock index b83b507..62ec51e 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -407,8 +407,8 @@ packages: dependency: "direct main" description: path: "." - ref: "v1.0.118" - resolved-ref: "3c55c8b4b7b4cf503a8013087b5480be3669ff63" + ref: "v1.0.119" + resolved-ref: c3bf044e937ea8f07a390ae5a0506e146e434fb7 url: "https://github.com/lppcg/fl_lib" source: git version: "0.0.1" diff --git a/pubspec.yaml b/pubspec.yaml index 3f30147..0bca539 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -36,7 +36,7 @@ dependencies: fl_lib: git: url: https://github.com/lppcg/fl_lib - ref: v1.0.118 + ref: v1.0.119 dependency_overrides: # fl_lib: