-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(home): add planner advert (#557)
* 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
1 parent
47a68ca
commit 51f75bb
Showing
12 changed files
with
1,558 additions
and
1,438 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
lib/features/planner_advert/repository/getPlannerAdvertContent.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
query GetPlannerAdvertContent { | ||
PlannerAdvert { | ||
isEnabled, | ||
title, | ||
description, | ||
url | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
lib/features/planner_advert/repository/planner_advert_repository.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
54
lib/features/planner_advert/widgets/planner_advert_widget.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...rizontal_rectangular_section_loading.dart → ...rizontal_rectangular_section_loading.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters