fix: action button on Reader now toggles auto-scroll (not food assistant)
All checks were successful
Security Checks / dependency-audit (push) Successful in 13s
Security Checks / secret-scanning (push) Successful in 4s
Security Checks / dockerfile-lint (push) Successful in 4s

Bug: when action tab (value=3) was tapped, selectedTab was already 3
by the time handleActionTap ran. The check 'if selectedTab == 2'
always failed, falling through to food assistant.

Fix: use onChange(of: selectedTab) oldValue to capture which tab the
user was on BEFORE tapping the action button. Pass that to
handleActionTap(from:). If from Reader (2), toggle auto-scroll.
If from Home/Fitness, open food assistant.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Yusuf Suleman
2026-04-04 08:00:43 -05:00
parent e2fc87b6aa
commit 395cca08dd

View File

@@ -30,6 +30,7 @@ struct MainTabView: View {
@State private var readerVM = ReaderViewModel() @State private var readerVM = ReaderViewModel()
@State private var isAutoScrolling = false @State private var isAutoScrolling = false
@State private var scrollSpeed: Double = 1.0 @State private var scrollSpeed: Double = 1.0
@State private var previousTab = 0
private var showReader: Bool { private var showReader: Bool {
auth.currentUser?.id != 4 auth.currentUser?.id != 4
@@ -64,11 +65,7 @@ struct MainTabView: View {
// Home/Fitness: quick add food (+) // Home/Fitness: quick add food (+)
// Reader: play/pause auto-scroll // Reader: play/pause auto-scroll
Tab(value: 3, role: .search) { Tab(value: 3, role: .search) {
// This view shows briefly when tapped immediately redirect
Color.clear Color.clear
.onAppear {
handleActionTap()
}
} label: { } label: {
Label("Action", systemImage: actionIcon) Label("Action", systemImage: actionIcon)
} }
@@ -146,23 +143,28 @@ struct MainTabView: View {
renderer.attachToWindow() renderer.attachToWindow()
await readerVM.loadInitial() await readerVM.loadInitial()
} }
.onChange(of: selectedTab) { _, newTab in .onChange(of: selectedTab) { oldTab, newTab in
if newTab == 3 {
// Action tab tapped handle based on previous tab
handleActionTap(from: oldTab)
} else {
previousTab = newTab
if newTab != 2 { isAutoScrolling = false } if newTab != 2 { isAutoScrolling = false }
} }
} }
}
private func handleActionTap() { private func handleActionTap(from sourceTab: Int) {
if selectedTab == 2 { if sourceTab == 2 {
// Reader: toggle auto-scroll, stay on Reader // Reader: toggle auto-scroll, return to Reader
withAnimation(.spring(duration: 0.3)) { withAnimation(.spring(duration: 0.3)) {
isAutoScrolling.toggle() isAutoScrolling.toggle()
} }
selectedTab = 2 // stay on Reader (don't switch to the "action" tab) selectedTab = 2
} else { } else {
// Home/Fitness: open food assistant, return to previous tab // Home/Fitness: open food assistant, return to previous tab
let returnTab = selectedTab
showAssistant = true showAssistant = true
selectedTab = returnTab selectedTab = sourceTab
} }
} }