fix(ui): address PR #30 review findings

- ViewportInfo.updateShouldNotify: compare layoutClass only
  (not width/height), avoiding unnecessary rebuilds on every
  resize frame within the same layout class.
- ChatPanel: use BorderDirectional(start:) for RTL support.
- ChatPanel: localize 'Close chat' tooltip via AppL10n.chatCloseAction.
- Inline panel snackbar: localize via AppL10n.chatPanelCollapsedHint.
  New en/zh ARB entries added.
- _saveCurrentDraft(): removed — it was a self-assignment no-op.
  Draft persistence relies on ChatDetailView's didUpdateWidget
  (fires onDraftChanged on target switch) and dispose (fires on
  panel tear-down), both of which already populate _chatDrafts
  correctly without an explicit save call.
- _handleInlineChatViewport layout snackbar: use AppL10n.
- Audio level-meter: switch from callback-count (% 3) to time-based
  gating (std::time::Duration::from_millis(33)), robust to cpal
  buffer-size or sample-rate changes. Remove level_decimation_counter.
- chat_panel_test.dart: add AppL10n.localizationsDelegates so the
  test resolves l10n keys.

Tests: 183 passed, 2 skipped. Dart analyze clean.
cargo test -p chanora_audio --lib: 125 passed.
This commit is contained in:
Edison Jwa
2026-06-07 23:30:00 +09:00
parent e9cd832828
commit dad633e381
10 changed files with 83 additions and 42 deletions
@@ -57,8 +57,11 @@ class ViewportInfo extends InheritedWidget {
bool get isWide => !isCompact;
@override
bool updateShouldNotify(ViewportInfo old) =>
layoutClass != old.layoutClass ||
width != old.width ||
height != old.height;
bool updateShouldNotify(ViewportInfo old) => layoutClass != old.layoutClass;
// NOTE: width/height changes within the same layout class do NOT trigger
// notification. Dependents who genuinely need pixel-level dimensions
// (rare — most layouts should switch on layoutClass) must use a local
// LayoutBuilder. Notifying on every pixel would rebuild every dependent
// on every resize frame, which is the exact pessimisation this
// InheritedWidget exists to avoid.
}
+1
View File
@@ -46,6 +46,7 @@
"retryAction": "Retry",
"chatAction": "Chat",
"chatCloseAction": "Close chat",
"chatPanelCollapsedHint": "Tap the chat button to continue your conversation",
"chatNewPrivateAction": "New private chat",
"chatSearchClientsHint": "Search clients...",
"chatDirectMessageAction": "Private message",
+1
View File
@@ -39,6 +39,7 @@
"retryAction": "重试",
"chatAction": "聊天",
"chatCloseAction": "关闭聊天",
"chatPanelCollapsedHint": "点击聊天按钮以继续对话",
"chatNewPrivateAction": "新建私聊",
"chatSearchClientsHint": "搜索用户...",
"chatDirectMessageAction": "私聊",
@@ -307,6 +307,12 @@ abstract class AppL10n {
/// **'Close chat'**
String get chatCloseAction;
/// No description provided for @chatPanelCollapsedHint.
///
/// In en, this message translates to:
/// **'Tap the chat button to continue your conversation'**
String get chatPanelCollapsedHint;
/// No description provided for @chatNewPrivateAction.
///
/// In en, this message translates to:
@@ -123,6 +123,10 @@ class AppL10nEn extends AppL10n {
@override
String get chatCloseAction => 'Close chat';
@override
String get chatPanelCollapsedHint =>
'Tap the chat button to continue your conversation';
@override
String get chatNewPrivateAction => 'New private chat';
@@ -120,6 +120,9 @@ class AppL10nZh extends AppL10n {
@override
String get chatCloseAction => '关闭聊天';
@override
String get chatPanelCollapsedHint => '点击聊天按钮以继续对话';
@override
String get chatNewPrivateAction => '新建私聊';
+22 -19
View File
@@ -1673,17 +1673,18 @@ class _BetaHomeState extends State<_BetaHome> with WidgetsBindingObserver {
};
}
/// Saves the current draft text for the current inline chat target.
void _saveCurrentDraft() {
// Drafts are continuously saved via onDraftChanged callback in Task 4.
// This method exists as an explicit save point.
final target = _inlineChatTarget;
if (target == null) return;
final key = _draftKeyForTarget(target);
if (_chatDrafts.containsKey(key)) {
_chatDrafts[key] = _chatDrafts[key] ?? '';
}
}
/// Returns the current draft text for the inline chat target, or null
/// if no draft has been stored.
///
/// Draft persistence relies on [ChatDetailView]'s own lifecycle:
/// `didUpdateWidget` flushes the outgoing target's draft via
/// `onDraftChanged` when the parent rebuilds with a new target, and
/// `dispose` flushes the final draft when the panel is torn down
/// (e.g. on [_closeInlineChat]). Both paths feed
/// [_chatDrafts] without requiring an explicit save call from this
/// class.
String? _currentDraftFor(rust.BridgeMessageTarget target) =>
_chatDrafts[_draftKeyForTarget(target)];
Future<void> _onOpenChat({
rust.BridgeMessageTarget? target,
@@ -1722,8 +1723,9 @@ class _BetaHomeState extends State<_BetaHome> with WidgetsBindingObserver {
layoutClassFromWidth(MediaQuery.sizeOf(context).width) ==
LayoutClass.expanded;
if (isExpanded) {
// Outgoing draft is preserved by ChatDetailView.didUpdateWidget,
// which fires onDraftChanged with the old target's text on rebuild.
setState(() {
_saveCurrentDraft();
_chatUnread = 0;
_chatOpen = true;
_inlineChatTarget = newTarget;
@@ -1754,8 +1756,10 @@ class _BetaHomeState extends State<_BetaHome> with WidgetsBindingObserver {
}
void _closeInlineChat() {
// Final draft for the dismissed target is preserved by
// ChatDetailView.dispose, which fires onDraftChanged when the panel
// is removed from the tree on the next rebuild.
setState(() {
_saveCurrentDraft();
_lastDismissedTarget = _inlineChatTarget;
_lastDismissedClientName = _inlineChatClientName;
_chatOpen = false;
@@ -1788,8 +1792,8 @@ class _BetaHomeState extends State<_BetaHome> with WidgetsBindingObserver {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted || _inlineChatTarget == null) return;
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Tap the chat button to continue your conversation'),
SnackBar(
content: Text(AppL10n.of(context).chatPanelCollapsedHint),
),
);
});
@@ -2654,10 +2658,9 @@ class _BetaHomeState extends State<_BetaHome> with WidgetsBindingObserver {
snapshot: _snapshot!,
target: inlineChatTarget,
clientName: _inlineChatClientName,
restoredDraft:
_chatDrafts[_draftKeyForTarget(
inlineChatTarget,
)],
restoredDraft: _currentDraftFor(
inlineChatTarget,
),
onDraftChanged: (text) {
final draftKey = _draftKeyForTarget(
inlineChatTarget,
@@ -3,6 +3,7 @@
import 'package:flutter/material.dart';
import '../design/breakpoints.dart';
import '../l10n/generated/app_localizations.dart';
import '../services/snapshot_state_mapper.dart';
import '../services/ts3_server_link.dart';
import '../src/rust/api.dart' as rust;
@@ -51,14 +52,15 @@ class ChatPanel extends StatelessWidget {
Widget build(BuildContext context) {
final currentChannelId = ownClientSnapshotState(snapshot)?.channelId;
final channelName = snapshotChannelName(snapshot, currentChannelId);
final l10n = AppL10n.of(context);
return SizedBox(
width: ChanoraBreakpoints.chatPanelWidth,
child: DecoratedBox(
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surface,
border: Border(
left: BorderSide(
border: BorderDirectional(
start: BorderSide(
color: Theme.of(context).colorScheme.outlineVariant,
),
),
@@ -75,7 +77,7 @@ class ChatPanel extends StatelessWidget {
onDraftChanged: onDraftChanged,
messageMaxWidth: 500,
headerTrailing: IconButton(
tooltip: 'Close chat',
tooltip: l10n.chatCloseAction,
icon: const Icon(Icons.close),
onPressed: onClose,
),
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:chanora_flutter/l10n/generated/app_localizations.dart';
import 'package:chanora_flutter/src/rust/api.dart' as rust;
import 'package:chanora_flutter/widgets/chat_panel.dart';
import 'package:chanora_flutter/widgets/chat_views.dart';
@@ -55,6 +56,8 @@ void main() {
await tester.pumpWidget(
MaterialApp(
localizationsDelegates: AppL10n.localizationsDelegates,
supportedLocales: AppL10n.supportedLocales,
home: Scaffold(
body: ChatPanel(
messages: messages,
@@ -87,6 +90,8 @@ void main() {
required String? restoredDraft,
}) {
return MaterialApp(
localizationsDelegates: AppL10n.localizationsDelegates,
supportedLocales: AppL10n.supportedLocales,
home: Scaffold(
body: ChatDetailView(
messages: messages,