Skip to content

Commit

Permalink
opt.: chat btns if mouse cursor exists (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
lollipopkit authored Aug 6, 2024
1 parent 1741448 commit a877db5
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 34 deletions.
9 changes: 7 additions & 2 deletions lib/data/model/chat/history/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
),
],
);
}
Expand Down
154 changes: 125 additions & 29 deletions lib/view/page/home/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -128,7 +128,6 @@ class _ChatPageState extends State<_ChatPage>
_switchNextChat();
break;
}
return Future.value();
},
child: child,
);
Expand All @@ -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<Widget> _buildChatItemHovers(
List<ChatHistoryItem> 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<Widget> _buildChatItemFuncs(
List<ChatHistoryItem> chatItems,
ChatHistoryItem chatItem,
) {
// && Stores.setting.replay.fetch()
final replayEnabled = chatItem.role.isUser;

return [
Expand Down
1 change: 1 addition & 0 deletions lib/view/page/home/home.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit a877db5

Please sign in to comment.