Commit 974eb518 authored by Matija Obreza's avatar Matija Obreza
Browse files

Fix: Select-all and add-to-cart bugfix

- `canAddToCart(acc) && acc.uuid` evaluated to `false`, now filtered out
- Reset selected items after data is loaded
parent defb843a
......@@ -96,6 +96,9 @@ class AccessionListPage extends React.Component<IAccessionListPageProps & WithTr
})
.catch((e) => {
console.log('Api call failed: ', e);
})
.finally(() => {
this.setState({ isAllSelected: false, selected: [] });
});
};
......@@ -157,7 +160,7 @@ class AccessionListPage extends React.Component<IAccessionListPageProps & WithTr
private onToggleAll = () => {
this.setState((prevState) => ({
isAllSelected: !prevState.isAllSelected,
selected: !prevState.isAllSelected ? prevState.accessions.content.map((acc) => canAddToCart(acc) && acc.uuid) : [],
selected: !prevState.isAllSelected ? prevState.accessions.content.map((acc) => canAddToCart(acc) ? acc.uuid : null).filter((uuid) => uuid && uuid) : [],
}));
};
......
......@@ -72,6 +72,8 @@ class CartPage extends React.Component<ICartPageProps, ICartPageState> {
})
.catch((e) => {
console.log('Api call failed: ', e);
LocalStorageCart.clearCart();
this.setState({ accessions: null, isEmpty: true });
});
};
......
......@@ -42,7 +42,7 @@ export class LocalStorageCart {
};
public static addToCart = (what: string | string[]) => {
// console.log('add to cart: ', what);
console.log(`add to cart: ${typeof what}`, what);
const cartUuids = LocalStorageCart.getCartItemsLS();
if (cartUuids.length === 0) {
return localStorage.setItem(LocalStorageCart.LS_KEY, JSON.stringify(Array.isArray(what) ? what : [what]));
......@@ -76,6 +76,10 @@ export class LocalStorageCart {
}
localStorage.setItem(LocalStorageCart.LS_KEY, JSON.stringify(updatedCartItems));
}
public static clearCart = () => {
localStorage.removeItem(LocalStorageCart.LS_KEY);
}
}
export const canAddToCart = (accession: Accession) => {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment