Skip to content

Commit

Permalink
Small changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
yokawaiik committed Jul 9, 2022
1 parent 8cff1f3 commit 0182774
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
1 change: 0 additions & 1 deletion wish_app/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:get/get.dart';
import 'package:wish_app/src/bindings/global_bindings.dart';
import 'package:wish_app/src/modules/connection_manager/services/connection_manager_service.dart';
import 'package:wish_app/src/utils/environment.dart' as environment;
import 'package:wish_app/src/wish_app.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:supabase_flutter/supabase_flutter.dart';
import 'package:wish_app/src/models/supabase_exception.dart';
import 'package:wish_app/src/models/wish.dart';
import 'package:wish_app/src/modules/account/controllers/account_controller.dart';
import 'package:wish_app/src/modules/account/models/account_arguments.dart';
import 'package:wish_app/src/modules/account/views/account_view.dart';
import 'package:wish_app/src/modules/favorites/api_services/favorites_api_service.dart';
import 'package:wish_app/src/modules/home/api_services/home_api_service.dart';
import 'package:wish_app/src/modules/home/controllers/home_controller.dart';
import 'package:wish_app/src/api_services/add_wish_api_service.dart';
Expand All @@ -18,12 +20,12 @@ import '../constants/router_constants.dart' as router_constants;

class HomeMainController extends GetxController {
final _supabase = Supabase.instance;
final userService = Get.find<UserService>();
final _userService = Get.find<UserService>();
final _homeController = Get.find<HomeController>();

late final ScrollController scrollController;

RxBool get isUserAuthenticated => userService.isUserAuthenticated;
RxBool get isUserAuthenticated => _userService.isUserAuthenticated;
// bool get isUserAuthenticated2 => userService.isUserAuthenticated.value;

@override
Expand Down Expand Up @@ -81,7 +83,7 @@ class HomeMainController extends GetxController {
try {
print("loadCountOfWishInSubscriptions");
final loadedCountOfWish = await HomeService.countOfWishInSubscriptions(
currentUserId: userService.currentUser?.id,
currentUserId: _userService.currentUser?.id,
);

print(loadedCountOfWish);
Expand All @@ -106,7 +108,7 @@ class HomeMainController extends GetxController {
loadedWishList = await HomeService.loadWishList(
limit: limit,
offset: countLoadedWish,
currentUserId: userService.currentUser!.id,
currentUserId: _userService.currentUser!.id,
);
} else {
// for guest
Expand Down Expand Up @@ -161,12 +163,20 @@ class HomeMainController extends GetxController {
//todo: shareWish
void shareWish() {}

//todo: addToFavorites - add getting touch with api
void addToFavorites(int id) async {
final foundWish = homeWishList.firstWhere((wish) => wish.id == id);
try {
final foundWish = homeWishList.firstWhere((wish) => wish.id == id);

foundWish.isFavorite = !foundWish.isFavorite;
homeWishList.refresh();
await FavoritesApiService.toggleFavorite(
id, _userService.currentUser!.id);

foundWish.isFavorite = !foundWish.isFavorite;
homeWishList.refresh();
} on SupabaseException catch (e) {
Get.snackbar(e.title, e.msg);
} catch (e) {
Get.snackbar("Unexpected error", "Something went wrong.");
}
}

void deleteWish(int id) {
Expand Down
3 changes: 2 additions & 1 deletion wish_app/lib/src/modules/home/views/home_main_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ class HomeMainView extends GetView<HomeMainController> {
),
floatingActionButton: Obx(
() {
return controller.userService.isUserAuthenticated.value
// return controller.userService.isUserAuthenticated.value
return controller.isUserAuthenticated.value
? FloatingActionButton(
child: Icon(
Icons.add,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ class WishInfoController extends GetxController with StateMixin<Wish> {

case router_constants.homeAccountRouteName:
case FavoritesView.routeName:
// todo: request to service if user came by link
final theFoundWish = await AddWishApiService.getWish(
_args.wishId,
_us.currentUser!.id,
Expand Down

0 comments on commit 0182774

Please sign in to comment.