Skip to content

Commit

Permalink
added i18n for module: home.
Browse files Browse the repository at this point in the history
  • Loading branch information
yokawaiik committed Jul 16, 2022
1 parent afd2c2e commit 8793162
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 63 deletions.
17 changes: 11 additions & 6 deletions wish_app/lib/src/modules/home/api_services/home_api_service.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:get/get.dart';
import 'package:supabase_flutter/supabase_flutter.dart';

import '../../global/models/supabase_exception.dart';
import '../../global/models/unknown_exception.dart';
import '../../global/models/wish.dart';

class HomeService {
Expand Down Expand Up @@ -30,7 +29,9 @@ class HomeService {
.execute();

if (selectedQuery.hasError) {
throw SupabaseException("Supabase Error", selectedQuery.error!.message);
// throw SupabaseException("Supabase Error", selectedQuery.error!.message);
throw SupabaseException(
"error_db_unknown_title".tr, selectedQuery.error!.message);
}

final lastWishList = (selectedQuery.data as List<dynamic>)
Expand All @@ -44,7 +45,8 @@ class HomeService {
rethrow;
} catch (e) {
print("HomeService - loadWishList - SupabaseException - $e");
throw UnknownException("Unknown error");
// throw UnknownException("Unknown error");
rethrow;
}
}

Expand All @@ -66,7 +68,9 @@ class HomeService {
.execute();

if (countWish.hasError) {
throw SupabaseException("Supabase Error", countWish.error!.message);
// throw SupabaseException("Supabase Error", countWish.error!.message);
throw SupabaseException(
"error_db_unknown_title".tr, countWish.error!.message);
}

print(countWish.data);
Expand All @@ -76,7 +80,8 @@ class HomeService {
rethrow;
} catch (e) {
print("HomeService - loadCountOfWishInSubscriptions - $e");
throw UnknownException("Unknown error");
// throw UnknownException("Unknown error");
rethrow;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:get/get.dart';

import '../controllers/home_controller.dart';
import '../controllers/home_main_controller.dart';

class HomeMainBindings extends Bindings {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class HomeController extends GetxController {
Expand Down
59 changes: 26 additions & 33 deletions wish_app/lib/src/modules/home/controllers/home_main_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@ import '../../wish/views/wish_info_view.dart';
import '../constants/router_constants.dart' as router_constants;

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

late final ScrollController scrollController;

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

@override
void onInit() {
Expand All @@ -32,34 +30,22 @@ class HomeMainController extends GetxController {
refreshWishList();
}

// @override
// void onReady() {
// super.onReady();
// refreshWishList();
// }

RxBool isLoading = RxBool(false);
RxBool isDeleting = RxBool(false);

int countWish = 0;
int limit = 10;
// int limit = 2;
RxList<Wish> homeWishList = RxList();
int get countLoadedWish => homeWishList.length;

void _scrollListener() {
if (countLoadedWish == countWish) return;

// var position = scrollController.offset;
var position = scrollController.positions.last.pixels;
var maxScrollExtent = scrollController.positions.last.maxScrollExtent;
var outOfRange = scrollController.positions.last.outOfRange;

if (position >= maxScrollExtent &&
// if (scrollController.offset >= scrollController.position.maxScrollExtent &&
!outOfRange) {
// print("comes to bottom $isLoading");
// print("RUNNING LOAD MORE");
if (position >= maxScrollExtent && !outOfRange) {
loadWishList(countLoadedWish);
}
}
Expand All @@ -78,12 +64,12 @@ class HomeMainController extends GetxController {

Future<void> loadCountOfWishInSubscriptions() async {
try {
print("loadCountOfWishInSubscriptions");
// print("loadCountOfWishInSubscriptions");
final loadedCountOfWish = await HomeService.countOfWishInSubscriptions(
currentUserId: _userService.currentUser?.id,
currentUserId: _us.currentUser?.id,
);

print(loadedCountOfWish);
// print(loadedCountOfWish);

if (loadedCountOfWish == null) return;

Expand All @@ -96,7 +82,7 @@ class HomeMainController extends GetxController {

Future<void> loadWishList([int offset = 0, bool isRefresh = false]) async {
try {
print(offset);
// print(offset);

isLoading.value = true;
List<Wish>? loadedWishList;
Expand All @@ -105,7 +91,7 @@ class HomeMainController extends GetxController {
loadedWishList = await HomeService.loadWishList(
limit: limit,
offset: countLoadedWish,
currentUserId: _userService.currentUser!.id,
currentUserId: _us.currentUser!.id,
);
} else {
// for guest
Expand All @@ -124,8 +110,11 @@ class HomeMainController extends GetxController {
homeWishList.addAll(loadedWishList);
homeWishList.refresh();
} catch (e) {
Get.snackbar(
"Error loading a last wish list", "Something happened to server.");
// Get.snackbar(
// "Error loading a last wish list",
// "Something happened to server.",
// );
Get.snackbar("error_title".tr, "Error loading a last wish list".tr);
} finally {
isLoading.value = false;
}
Expand All @@ -149,7 +138,6 @@ class HomeMainController extends GetxController {

await Get.toNamed(
WishInfoView.routeName,
// arguments: {"id": id, "routeName": HomeView.routeName},
arguments: WishInfoArguments(
wishId: id,
previousRouteName: router_constants.homeMainRouteName,
Expand All @@ -164,15 +152,15 @@ class HomeMainController extends GetxController {
try {
final foundWish = homeWishList.firstWhere((wish) => wish.id == id);

await FavoritesApiService.toggleFavorite(
id, _userService.currentUser!.id);
await FavoritesApiService.toggleFavorite(id, _us.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.");
// Get.snackbar("Unexpected error", "Something went wrong.");
Get.snackbar("error_title".tr, "error_m_something_went_wrong".tr);
}
}

Expand All @@ -183,14 +171,19 @@ class HomeMainController extends GetxController {

void actionDeleteWish(Wish wish) async {
try {
Get.back(closeOverlays: true); // close modalBottomSheet
Get.back(closeOverlays: true); // ? info: close modalBottomSheet
isDeleting.value = true;
await AddWishApiService.deleteWish(wish.id, wish.imagePath);
deleteWish(wish.id);
} catch (e) {
print(e);
// Get.snackbar(
// "Error loading a last wish list",
// "Something happened to server.",
// );
Get.snackbar(
"Error loading a last wish list", "Something happened to server.");
"error_title".tr,
"error_m_something_went_wrong".tr,
);
} finally {
isDeleting.value = false;
}
Expand All @@ -207,7 +200,7 @@ class HomeMainController extends GetxController {
wish.createdBy.id,
),
preventDuplicates: false,
id: _homeController.nestedKey,
id: _hc.nestedKey,
);
}
}
Expand Down
30 changes: 15 additions & 15 deletions wish_app/lib/src/modules/home/views/home_main_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class HomeMainView extends GetView<HomeMainController> {
children: [
IconButton(
onPressed: () => Get.back(closeOverlays: true),
icon: Icon(
icon: const Icon(
Icons.close,
size: 36,
),
Expand All @@ -42,27 +42,27 @@ class HomeMainView extends GetView<HomeMainController> {
children: [
if (!wish.createdBy.isCurrentUser)
ListTile(
leading: Icon(
leading: const Icon(
Icons.favorite,
color: theme_wish_app.favoriteColor,
),
title: Text("Add to favorites"),
title: Text("fm_hmv_bs_lv_add_to_favorites".tr),
onTap: () => controller.addToFavorites(wish.id),
),
ListTile(
leading: Icon(Icons.send),
title: Text("Share"),
onTap: controller.shareWish,
),
// ListTile(
// leading: const Icon(Icons.send),
// title: const Text("Share"),
// onTap: controller.shareWish,
// ),
if (wish.createdBy.isCurrentUser)
ListTile(
leading: Icon(Icons.delete),
title: Text("Delete"),
leading: const Icon(Icons.delete),
title: Text("fm_hmv_bs_lv_delete".tr),
onTap: () => controller.actionDeleteWish(wish),
),
ListTile(
leading: Icon(Icons.person),
title: Text("See profile"),
leading: const Icon(Icons.person),
title: Text("fm_hmv_bs_lv_see_profile".tr),
onTap: () => controller.seeProfile(wish),
),
],
Expand All @@ -80,7 +80,7 @@ class HomeMainView extends GetView<HomeMainController> {
onWillPop: Get.find<HomeController>().onWillPop,
child: Scaffold(
appBar: AppBar(
title: Text("Home"),
title: Text("fm_hmv_appbar_title".tr),
),
body: RefreshIndicator(
onRefresh: () async {
Expand All @@ -99,7 +99,7 @@ class HomeMainView extends GetView<HomeMainController> {
),
),
if (controller.isDeleting.value) ...[
Container(
SizedBox(
width: double.infinity,
height: double.infinity,
child: BackdropFilter(
Expand Down Expand Up @@ -144,7 +144,7 @@ class HomeMainView extends GetView<HomeMainController> {
// todo, optional: implement grid to desktop

return MasonryGridView.builder(
padding: EdgeInsets.all(global_constants.paddingInsideGridView),
padding: const EdgeInsets.all(global_constants.paddingInsideGridView),
gridDelegate: const SliverSimpleGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
),
Expand Down
4 changes: 2 additions & 2 deletions wish_app/lib/src/modules/home/views/home_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class HomeView extends GetView<HomeController> {
onGenerateRoute: (RouteSettings settings) {
switch (settings.name) {
case router_constants.homeAccountRouteName:
var args = settings.arguments as AccountArguments;
final args = settings.arguments as AccountArguments;

return GetPageRoute(
routeName: router_constants.homeAccountRouteName,
Expand All @@ -39,7 +39,7 @@ class HomeView extends GetView<HomeController> {
return GetPageRoute(
routeName: router_constants.homeMainRouteName,
settings: settings,
page: () => HomeMainView(),
page: () => const HomeMainView(),
binding: HomeMainBindings(),
);
}
Expand Down
6 changes: 3 additions & 3 deletions wish_app/lib/src/modules/splash/views/splash_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ class SplashView extends GetView<SplashBindings> {
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("Hi, wait a second..."),
SizedBox(
Text("s_sv_text_on_screen".tr),
const SizedBox(
height: 20,
),
CircularProgressIndicator(),
const CircularProgressIndicator(),
],
),
),
Expand Down
4 changes: 2 additions & 2 deletions wish_app/lib/src/modules/translations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
- [x] Auth;
- [x] Favorites;
- [ ] Global;
- [ ] Home;
- [x] Home;
- [ ] Navigator;
- [ ] Splash.
- [x] Splash.

0 comments on commit 8793162

Please sign in to comment.