Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions app/lib/pages/memories/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -164,30 +164,27 @@ class MemoriesPageState extends State<MemoriesPage> with AutomaticKeepAliveClien
(() async {
final provider = context.read<MemoriesProvider>();
await provider.init();
if (!mounted) return;

// Apply the date-based default filter
_applyFilter(_currentFilter);

// Mark initial load as complete
if (mounted) {
setState(() {
_isInitialLoad = false;
});
}
setState(() {
_isInitialLoad = false;
});
Comment on lines 169 to +174
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

There are two separate setState calls here, one inside _applyFilter and another one here to set _isInitialLoad. This is inefficient as it causes two rebuilds. After applying the suggested change to _applyFilter to accept a callback, you can combine these into a single state update.

      _applyFilter(_currentFilter, andThen: () {
        _isInitialLoad = false;
      });


if (!mounted) return;
final unreviewedMemories = provider.unreviewed;
final unreviewed = provider.unreviewed;
final home = context.read<HomeProvider>();
if (unreviewedMemories.isNotEmpty && home.selectedIndex == 2) {
_showReviewSheet(context, unreviewedMemories, provider);

if (unreviewed.isNotEmpty && home.selectedIndex == 2) {
_showReviewSheet(context, unreviewed, provider);
}
}).withPostFrameCallback();
}

void _applyFilter(FilterOption option) {
setState(() {
_currentFilter = option;

switch (option) {
case FilterOption.interesting:
_filterByCategory(MemoryCategory.interesting);
Expand All @@ -202,7 +199,7 @@ class MemoriesPageState extends State<MemoriesPage> with AutomaticKeepAliveClien
MixpanelManager().memoriesFiltered('manual');
break;
case FilterOption.all:
_filterByCategory(null); // null means no category filter
_filterByCategory(null);
MixpanelManager().memoriesFiltered('all');
break;
}
Expand All @@ -211,11 +208,9 @@ class MemoriesPageState extends State<MemoriesPage> with AutomaticKeepAliveClien

void _filterByCategory(MemoryCategory? category) {
if (!mounted) return;

setState(() {
_selectedCategory = category;
});

final provider = context.read<MemoriesProvider>();
provider.setCategoryFilter(category);
}
Expand Down