Skip to content

Commit

Permalink
feat(digital-guide): add lodge section (#545)
Browse files Browse the repository at this point in the history
* feat(digital-guide): setup data layer

* feat(digital-guide): setup presentation layer

* feat(digital-guide): docs

* apply pr suggestion

Co-authored-by: Szymon Kowaliński <szymon@kowalinski.dev>

* feta(digital-guide): apply pr suggestion

---------

Co-authored-by: Szymon Kowaliński <szymon@kowalinski.dev>
  • Loading branch information
mikolaj-jalocha and simon-the-shark authored Jan 23, 2025
1 parent a44f76e commit 3abd001
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import "../../tabs/adapted_toilets/presentation/adapted_toilets_expansion_tile_c
import "../../tabs/amenities/presentation/amenities_expansion_tile_content.dart";
import "../../tabs/evacuation/evacuation_widget.dart";
import "../../tabs/localization/presentation/localization_expansion_tile_content.dart";
import "../../tabs/lodge/presentation/digital_guide_lodge_expansion_tile_content.dart";
import "../../tabs/micronavigation/presentation/micronavigation_expansion_tile_content.dart";
import "../../tabs/rooms/presentation/digital_guide_rooms_expansion_tile_content.dart";
import "../../tabs/surrounding/presentation/surroundings_expansion_tile_content.dart";
Expand Down Expand Up @@ -102,6 +103,14 @@ class DigitalGuideFeaturesSection extends ConsumerWidget {
),
],
),
(
title: context.localize.lodge,
content: [
DigitalGuideLodgeExpansionTileContent(
digitalGuideData,
),
],
),
];

return SliverList(
Expand Down
3 changes: 3 additions & 0 deletions lib/features/digital_guide_view/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@
* /rooms/data/repository/rooms_repository.dart
* DIGITAL_GUIDE_URL/rooms/{id}

5) Lodges data
* /lodges/?building={buildingId}

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import "package:freezed_annotation/freezed_annotation.dart";

part "digital_guide_lodge.freezed.dart";
part "digital_guide_lodge.g.dart";

@freezed
class DigitalGuideLodge with _$DigitalGuideLodge {
const factory DigitalGuideLodge({
required int id,
required DigitalGuideTranslationsLodge translations,
@JsonKey(name: "images") required List<int>? imagesIds,
}) = _DigitalGuideLodge;

factory DigitalGuideLodge.fromJson(Map<String, dynamic> json) =>
_$DigitalGuideLodgeFromJson(json);
}

@freezed
class DigitalGuideTranslationsLodge with _$DigitalGuideTranslationsLodge {
const factory DigitalGuideTranslationsLodge({
required DigitalGuideTranslationLodge pl,
}) = _DigitalGuideTranslationsLodge;

factory DigitalGuideTranslationsLodge.fromJson(Map<String, dynamic> json) =>
_$DigitalGuideTranslationsLodgeFromJson(json);
}

@freezed
class DigitalGuideTranslationLodge with _$DigitalGuideTranslationLodge {
@JsonSerializable(fieldRename: FieldRename.snake)
const factory DigitalGuideTranslationLodge({
required String location,
required String workingDaysAndHours,
required String comment,
}) = _DigitalGuideTranslationLodge;
factory DigitalGuideTranslationLodge.fromJson(Map<String, dynamic> json) =>
_$DigitalGuideTranslationLodgeFromJson(json);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import "package:fast_immutable_collections/fast_immutable_collections.dart";
import "package:flutter_riverpod/flutter_riverpod.dart";
import "package:riverpod_annotation/riverpod_annotation.dart";

import "../../../../data/api/digital_guide_get_and_cache.dart";
import "../../../../data/models/digital_guide_response.dart";
import "../models/digital_guide_lodge.dart";

part "lodges_repository.g.dart";

@riverpod
Future<IList<DigitalGuideLodge>> lodgesRepository(
Ref ref,
DigitalGuideResponse building,
) async {
final endpoint = "lodges/?building=${building.id}";
return ref.getAndCacheDataFromDigitalGuide(
endpoint,
(List<dynamic> json) => json
.whereType<Map<String, dynamic>>()
.map(DigitalGuideLodge.fromJson)
.toIList(),
onRetry: () => ref.invalidateSelf(),
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import "package:fast_immutable_collections/fast_immutable_collections.dart";
import "package:flutter/material.dart";
import "package:flutter_riverpod/flutter_riverpod.dart";

import "../../../../../config/ui_config.dart";
import "../../../../../theme/app_theme.dart";
import "../../../../../utils/context_extensions.dart";
import "../../../../../widgets/my_error_widget.dart";
import "../../../data/models/digital_guide_response.dart";
import "../../../presentation/widgets/digital_guide_photo_row.dart";
import "../data/models/digital_guide_lodge.dart";
import "../data/repository/lodges_repository.dart";

class DigitalGuideLodgeExpansionTileContent extends ConsumerWidget {
const DigitalGuideLodgeExpansionTileContent(this.digitalGuideResponse);

final DigitalGuideResponse digitalGuideResponse;

@override
Widget build(BuildContext context, WidgetRef ref) {
final lodgeResponse =
ref.watch(lodgesRepositoryProvider(digitalGuideResponse));
return lodgeResponse.when(
data: (data) =>
_DigitalGuideLodgeExpansionTileContent(lodge: data.firstOrNull),
error: (error, _) => MyErrorWidget(error),
loading: () => const Center(
child: CircularProgressIndicator(),
),
);
}
}

class _DigitalGuideLodgeExpansionTileContent extends StatelessWidget {
final DigitalGuideLodge? lodge;

const _DigitalGuideLodgeExpansionTileContent({
required this.lodge,
});

@override
Widget build(BuildContext context) {
if (lodge == null) {
return Center(child: Text(context.localize.no_lodge_in_the_building));
}
final lodgeInformation = lodge!.translations.pl;
return Padding(
padding: const EdgeInsets.all(DigitalGuideConfig.paddingMedium),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(context.localize.localization, style: context.textTheme.title),
Padding(
padding: const EdgeInsets.symmetric(
vertical: DigitalGuideConfig.heightSmall,
),
child: Text(lodgeInformation.location),
),
Text(context.localize.working_hours, style: context.textTheme.title),
const SizedBox(
height: DigitalGuideConfig.heightSmall,
),
Text(lodgeInformation.workingDaysAndHours),
const SizedBox(
height: DigitalGuideConfig.heightSmall,
),
if (lodgeInformation.comment.isNotEmpty)
Padding(
padding: const EdgeInsets.only(
bottom: DigitalGuideConfig.paddingSmall,
),
child: Text(
context.localize.additional_information,
style: context.textTheme.title,
),
),
Text(lodgeInformation.comment),
if (lodgeInformation.comment.isNotEmpty)
const SizedBox(
height: DigitalGuideConfig.heightMedium,
),
DigitalGuidePhotoRow(
imagesIDs: lodge!.imagesIds?.toIList() ?? const IList.empty(),
),
],
),
);
}
}
6 changes: 4 additions & 2 deletions lib/l10n/app_pl.arb
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@
"communique" : "Komunikat",
"audio_message" : "Komunikat Dźwiękowy",
"audio_message_comment" : "Sygnał znacznika może różnić się tempem i brzmieniem",
"digital_guide" : "Cyfrowy Przewodnik",
"platforms" : "Podesty",
"stairs" : "Schody",
"key_information" : "Najważniejsze informacje",
Expand All @@ -299,5 +298,8 @@
"sensorySensitivity": "Wrażliwość sensoryczna",
"cognitiveImpairment": "Trudności poznawcze",
"accessibility_profiles":"Profile dostępności",
"you_can_adjust": "Możesz dostosować informacje pod swoje specjalne potrzeby"
"you_can_adjust": "Możesz dostosować informacje pod swoje specjalne potrzeby",
"additional_information": "Dodatkowe informacje",
"lodge": "Portiernia",
"no_lodge_in_the_building": "W tym budynku nie ma portierni"
}

0 comments on commit 3abd001

Please sign in to comment.