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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user