Add 30-second debounce to tab refresh in HomeShell

Co-authored-by: derkauzigekoala <79001016+derkauzigekoala@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-02-24 19:19:49 +00:00
parent 44951de8f5
commit b9e298851b

View file

@ -15,6 +15,8 @@ class _HomeShellState extends State<HomeShell> {
int _currentIndex = 0;
final _collectionsKey = GlobalKey<CollectionsScreenState>();
final _scanKey = GlobalKey<ScanTabState>();
final Map<int, DateTime> _lastRefreshed = {};
static const _refreshDebounce = Duration(seconds: 30);
late final List<Widget> _pages = <Widget>[
CollectionsScreen(key: _collectionsKey),
@ -24,10 +26,13 @@ class _HomeShellState extends State<HomeShell> {
void _onTabSelected(int i) {
setState(() => _currentIndex = i);
final now = DateTime.now();
final last = _lastRefreshed[i];
if (last != null && now.difference(last) < _refreshDebounce) return;
_lastRefreshed[i] = now;
if (i == 0) {
_collectionsKey.currentState?.refresh();
}
if (i == 1) {
} else if (i == 1) {
_scanKey.currentState?.refresh();
}
}