💄 Optimzation and fixes
This commit is contained in:
@ -27,16 +27,19 @@ class AccountShellScreen extends HookConsumerWidget {
|
||||
final isWide = isWideScreen(context);
|
||||
|
||||
if (isWide) {
|
||||
return Row(
|
||||
children: [
|
||||
SizedBox(width: 360, child: AccountScreen(isAside: true)),
|
||||
VerticalDivider(width: 1),
|
||||
Expanded(child: AutoRouter()),
|
||||
],
|
||||
return AppBackground(
|
||||
isRoot: true,
|
||||
child: Row(
|
||||
children: [
|
||||
SizedBox(width: 360, child: AccountScreen(isAside: true)),
|
||||
VerticalDivider(width: 1),
|
||||
Expanded(child: AutoRouter()),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return AutoRouter();
|
||||
return AppBackground(isRoot: true, child: AutoRouter());
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,7 +52,7 @@ class AccountScreen extends HookConsumerWidget {
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final isWide = isWideScreen(context);
|
||||
if (isWide && !isAside) {
|
||||
return Container(color: Theme.of(context).scaffoldBackgroundColor);
|
||||
return const EmptyPageHolder();
|
||||
}
|
||||
|
||||
final user = ref.watch(userInfoProvider);
|
||||
@ -62,6 +65,7 @@ class AccountScreen extends HookConsumerWidget {
|
||||
}
|
||||
|
||||
return AppScaffold(
|
||||
noBackground: isWide,
|
||||
appBar: AppBar(title: const Text('account').tr()),
|
||||
body: SingleChildScrollView(
|
||||
child: Column(
|
||||
|
@ -85,9 +85,12 @@ class ChatRoomListTile extends HookConsumerWidget {
|
||||
),
|
||||
Expanded(
|
||||
child: Text(
|
||||
data.lastMessage.content ?? 'messageNone'.tr(),
|
||||
(data.lastMessage.content?.isNotEmpty ?? false)
|
||||
? data.lastMessage.content!
|
||||
: 'messageNone'.tr(),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
@ -182,16 +185,19 @@ class ChatShellScreen extends HookConsumerWidget {
|
||||
final isWide = isWideScreen(context);
|
||||
|
||||
if (isWide) {
|
||||
return Row(
|
||||
children: [
|
||||
Flexible(flex: 2, child: ChatListScreen(isAside: true)),
|
||||
VerticalDivider(width: 1),
|
||||
Flexible(flex: 4, child: AutoRouter()),
|
||||
],
|
||||
return AppBackground(
|
||||
isRoot: true,
|
||||
child: Row(
|
||||
children: [
|
||||
Flexible(flex: 2, child: ChatListScreen(isAside: true)),
|
||||
VerticalDivider(width: 1),
|
||||
Flexible(flex: 4, child: AutoRouter()),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return AutoRouter();
|
||||
return AppBackground(isRoot: true, child: AutoRouter());
|
||||
}
|
||||
}
|
||||
|
||||
@ -204,11 +210,22 @@ class ChatListScreen extends HookConsumerWidget {
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final isWide = isWideScreen(context);
|
||||
if (isWide && !isAside) {
|
||||
return Container(color: Theme.of(context).scaffoldBackgroundColor);
|
||||
return const EmptyPageHolder();
|
||||
}
|
||||
|
||||
final chats = ref.watch(chatroomsJoinedProvider);
|
||||
final chatInvites = ref.watch(chatroomInvitesProvider);
|
||||
final tabController = useTabController(initialLength: 3);
|
||||
final selectedTab = useState(
|
||||
0,
|
||||
); // 0 for All, 1 for Direct Messages, 2 for Group Chats
|
||||
|
||||
useEffect(() {
|
||||
tabController.addListener(() {
|
||||
selectedTab.value = tabController.index;
|
||||
});
|
||||
return null;
|
||||
}, [tabController]);
|
||||
|
||||
Future<void> createDirectMessage() async {
|
||||
final result = await showModalBottomSheet(
|
||||
@ -228,6 +245,14 @@ class ChatListScreen extends HookConsumerWidget {
|
||||
return AppScaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('chat').tr(),
|
||||
bottom: TabBar(
|
||||
controller: tabController,
|
||||
tabs: [
|
||||
Tab(text: 'chatTabAll'.tr()),
|
||||
Tab(text: 'chatTabDirect'.tr()),
|
||||
Tab(text: 'chatTabGroup'.tr()),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: Badge(
|
||||
@ -301,9 +326,26 @@ class ChatListScreen extends HookConsumerWidget {
|
||||
}),
|
||||
child: ListView.builder(
|
||||
padding: EdgeInsets.zero,
|
||||
itemCount: items.length,
|
||||
itemCount:
|
||||
items
|
||||
.where(
|
||||
(item) =>
|
||||
selectedTab.value == 0 ||
|
||||
(selectedTab.value == 1 && item.type == 1) ||
|
||||
(selectedTab.value == 2 && item.type != 1),
|
||||
)
|
||||
.length,
|
||||
itemBuilder: (context, index) {
|
||||
final item = items[index];
|
||||
final filteredItems =
|
||||
items
|
||||
.where(
|
||||
(item) =>
|
||||
selectedTab.value == 0 ||
|
||||
(selectedTab.value == 1 && item.type == 1) ||
|
||||
(selectedTab.value == 2 && item.type != 1),
|
||||
)
|
||||
.toList();
|
||||
final item = filteredItems[index];
|
||||
return ChatRoomListTile(
|
||||
room: item,
|
||||
isDirect: item.type == 1,
|
||||
|
@ -25,6 +25,7 @@ import 'package:island/widgets/content/cloud_files.dart';
|
||||
import 'package:island/widgets/response.dart';
|
||||
import 'package:material_symbols_icons/material_symbols_icons.dart';
|
||||
import 'package:styled_widget/styled_widget.dart';
|
||||
import 'package:super_sliver_list/super_sliver_list.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
import 'package:material_symbols_icons/symbols.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
@ -321,12 +322,16 @@ class ChatRoomScreen extends HookConsumerWidget {
|
||||
);
|
||||
}
|
||||
|
||||
var isLoading = false;
|
||||
|
||||
// Add scroll listener for pagination
|
||||
useEffect(() {
|
||||
void onScroll() {
|
||||
if (scrollController.position.pixels >=
|
||||
scrollController.position.maxScrollExtent - 200) {
|
||||
messagesNotifier.loadMore();
|
||||
if (isLoading) return;
|
||||
isLoading = true;
|
||||
messagesNotifier.loadMore().then((_) => isLoading = false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -338,6 +343,7 @@ class ChatRoomScreen extends HookConsumerWidget {
|
||||
useEffect(() {
|
||||
void onMessage(WebSocketPacket pkt) {
|
||||
if (!pkt.type.startsWith('messages')) return;
|
||||
if (['messages.read'].contains(pkt.type)) return;
|
||||
final message = SnChatMessage.fromJson(pkt.data!);
|
||||
if (message.chatRoomId != chatRoom.value?.id) return;
|
||||
switch (pkt.type) {
|
||||
@ -384,19 +390,21 @@ class ChatRoomScreen extends HookConsumerWidget {
|
||||
void sendMessage() {
|
||||
if (messageController.text.trim().isNotEmpty ||
|
||||
attachments.value.isNotEmpty) {
|
||||
messagesNotifier.sendMessage(
|
||||
messageController.text.trim(),
|
||||
attachments.value,
|
||||
editingTo: messageEditingTo.value,
|
||||
forwardingTo: messageForwardingTo.value,
|
||||
replyingTo: messageReplyingTo.value,
|
||||
onProgress: (messageId, progress) {
|
||||
attachmentProgress.value = {
|
||||
...attachmentProgress.value,
|
||||
messageId: progress,
|
||||
};
|
||||
},
|
||||
);
|
||||
messagesNotifier
|
||||
.sendMessage(
|
||||
messageController.text.trim(),
|
||||
attachments.value,
|
||||
editingTo: messageEditingTo.value,
|
||||
forwardingTo: messageForwardingTo.value,
|
||||
replyingTo: messageReplyingTo.value,
|
||||
onProgress: (messageId, progress) {
|
||||
attachmentProgress.value = {
|
||||
...attachmentProgress.value,
|
||||
messageId: progress,
|
||||
};
|
||||
},
|
||||
)
|
||||
.then((_) => sendReadReceipt());
|
||||
messageController.clear();
|
||||
messageEditingTo.value = null;
|
||||
messageReplyingTo.value = null;
|
||||
@ -407,7 +415,7 @@ class ChatRoomScreen extends HookConsumerWidget {
|
||||
|
||||
final compactHeader = isWideScreen(context);
|
||||
|
||||
return Scaffold(
|
||||
return AppScaffold(
|
||||
appBar: AppBar(
|
||||
leading: !compactHeader ? const Center(child: PageBackButton()) : null,
|
||||
automaticallyImplyLeading: false,
|
||||
@ -526,7 +534,7 @@ class ChatRoomScreen extends HookConsumerWidget {
|
||||
(messageList) =>
|
||||
messageList.isEmpty
|
||||
? Center(child: Text('No messages yet'.tr()))
|
||||
: ListView.builder(
|
||||
: SuperListView.builder(
|
||||
padding: EdgeInsets.symmetric(vertical: 16),
|
||||
controller: scrollController,
|
||||
reverse: true, // Show newest messages at the bottom
|
||||
@ -539,7 +547,12 @@ class ChatRoomScreen extends HookConsumerWidget {
|
||||
: null;
|
||||
final isLastInGroup =
|
||||
nextMessage == null ||
|
||||
nextMessage.senderId != message.senderId;
|
||||
nextMessage.senderId != message.senderId ||
|
||||
nextMessage.createdAt
|
||||
.difference(message.createdAt)
|
||||
.inMinutes
|
||||
.abs() >
|
||||
3;
|
||||
|
||||
return chatIdentity.when(
|
||||
skipError: true,
|
||||
|
@ -8,6 +8,7 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:island/models/user.dart';
|
||||
import 'package:island/pods/network.dart';
|
||||
import 'package:island/widgets/alert.dart';
|
||||
import 'package:island/widgets/app_scaffold.dart';
|
||||
import 'package:island/widgets/content/markdown.dart';
|
||||
import 'package:relative_time/relative_time.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
@ -85,7 +86,7 @@ class NotificationScreen extends HookConsumerWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
return Scaffold(
|
||||
return AppScaffold(
|
||||
appBar: AppBar(title: const Text('notifications').tr()),
|
||||
body: PagingHelperView(
|
||||
provider: notificationListNotifierProvider,
|
||||
|
@ -165,8 +165,9 @@ class _RealmActionMenu extends HookConsumerWidget {
|
||||
final client = ref.watch(apiClientProvider);
|
||||
client.delete('/realms/$realmSlug');
|
||||
ref.invalidate(realmsJoinedProvider);
|
||||
if (context.mounted)
|
||||
if (context.mounted) {
|
||||
context.router.maybePop(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
@ -40,6 +40,7 @@ class RealmListScreen extends HookConsumerWidget {
|
||||
final realmInvites = ref.watch(realmInvitesProvider);
|
||||
|
||||
return AppScaffold(
|
||||
noBackground: false,
|
||||
appBar: AppBar(
|
||||
title: const Text('realms').tr(),
|
||||
actions: [
|
||||
|
@ -37,6 +37,7 @@ class SettingsScreen extends HookConsumerWidget {
|
||||
}, []);
|
||||
|
||||
return AppScaffold(
|
||||
noBackground: false,
|
||||
appBar: AppBar(title: const Text('Settings')),
|
||||
body: SingleChildScrollView(
|
||||
child: Column(
|
||||
|
Reference in New Issue
Block a user