Skip to content

Commit

Permalink
fix: Remove shopping list item locally
Browse files Browse the repository at this point in the history
  • Loading branch information
TomBursch committed Oct 21, 2024
1 parent 8ee107d commit 16110f9
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 12 deletions.
9 changes: 1 addition & 8 deletions kitchenowl/lib/cubits/shoppinglist_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ class ShoppinglistCubit extends Cubit<ShoppinglistCubitState> {
final Household household;
Future<void>? _refreshThread;
String? _refreshCurrentQuery;
int Function() recentItemCountProvider;

String get query => (state is SearchShoppinglistCubitState)
? (state as SearchShoppinglistCubitState).query
: "";

ShoppinglistCubit(this.household, this.recentItemCountProvider)
ShoppinglistCubit(this.household)
: super(const LoadingShoppinglistCubitState()) {
PreferenceStorage.getInstance().readInt(key: 'itemSorting').then((i) {
if (i != null && state.sorting.index != i) {
Expand Down Expand Up @@ -155,9 +154,6 @@ class ShoppinglistCubit extends Cubit<ShoppinglistCubitState> {
final recent = List.of(shoppinglist.recentItems);
recent.removeWhere((e) => e.name == item.name);
recent.insert(0, ItemWithDescription.fromItem(item: item));
if (recent.length > recentItemCountProvider()) {
recent.removeLast();
}
if (_state is SearchShoppinglistCubitState) {
final result = List.of(_state.result);
final index = result.indexOf(item);
Expand Down Expand Up @@ -208,9 +204,6 @@ class ShoppinglistCubit extends Cubit<ShoppinglistCubitState> {
0,
selectedItems.map((e) => ItemWithDescription.fromItem(item: e)),
);
if (recent.length > recentItemCountProvider()) {
recent.removeRange(recentItemCountProvider(), recent.length);
}

if (_state is SearchShoppinglistCubitState) {
final result = List.of(_state.result);
Expand Down
5 changes: 1 addition & 4 deletions kitchenowl/lib/pages/household_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ class _HouseholdPageState extends State<HouseholdPage> {
void initState() {
super.initState();
householdCubit = HouseholdCubit(widget.household);
shoppingListCubit = ShoppinglistCubit(
widget.household,
() => App.settings.recentItemsCount,
);
shoppingListCubit = ShoppinglistCubit(widget.household);
recipeListCubit = RecipeListCubit(widget.household);
plannerCubit = PlannerCubit(widget.household);
expenseListCubit = ExpenseListCubit(widget.household);
Expand Down

0 comments on commit 16110f9

Please sign in to comment.