You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
907 B
35 lines
907 B
import 'package:mobx/mobx.dart';
|
|
import 'package:thesis_shop/models/product.dart';
|
|
import 'package:thesis_shop/service/product_service.dart';
|
|
import 'package:thesis_shop/stores/user_store.dart';
|
|
|
|
part 'product_store.g.dart';
|
|
|
|
class ProductStore = _ProductStore with _$ProductStore;
|
|
|
|
abstract class _ProductStore with Store {
|
|
final ProductService _service;
|
|
final UserStore _userStore;
|
|
_ProductStore(this._service, this._userStore) : super() {
|
|
loadProducts();
|
|
}
|
|
|
|
ObservableFuture<List<Product>> _products = ObservableFuture.value([]);
|
|
|
|
@computed
|
|
ObservableFuture<List<Product>> get products {
|
|
if (!_userStore.isSignedIn) {
|
|
return _products;
|
|
}
|
|
|
|
return _products.then(
|
|
(products) =>
|
|
products.map((product) => product.copyWithDiscount()).toList(),
|
|
);
|
|
}
|
|
|
|
@action
|
|
void loadProducts() {
|
|
_products = ObservableFuture(_service.fetchProducts());
|
|
}
|
|
}
|
|
|