Skip to content

Commit

Permalink
feat(home): add planner advert (#557)
Browse files Browse the repository at this point in the history
* feat(planner-advert): setup data layer

* feat(planner-advert): setup presentation layer

* chore(planner-advert): code cleanup

* feat(planner-advert): PR suggestions

---------

Co-authored-by: Szymon Kowaliński <szymon@kowalinski.dev>
  • Loading branch information
mikolaj-jalocha and simon-the-shark authored Jan 27, 2025
1 parent 47a68ca commit 51f75bb
Show file tree
Hide file tree
Showing 12 changed files with 1,558 additions and 1,438 deletions.
2,886 changes: 1,456 additions & 1,430 deletions lib/api_base/schema.graphql

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion lib/config/ttl_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ enum TtlKey {
buildingsRepository,
guideDetailsRepository,
guideRepository,
changelogRepository
changelogRepository,
plannerAdvertRepository
// ... add a new key here if you create a new repository
}

Expand All @@ -38,6 +39,7 @@ abstract class TtlStrategy {
day, // leaving as day for now, cause maybe some uni orgs will update it by themselves
TtlKey.guideRepository => week,
TtlKey.changelogRepository => week,
TtlKey.plannerAdvertRepository => day
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import "package:flutter/material.dart";
import "package:flutter_riverpod/flutter_riverpod.dart";

import "../../../config/ui_config.dart";
import "../../../widgets/loading_widgets/simple_previews/horizontal_rectangular_section_loading.dart";
import "../../../widgets/my_error_widget.dart";
import "../../home_view/widgets/loading_widgets/horizontal_rectangular_section_loading.dart";
import "../repository/academic_calendar_repo.dart";
import "countdown_widget/exam_session_countdown.dart";
import "home_screen_greeting.dart";
Expand Down
4 changes: 3 additions & 1 deletion lib/features/home_view/home_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "package:flutter/material.dart";
import "../../config/ui_config.dart";
import "../../theme/app_theme.dart";
import "../academic_calendar/widgets/academic_calendar_consumer.dart";
import "../planner_advert/widgets/planner_advert_widget.dart";
import "keep_alive_home_view_providers.dart";
import "widgets/buildings_section/buildings_section.dart";
import "widgets/logo_app_bar.dart";
Expand All @@ -23,6 +24,7 @@ class HomeView extends StatelessWidget {
padding: EdgeInsets.only(top: 12, bottom: 4),
child: NavActionsSection(),
),
PlannerAdvertBanner(),
const ScienceClubsSection(),
const BuildingsSection(),
].lock;
Expand All @@ -35,7 +37,7 @@ class HomeView extends StatelessWidget {
child: ListView.separated(
itemBuilder: (context, index) => sections[index],
separatorBuilder: (context, index) => SizedBox(
height: index == 1 ? 0 : HomeViewConfig.paddingMedium,
height: index == 1 || index == 2 ? 0 : HomeViewConfig.paddingMedium,
),
itemCount: sections.length,
),
Expand Down
1 change: 1 addition & 0 deletions lib/features/offline_messages/messages_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extension GqlOfflineMessageX on BuildContext {
TtlKey.guideDetailsRepository => localize.offline_guide_details,
TtlKey.guideRepository => localize.offline_guide_posts,
TtlKey.changelogRepository => localize.offline_changelog,
TtlKey.plannerAdvertRepository => localize.general_offline,
};

String gqlOfflineMessageLocalized(TtlKey key) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
query GetPlannerAdvertContent {
PlannerAdvert {
isEnabled,
title,
description,
url
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import "package:flutter_riverpod/flutter_riverpod.dart";
import "package:riverpod_annotation/riverpod_annotation.dart";

import "../../../api_base/query_adapter.dart";
import "../../../config/ttl_config.dart";
import "getPlannerAdvertContent.graphql.dart";

part "planner_advert_repository.g.dart";

typedef PlannerAdvertContent = Query$GetPlannerAdvertContent$PlannerAdvert;

@riverpod
Future<PlannerAdvertContent?> plannerAdvertContentRepository(Ref ref) async {
final results = await ref.queryGraphql(
Options$Query$GetPlannerAdvertContent(),
TtlKey.plannerAdvertRepository,
);

return results?.PlannerAdvert;
}
54 changes: 54 additions & 0 deletions lib/features/planner_advert/widgets/planner_advert_widget.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import "dart:async";

import "package:flutter/material.dart";
import "package:flutter_riverpod/flutter_riverpod.dart";

import "../../../config/ui_config.dart";
import "../../../theme/app_theme.dart";
import "../../../utils/launch_url_util.dart";
import "../../../widgets/loading_widgets/simple_previews/horizontal_rectangular_section_loading.dart";
import "../../../widgets/my_error_widget.dart";
import "../../../widgets/technical_message.dart";
import "../repository/planner_advert_repository.dart";

class PlannerAdvertBanner extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final state = ref.watch(plannerAdvertContentRepositoryProvider);
return switch (state) {
AsyncError(:final error) => MyErrorWidget(error),
AsyncValue(:final PlannerAdvertContent value) =>
_PlannerAdvertBanner(value),
_ => const HorizontalRectangularSectionLoading()
};
}
}

class _PlannerAdvertBanner extends ConsumerWidget {
const _PlannerAdvertBanner(
this.data,
);

final PlannerAdvertContent data;

@override
Widget build(BuildContext context, WidgetRef ref) {
return !data.isEnabled
? const SizedBox.shrink()
: Padding(
padding: const EdgeInsets.symmetric(
horizontal: HomeViewConfig.paddingSmall,
),
child: TechnicalMessage(
title: data.title,
message: data.description,
alertType: AlertType.info,
icon: Icon(
Icons.open_in_new_rounded,
color: context.colorTheme.whiteSoap,
),
onTap: () async => unawaited(ref.launch(data.url)),
),
);
}
}
2 changes: 1 addition & 1 deletion lib/features/sks-menu/presentation/sks_menu_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import "../../../widgets/detail_views/detail_view_app_bar.dart";
import "../../../widgets/horizontal_symmetric_safe_area.dart";
import "../../../widgets/my_error_widget.dart";
import "../../../widgets/my_text_button.dart";
import "../../../widgets/technical_message.dart";
import "../../../widgets/text_and_url_widget.dart";
import "../../sks_people_live/presentation/widgets/sks_user_data_button.dart";
import "../data/models/sks_menu_response.dart";
import "../data/repository/sks_menu_repository.dart";
import "widgets/sks_menu_header.dart";
import "widgets/sks_menu_section.dart";
import "widgets/sks_menu_view_loading.dart";
import "widgets/technical_message.dart";

@RoutePage()
class SksMenuView extends HookConsumerWidget {
Expand Down
1 change: 1 addition & 0 deletions lib/l10n/app_pl.arb
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@
"dressing_room": "Szatnia",
"no_lodge_in_the_building": "W tym budynku nie ma portierni",
"no_dressing_room_in_the_building": "W tym budynku nie ma szatni",
"general_offline" : "pobierania danych",
"floors_served_by_lift": "Piętra obsługiwane przez windę",
"dimensions" : "Wymiary",
"max_capacity" : "Maksymalny udźwig",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "package:flutter/material.dart";

import "../../../../widgets/loading_widgets/shimmer_loading.dart";
import "../shimmer_loading.dart";

class HorizontalRectangularSectionLoading extends StatelessWidget {
const HorizontalRectangularSectionLoading({super.key});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import "package:flutter/material.dart";

import "../../../../config/ui_config.dart";
import "../../../../theme/app_theme.dart";
import "../../data/models/dish_category_enum.dart";
import "../config/ui_config.dart";
import "../features/sks-menu/data/models/dish_category_enum.dart";
import "../theme/app_theme.dart";

enum AlertType { info, error }

Expand All @@ -12,10 +12,14 @@ class TechnicalMessage extends StatelessWidget {
required this.message,
this.title,
this.alertType = AlertType.error,
this.icon,
this.onTap,
});
final String message;
final String? title;
final AlertType alertType;
final Icon? icon;
final VoidCallback? onTap;
@override
Widget build(BuildContext context) {
return Padding(
Expand All @@ -30,6 +34,8 @@ class TechnicalMessage extends StatelessWidget {
? context.colorTheme.orangePomegranade
: context.colorTheme.blueAzure,
child: ListTile(
onTap: onTap,
trailing: icon,
title: Text(
title ?? DishCategory.technicalInfo.getLocalizedName(context),
style: context.textTheme.titleWhite,
Expand Down

0 comments on commit 51f75bb

Please sign in to comment.